From 894c065b995dbd5c8f5442a9093ebe58f77af117 Mon Sep 17 00:00:00 2001 From: Kocmonavtik <61938582+Kocmonavtik@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:30:27 +0300 Subject: [PATCH] Fixed multiple execution of order updates (#352) --- CHANGELOG.md | 3 ++ VERSION | 2 +- src/include/class-wc-retailcrm-base.php | 44 +++++++---------------- src/include/class-wc-retailcrm-orders.php | 5 +++ src/readme.txt | 4 ++- src/retailcrm.php | 2 +- src/uninstall.php | 2 +- 7 files changed, 27 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 844da2c..198fa91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2024-10-24 4.8.12 +* Fixed multiple execution of order updates + ## 2024-10-14 4.8.11 * Added additional parameters to GET requests diff --git a/VERSION b/VERSION index c1b6143..332911c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.8.11 +4.8.12 diff --git a/src/include/class-wc-retailcrm-base.php b/src/include/class-wc-retailcrm-base.php index 52b8e45..0bb3215 100644 --- a/src/include/class-wc-retailcrm-base.php +++ b/src/include/class-wc-retailcrm-base.php @@ -108,6 +108,14 @@ if (!class_exists('WC_Retailcrm_Base')) { add_action('admin_enqueue_scripts', [$this, 'include_files_for_admin'], 101); add_action('woocommerce_new_order', [$this, 'create_order'], 11, 1); + if ( + !$this->get_option('deactivate_update_order') + || $this->get_option('deactivate_update_order') == static::NO + ) { + add_action('woocommerce_update_order', [$this, 'take_update_order'], 11, 1); + add_action('shutdown', [$this, 'update_order'], -1); + add_action('woocommerce_saved_order_items', [$this, 'update_order_items'], 10, 1); + } if (isLoyaltyActivate($this->settings)) { add_action('wp_ajax_register_customer_loyalty', [$this, 'register_customer_loyalty']); @@ -130,23 +138,8 @@ if (!class_exists('WC_Retailcrm_Base')) { add_action('retailcrm_loyalty_upload_price', [$this, 'upload_loyalty_price']); add_action('admin_print_footer_scripts', [$this, 'ajax_upload_loyalty_price'], 99); add_action('wp_ajax_upload_loyalty_price', [$this, 'upload_loyalty_price']); - - if ( - !$this->get_option('deactivate_update_order') - || $this->get_option('deactivate_update_order') == static::NO - ) { - add_action('woocommerce_update_order', [$this, 'take_update_order'], 11, 1); - add_action('shutdown', [$this, 'update_order_loyalty'], -1); - add_action('woocommerce_saved_order_items', [$this, 'update_order_items'], 10, 1); - } - } elseif ( - !$this->get_option('deactivate_update_order') - || $this->get_option('deactivate_update_order') == static::NO - ) { - add_action('woocommerce_update_order', [$this, 'update_order'], 10, 1); } - // Subscribed hooks add_action('register_form', [$this, 'subscribe_register_form'], 99); add_action('woocommerce_register_form', [$this, 'subscribe_woocommerce_register_form'], 99); @@ -653,19 +646,6 @@ if (!class_exists('WC_Retailcrm_Base')) { } } - public function update_order($orderId) - { - WC_Retailcrm_Logger::setHook(current_action(), $orderId); - - if (WC_Retailcrm_Plugin::history_running() === true) { - WC_Retailcrm_Logger::info(__METHOD__, 'History in progress, skip'); - - return; - } - - $this->orders->updateOrder($orderId); - } - /** * Edit order in retailCRM * @@ -695,7 +675,7 @@ if (!class_exists('WC_Retailcrm_Base')) { $this->updatedOrderId[$order_id] = $order_id; } - public function update_order_loyalty() + public function update_order() { WC_Retailcrm_Logger::setHook(current_action()); @@ -708,8 +688,10 @@ if (!class_exists('WC_Retailcrm_Base')) { public function update_order_items($orderId) { - WC_Retailcrm_Logger::setHook(current_action(), $orderId); - $this->orders->updateOrder($orderId); + if (is_admin()) { + WC_Retailcrm_Logger::setHook(current_action(), $orderId); + $this->orders->updateOrder($orderId); + } } public function trash_order_action($id) diff --git a/src/include/class-wc-retailcrm-orders.php b/src/include/class-wc-retailcrm-orders.php index dc38f09..596b640 100644 --- a/src/include/class-wc-retailcrm-orders.php +++ b/src/include/class-wc-retailcrm-orders.php @@ -330,6 +330,11 @@ if (!class_exists('WC_Retailcrm_Orders')) : try { $wcOrder = wc_get_order($orderId); + + if ($wcOrder->get_status() === 'checkout-draft') { + return null; + } + WC_Retailcrm_Logger::info( __METHOD__, 'Update WC_Order ' . $wcOrder->get_id(), diff --git a/src/readme.txt b/src/readme.txt index 96bd8d4..7866dd6 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.11 +Stable tag: 4.8.12 License: GPLv1 or later License URI: http://www.gnu.org/licenses/gpl-1.0.html @@ -82,6 +82,8 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i == Changelog == += 4.8.12 = +* Fixed multiple execution of order updates = 4.8.11 = * Added additional parameters to GET requests diff --git a/src/retailcrm.php b/src/retailcrm.php index a29573c..256d61b 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.11 + * Version: 4.8.12 * 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 bbb5360..71df6d4 100644 --- a/src/uninstall.php +++ b/src/uninstall.php @@ -16,7 +16,7 @@ * * @link https://wordpress.org/plugins/woo-retailcrm/ * - * @version 4.8.11 + * @version 4.8.12 * * @package RetailCRM */