Skip to content

Commit

Permalink
Supports custom cart and checkout templates (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocmonavtik authored Nov 11, 2024
1 parent 894c065 commit 6e39fca
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.8.12
4.8.13
56 changes: 45 additions & 11 deletions src/include/class-wc-retailcrm-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -526,22 +530,52 @@ 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
*
* @codeCoverageIgnore Check in another tests
*
* @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);
}
}

Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/retailcrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @link https://wordpress.org/plugins/woo-retailcrm/
*
* @version 4.8.12
* @version 4.8.13
*
* @package RetailCRM
*/
Expand Down

0 comments on commit 6e39fca

Please sign in to comment.