Correct changes in variation data update and fix context

This commit is contained in:
Mike Jolley 2017-02-16 16:07:11 +00:00
parent e07d9ad970
commit b69988fe39
2 changed files with 13 additions and 12 deletions

View File

@ -160,13 +160,13 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
if ( array_intersect( array( 'description', 'short_description', 'name', 'parent_id', 'reviews_allowed', 'status', 'menu_order' ), array_keys( $changes ) ) ) { if ( array_intersect( array( 'description', 'short_description', 'name', 'parent_id', 'reviews_allowed', 'status', 'menu_order' ), array_keys( $changes ) ) ) {
wp_update_post( array( wp_update_post( array(
'ID' => $product->get_id(), 'ID' => $product->get_id(),
'post_content' => $product->get_description(), 'post_content' => $product->get_description( 'edit' ),
'post_excerpt' => $product->get_short_description(), 'post_excerpt' => $product->get_short_description( 'edit' ),
'post_title' => $product->get_name(), 'post_title' => $product->get_name( 'edit' ),
'post_parent' => $product->get_parent_id(), 'post_parent' => $product->get_parent_id( 'edit' ),
'comment_status' => $product->get_reviews_allowed() ? 'open' : 'closed', 'comment_status' => $product->get_reviews_allowed( 'edit' ) ? 'open' : 'closed',
'post_status' => $product->get_status() ? $product->get_status() : 'publish', 'post_status' => $product->get_status( 'edit' ) ? $product->get_status( 'edit' ) : 'publish',
'menu_order' => $product->get_menu_order(), 'menu_order' => $product->get_menu_order( 'edit' ),
) ); ) );
} }

View File

@ -137,16 +137,17 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl
*/ */
public function update( &$product ) { public function update( &$product ) {
$changes = $product->get_changes(); $changes = $product->get_changes();
$title = $this->generate_product_title( $product );
// Only update the post when the post data changes. // Only update the post when the post data changes.
if ( array_intersect( array( 'description', 'short_description', 'name', 'parent_id', 'reviews_allowed', 'status', 'menu_order' ), array_keys( $changes ) ) ) { if ( $title !== $product->get_name( 'edit' ) || array_intersect( array( 'parent_id', 'status', 'menu_order' ), array_keys( $changes ) ) ) {
wp_update_post( array( wp_update_post( array(
'ID' => $product->get_id(), 'ID' => $product->get_id(),
'post_title' => $this->generate_product_title( $product ), // ! 'post_title' => $title,
'post_parent' => $product->get_parent_id(), 'post_parent' => $product->get_parent_id( 'edit' ),
'comment_status' => 'closed', 'comment_status' => 'closed',
'post_status' => $product->get_status() ? $product->get_status() : 'publish', 'post_status' => $product->get_status( 'edit' ) ? $product->get_status( 'edit' ) : 'publish',
'menu_order' => $product->get_menu_order(), 'menu_order' => $product->get_menu_order( 'edit' ),
) ); ) );
} }