1
0
Fork 0
mirror of synced 2025-04-06 07:13:33 +03:00
This commit is contained in:
dima-uryvskiy 2021-03-15 18:10:10 +03:00
parent c195e27e50
commit a6d1fc6aca

View file

@ -52,8 +52,8 @@ if (!class_exists('WC_Retailcrm_Inventories')) :
return null;
}
$page = 1;
$variationProducts = array();
$page = 1;
$variationProducts = array();
do {
/** @var WC_Retailcrm_Response $result */
@ -70,31 +70,31 @@ if (!class_exists('WC_Retailcrm_Inventories')) :
if (isset($offer[$this->bind_field])) {
$product = retailcrm_get_wc_product($offer[$this->bind_field], $this->retailcrm_settings);
if ($product instanceof WC_Product) {
if ($product->get_type() == 'variation' || $product->get_type() == 'variable') {
$parentId = $product->get_parent_id();
if ($product instanceof WC_Product) {
if ($product->get_type() == 'variation' || $product->get_type() == 'variable') {
$parentId = $product->get_parent_id();
if (isset($variationProducts[$parentId])) {
$variationProducts[$parentId] += $offer['quantity'];
} else {
$variationProducts[$parentId] = $offer['quantity'];
}
}
if (isset($variationProducts[$parentId])) {
$variationProducts[$parentId] += $offer['quantity'];
} else {
$variationProducts[$parentId] = $offer['quantity'];
}
}
$product->set_manage_stock(true);
$product->set_stock_quantity($offer['quantity']);
$success[] = $product->save();
}
}
}
$product->set_manage_stock(true);
$product->set_stock_quantity($offer['quantity']);
$success[] = $product->save();
}
}
}
foreach ($variationProducts as $id => $quantity) {
$variationProduct = wc_get_product($id);
$variationProduct->set_manage_stock(true);
$variationProduct->set_stock($quantity);
$success[] = $variationProduct->save();
}
} while ($page <= $totalPageCount);
foreach ($variationProducts as $id => $quantity) {
$variationProduct = wc_get_product($id);
$variationProduct->set_manage_stock(true);
$variationProduct->set_stock($quantity);
$success[] = $variationProduct->save();
}
} while ($page <= $totalPageCount);
return $success;
}