[2.4] [API] Fixed editing product variations

Fixed general variations edition and make sync again variations when just
edit a variable product and don't send any 'variations' data

closes #9406
This commit is contained in:
Claudio Sanches 2015-10-22 17:19:16 -02:00
parent ddc6baf07d
commit bfe98a283c
2 changed files with 16 additions and 4 deletions

View File

@ -399,8 +399,14 @@ class WC_API_Products extends WC_API_Resource {
$this->save_product_meta( $id, $data ); $this->save_product_meta( $id, $data );
// Save variations // Save variations
if ( isset( $data['type'] ) && 'variable' == $data['type'] && isset( $data['variations'] ) && is_array( $data['variations'] ) ) { $product = get_product( $id );
if ( $product->is_type( 'variable' ) ) {
if ( isset( $data['variations'] ) && is_array( $data['variations'] ) ) {
$this->save_variations( $id, $data ); $this->save_variations( $id, $data );
} else {
// Just sync variations
WC_Product_Variable::sync( $id );
}
} }
do_action( 'woocommerce_api_edit_product', $id, $data ); do_action( 'woocommerce_api_edit_product', $id, $data );

View File

@ -367,8 +367,14 @@ class WC_API_Products extends WC_API_Resource {
$this->save_product_meta( $id, $data ); $this->save_product_meta( $id, $data );
// Save variations // Save variations
if ( isset( $data['type'] ) && 'variable' == $data['type'] && isset( $data['variations'] ) && is_array( $data['variations'] ) ) { $product = get_product( $id );
if ( $product->is_type( 'variable' ) ) {
if ( isset( $data['variations'] ) && is_array( $data['variations'] ) ) {
$this->save_variations( $id, $data ); $this->save_variations( $id, $data );
} else {
// Just sync variations
WC_Product_Variable::sync( $id );
}
} }
do_action( 'woocommerce_api_edit_product', $id, $data ); do_action( 'woocommerce_api_edit_product', $id, $data );