Fix bug with variation product id
This commit is contained in:
parent
5d999f6fde
commit
f2b50e6d72
@ -74,12 +74,14 @@ if (!class_exists('WC_Retailcrm_Inventories')) :
|
|||||||
if ($product->get_type() == 'variation' || $product->get_type() == 'variable') {
|
if ($product->get_type() == 'variation' || $product->get_type() == 'variable') {
|
||||||
$parentId = $product->get_parent_id();
|
$parentId = $product->get_parent_id();
|
||||||
|
|
||||||
|
if (!empty($parentId)) {
|
||||||
if (isset($variationProducts[$parentId])) {
|
if (isset($variationProducts[$parentId])) {
|
||||||
$variationProducts[$parentId] += $offer['quantity'];
|
$variationProducts[$parentId] += $offer['quantity'];
|
||||||
} else {
|
} else {
|
||||||
$variationProducts[$parentId] = $offer['quantity'];
|
$variationProducts[$parentId] = $offer['quantity'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$product->set_manage_stock(true);
|
$product->set_manage_stock(true);
|
||||||
$product->set_stock_quantity($offer['quantity']);
|
$product->set_stock_quantity($offer['quantity']);
|
||||||
@ -88,12 +90,17 @@ if (!class_exists('WC_Retailcrm_Inventories')) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($variationProducts)) {
|
||||||
foreach ($variationProducts as $id => $quantity) {
|
foreach ($variationProducts as $id => $quantity) {
|
||||||
$variationProduct = wc_get_product($id);
|
$variationProduct = wc_get_product($id);
|
||||||
|
|
||||||
|
if (is_object($variationProduct)) {
|
||||||
$variationProduct->set_manage_stock(true);
|
$variationProduct->set_manage_stock(true);
|
||||||
$variationProduct->set_stock($quantity);
|
$variationProduct->set_stock($quantity);
|
||||||
$success[] = $variationProduct->save();
|
$success[] = $variationProduct->save();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} while ($page <= $totalPageCount);
|
} while ($page <= $totalPageCount);
|
||||||
|
|
||||||
return $success;
|
return $success;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user