From c195e27e50b75915dbcb7c2ecdde4aeb26f3c26c Mon Sep 17 00:00:00 2001 From: dima-uryvskiy Date: Mon, 15 Mar 2021 17:37:21 +0300 Subject: [PATCH] Add display of the total number of product variables --- CHANGELOG.md | 8 ++++ VERSION | 2 +- .../class-wc-retailcrm-inventories.php | 38 +++++++++++++------ src/readme.txt | 7 ++++ src/retailcrm.php | 2 +- src/uninstall.php | 2 +- 6 files changed, 44 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd56a4b..e0cdd44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## 2021-03-15 4.2.4 +* Добавили отображение общего количества вариативных товаров +* Добавили валидацию на дату создания заказа +* Добавили валидацию на заказы с auto-draft статусом +* Обновили версии WP и WC в локальных тестах +* Исправили баг в опции "Передача номера заказа" + + ## 2021-01-20 4.2.3 * Обновление версии в маркетплейсе diff --git a/VERSION b/VERSION index f2c6cb6..cf78d5b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.2.3 +4.2.4 diff --git a/src/include/class-wc-retailcrm-inventories.php b/src/include/class-wc-retailcrm-inventories.php index 01846ba..3e1fa10 100644 --- a/src/include/class-wc-retailcrm-inventories.php +++ b/src/include/class-wc-retailcrm-inventories.php @@ -52,7 +52,8 @@ if (!class_exists('WC_Retailcrm_Inventories')) : return null; } - $page = 1; + $page = 1; + $variationProducts = array(); do { /** @var WC_Retailcrm_Response $result */ @@ -69,18 +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() == 'variable') { - continue; - } + if ($product instanceof WC_Product) { + if ($product->get_type() == 'variation' || $product->get_type() == 'variable') { + $parentId = $product->get_parent_id(); - $product->set_manage_stock(true); - $product->set_stock_quantity($offer['quantity']); - $success[] = $product->save(); - } - } - } - } while ($page <= $totalPageCount); + 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(); + } + } + } + + 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; } diff --git a/src/readme.txt b/src/readme.txt index bfb2bcb..9edbfcb 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -83,6 +83,13 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i == Changelog == += 4.2.4 = +* Добавили отображение общего количества вариативных товаров +* Добавили валидацию на дату создания заказа +* Добавили валидацию на заказы с auto-draft статусом +* Обновили версии WP и WC в локальных тестах +* Исправили баг в опции "Передача номера заказа" + = 4.2.3= * Обновление версии в маркетплейсе diff --git a/src/retailcrm.php b/src/retailcrm.php index 2424522..00ef262 100644 --- a/src/retailcrm.php +++ b/src/retailcrm.php @@ -1,6 +1,6 @@