1
0
mirror of synced 2025-01-30 06:41:41 +03:00

Fix bug with variation product id

This commit is contained in:
Dima Uryvskiy 2021-10-27 15:53:04 +03:00 committed by GitHub
parent 5d999f6fde
commit f2b50e6d72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -74,10 +74,12 @@ 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 (isset($variationProducts[$parentId])) { if (!empty($parentId)) {
$variationProducts[$parentId] += $offer['quantity']; if (isset($variationProducts[$parentId])) {
} else { $variationProducts[$parentId] += $offer['quantity'];
$variationProducts[$parentId] = $offer['quantity']; } else {
$variationProducts[$parentId] = $offer['quantity'];
}
} }
} }
@ -88,11 +90,16 @@ if (!class_exists('WC_Retailcrm_Inventories')) :
} }
} }
foreach ($variationProducts as $id => $quantity) { if (!empty($variationProducts)) {
$variationProduct = wc_get_product($id); foreach ($variationProducts as $id => $quantity) {
$variationProduct->set_manage_stock(true); $variationProduct = wc_get_product($id);
$variationProduct->set_stock($quantity);
$success[] = $variationProduct->save(); if (is_object($variationProduct)) {
$variationProduct->set_manage_stock(true);
$variationProduct->set_stock($quantity);
$success[] = $variationProduct->save();
}
}
} }
} while ($page <= $totalPageCount); } while ($page <= $totalPageCount);