From cdc7ca71bc4f7e5cfda431863c894b8276c057b8 Mon Sep 17 00:00:00 2001 From: Uryvskiy Dima Date: Mon, 11 Nov 2024 16:50:57 +0300 Subject: [PATCH] The method for determining the stock quantity has been optimized (#354) --- CHANGELOG.md | 3 +++ VERSION | 2 +- src/include/class-wc-retailcrm-icml.php | 23 +++++++++++++---------- src/readme.txt | 5 ++++- src/retailcrm.php | 2 +- src/uninstall.php | 2 +- 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 916623d..503a7a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2024-11-07 4.8.14 +* The method for determining the stock quantity has been optimized + ## 2024-11-07 4.8.13 * Supports custom cart and checkout templates diff --git a/VERSION b/VERSION index 7fcf90f..ae9ac8e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.8.13 +4.8.14 diff --git a/src/include/class-wc-retailcrm-icml.php b/src/include/class-wc-retailcrm-icml.php index 682dbc0..2cf5d92 100644 --- a/src/include/class-wc-retailcrm-icml.php +++ b/src/include/class-wc-retailcrm-icml.php @@ -253,13 +253,6 @@ if (!class_exists('WC_Retailcrm_Icml')) : $tax = reset($tax_rates); } - if ($product->get_manage_stock() == true) { - $stockQuantity = $product->get_stock_quantity(); - $quantity = empty($stockQuantity) === false ? $stockQuantity : 0; - } else { - $quantity = $product->get_stock_status() === 'instock' ? 1 : 0; - } - $productData = [ 'id' => $product->get_id(), 'productId' => ($product->get_parent_id() > 0) ? $parent->get_id() : $product->get_id(), @@ -271,7 +264,7 @@ if (!class_exists('WC_Retailcrm_Icml')) : , 'picture' => $images, 'url' => ($product->get_parent_id() > 0) ? $parent->get_permalink() : $product->get_permalink(), - 'quantity' => $quantity, + 'quantity' => $this->getQuantity($product), 'categoryId' => $termList, 'dimensions' => $dimensions, 'weight' => $weight, @@ -309,9 +302,19 @@ if (!class_exists('WC_Retailcrm_Icml')) : $product ); - if (isset($productData)) { - return $productData; + return $productData ?? []; + } + + private function getQuantity($product) + { + if ($product->get_manage_stock()) { + $stockQuantity = $product->get_stock_quantity(); + $quantity = $stockQuantity !== null && $stockQuantity !== 0 ? $stockQuantity : 0; + } else { + $quantity = $product->get_stock_status() === 'instock' ? 1 : 0; } + + return $quantity; } /** diff --git a/src/readme.txt b/src/readme.txt index f8cfe55..7a82f70 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -5,7 +5,7 @@ Tags: Интеграция, Simla.com, simla Requires PHP: 7.1 Requires at least: 5.3 Tested up to: 6.5 -Stable tag: 4.8.13 +Stable tag: 4.8.14 License: GPLv1 or later License URI: http://www.gnu.org/licenses/gpl-1.0.html @@ -82,6 +82,9 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i == Changelog == += 4.8.14 = +* The method for determining the stock quantity has been optimized + = 4.8.13 = * Supports custom cart and checkout templates diff --git a/src/retailcrm.php b/src/retailcrm.php index 22992db..8178e7d 100644 --- a/src/retailcrm.php +++ b/src/retailcrm.php @@ -5,7 +5,7 @@ * Description: Integration plugin for WooCommerce & Simla.com * Author: RetailDriver LLC * Author URI: http://retailcrm.pro/ - * Version: 4.8.13 + * Version: 4.8.14 * Tested up to: 6.5 * Requires Plugins: woocommerce * WC requires at least: 5.4 diff --git a/src/uninstall.php b/src/uninstall.php index 3df38db..60118d9 100644 --- a/src/uninstall.php +++ b/src/uninstall.php @@ -16,7 +16,7 @@ * * @link https://wordpress.org/plugins/woo-retailcrm/ * - * @version 4.8.13 + * @version 4.8.14 * * @package RetailCRM */