Skip to content

Commit

Permalink
Merge branch 'update-more-product-values' into v1.5.2-matise
Browse files Browse the repository at this point in the history
  • Loading branch information
SHoogland committed May 3, 2019
2 parents 3de006b + 14da13f commit 26ca641
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions includes/class-xcore-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,35 @@ public function update_item($request)
$object = $this->get_object((int)$request['id']);
if ($object->is_type('variation')) {
$product = new WC_Product_Variation($request['id']);
$product->set_stock_quantity($request['stock_quantity']);
$product->set_manage_stock($request['manage_stock']);
if(isset($request['stock_quantity'])){
$product->set_stock_quantity($request['stock_quantity']);
}
if(isset($request['manage_stock'])){
$product->set_manage_stock($request['manage_stock']);
}
if(isset($request['regular_price'])){
$product->set_regular_price($request['regular_price']);
}
if(isset($request['tax_class'])){
$product->set_tax_class($request['tax_class']);
}
if(isset($request['weight'])){
$product->set_weight($request['weight']);
}
if(isset($request['catalog_visibility'])){
$product->set_catalog_visibility($request['catalog_visibility']);
}
if(isset($request['backorders'])){
$product->set_backorders($request['backorders']);
}
$product->set_stock_status();
$product->save();

// trigger an update (for example to let polylang sync products between languages)
if(has_action('woocommerce_update_product')){
do_action( 'woocommerce_update_product', $product->get_id() );
}

return parent::prepare_object_for_response($product, $request);
}

Expand All @@ -161,9 +185,9 @@ public function find_item_by_sku($request)
$product_id = $wpdb->get_var(
$wpdb->prepare(
"SELECT post_id
FROM $wpdb->postmeta
WHERE meta_key='%s'
AND meta_value='%s'",
FROM $wpdb->postmeta
WHERE meta_key='%s'
AND meta_value='%s'",
$meta_key,
$product_reference
)
Expand Down

0 comments on commit 26ca641

Please sign in to comment.