diff --git a/CHANGELOG.md b/CHANGELOG.md index 198fa91c..916623dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2024-11-07 4.8.13 +* Supports custom cart and checkout templates + ## 2024-10-24 4.8.12 * Fixed multiple execution of order updates diff --git a/VERSION b/VERSION index 332911cc..7fcf90f1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.8.12 +4.8.13 diff --git a/src/include/class-wc-retailcrm-base.php b/src/include/class-wc-retailcrm-base.php index 0bb32153..758763f8 100644 --- a/src/include/class-wc-retailcrm-base.php +++ b/src/include/class-wc-retailcrm-base.php @@ -41,6 +41,9 @@ class WC_Retailcrm_Base extends WC_Retailcrm_Abstracts_Settings /** @var array */ protected $updatedOrderId = []; + /** @var array */ + protected $createdOrderId = []; + /** * Init and hook in the integration. * @@ -106,13 +109,14 @@ public function __construct($retailcrm = false) add_action('wp_print_footer_scripts', [$this, 'initialize_whatsapp'], 101); add_action('wp_print_footer_scripts', [$this, 'send_analytics'], 99); add_action('admin_enqueue_scripts', [$this, 'include_files_for_admin'], 101); - add_action('woocommerce_new_order', [$this, 'create_order'], 11, 1); + add_action('woocommerce_new_order', [$this, 'fill_array_create_orders'], 11, 1); + add_action('shutdown', [$this, 'create_order'], -2); 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('woocommerce_update_order', [$this, 'fill_array_update_orders'], 11, 1); add_action('shutdown', [$this, 'update_order'], -1); add_action('woocommerce_saved_order_items', [$this, 'update_order_items'], 10, 1); } @@ -526,6 +530,19 @@ public function update_customer($customerId) $this->customers->updateCustomer($customerId); } + public function fill_array_create_orders($order_id) + { + WC_Retailcrm_Logger::setHook(current_action(), $order_id); + + if (WC_Retailcrm_Plugin::history_running() === true) { + WC_Retailcrm_Logger::info(__METHOD__, 'History in progress, skip'); + + return; + } + + $this->createdOrderId[$order_id] = $order_id; + } + /** * Create order in RetailCRM from admin panel * @@ -533,15 +550,32 @@ public function update_customer($customerId) * * @param int $order_id */ - public function create_order($order_id) + public function create_order() { - WC_Retailcrm_Logger::setHook(current_action(), $order_id); + WC_Retailcrm_Logger::setHook(current_action()); + + if (did_action('woocommerce_new_order') === 0) { + return; + } + + if (did_action('woocommerce_checkout_order_processed')) { + WC_Retailcrm_Logger::info( + __METHOD__, + 'There was a hook woocommerce_checkout_order_processed' + ); + + return; + } + + $logText = 'Creation order'; if (is_admin()) { - WC_Retailcrm_Logger::info(__METHOD__, 'Creation is from admin panel'); - $this->retailcrm_process_order($order_id); - } else { - WC_Retailcrm_Logger::info(__METHOD__, 'Creation is not from admin panel, skip'); + $logText = 'Creation order from admin panel'; + } + + foreach ($this->createdOrderId as $orderId) { + WC_Retailcrm_Logger::info(__METHOD__, sprintf('%s (%s)', $logText, $orderId)); + $this->retailcrm_process_order($orderId); } } @@ -655,7 +689,7 @@ public function clear_cart() * * @throws \Exception */ - public function take_update_order($order_id) + public function fill_array_update_orders($order_id) { WC_Retailcrm_Logger::setHook(current_action(), $order_id); @@ -679,8 +713,8 @@ public function update_order() { WC_Retailcrm_Logger::setHook(current_action()); - if ($this->updatedOrderId !== []) { - foreach ($this->updatedOrderId as $orderId) { + foreach ($this->updatedOrderId as $orderId) { + if (!isset($this->createdOrderId[$orderId])) { $this->orders->updateOrder($orderId); } } diff --git a/src/readme.txt b/src/readme.txt index 7866dd6e..f8cfe55c 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.12 +Stable tag: 4.8.13 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.13 = +* Supports custom cart and checkout templates + = 4.8.12 = * Fixed multiple execution of order updates diff --git a/src/retailcrm.php b/src/retailcrm.php index 256d61b3..22992dbf 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.12 + * Version: 4.8.13 * 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 71df6d4f..3df38dbf 100644 --- a/src/uninstall.php +++ b/src/uninstall.php @@ -16,7 +16,7 @@ * * @link https://wordpress.org/plugins/woo-retailcrm/ * - * @version 4.8.12 + * @version 4.8.13 * * @package RetailCRM */