From b69988fe399eeb71bfc54b63f10318a2b45cfef8 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 16 Feb 2017 16:07:11 +0000 Subject: [PATCH] Correct changes in variation data update and fix context --- .../class-wc-product-data-store-cpt.php | 14 +++++++------- .../class-wc-product-variation-data-store-cpt.php | 11 ++++++----- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/includes/data-stores/class-wc-product-data-store-cpt.php b/includes/data-stores/class-wc-product-data-store-cpt.php index 8acac11f8c1..7df9a2caa5b 100644 --- a/includes/data-stores/class-wc-product-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-data-store-cpt.php @@ -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 ) ) ) { wp_update_post( array( 'ID' => $product->get_id(), - 'post_content' => $product->get_description(), - 'post_excerpt' => $product->get_short_description(), - 'post_title' => $product->get_name(), - 'post_parent' => $product->get_parent_id(), - 'comment_status' => $product->get_reviews_allowed() ? 'open' : 'closed', - 'post_status' => $product->get_status() ? $product->get_status() : 'publish', - 'menu_order' => $product->get_menu_order(), + 'post_content' => $product->get_description( 'edit' ), + 'post_excerpt' => $product->get_short_description( 'edit' ), + 'post_title' => $product->get_name( 'edit' ), + 'post_parent' => $product->get_parent_id( 'edit' ), + 'comment_status' => $product->get_reviews_allowed( 'edit' ) ? 'open' : 'closed', + 'post_status' => $product->get_status( 'edit' ) ? $product->get_status( 'edit' ) : 'publish', + 'menu_order' => $product->get_menu_order( 'edit' ), ) ); } diff --git a/includes/data-stores/class-wc-product-variation-data-store-cpt.php b/includes/data-stores/class-wc-product-variation-data-store-cpt.php index 84341350118..9a322b12b80 100644 --- a/includes/data-stores/class-wc-product-variation-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-variation-data-store-cpt.php @@ -137,16 +137,17 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl */ public function update( &$product ) { $changes = $product->get_changes(); + $title = $this->generate_product_title( $product ); // 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( 'ID' => $product->get_id(), - 'post_title' => $this->generate_product_title( $product ), // ! - 'post_parent' => $product->get_parent_id(), + 'post_title' => $title, + 'post_parent' => $product->get_parent_id( 'edit' ), 'comment_status' => 'closed', - 'post_status' => $product->get_status() ? $product->get_status() : 'publish', - 'menu_order' => $product->get_menu_order(), + 'post_status' => $product->get_status( 'edit' ) ? $product->get_status( 'edit' ) : 'publish', + 'menu_order' => $product->get_menu_order( 'edit' ), ) ); }