From d58b66a01b6a09e306dfb229c185060e0e866a25 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Tue, 19 Mar 2019 16:43:54 +0300 Subject: [PATCH] History fix, orders history setting --- CHANGELOG.md | 4 ++ VERSION | 2 +- .../controller/extension/module/retailcrm.php | 4 +- .../en-gb/extension/module/retailcrm.php | 8 ++-- .../es-es/extension/module/retailcrm.php | 10 +++-- .../ru-ru/extension/module/retailcrm.php | 10 +++-- .../model/extension/retailcrm/history.php | 40 +++++++++---------- .../extension/retailcrm/history/v4_5.php | 30 +++++++++----- .../template/extension/module/retailcrm.tpl | 22 +++++++++- .../template/extension/module/retailcrm.twig | 36 +++++++++++++---- .../controller/extension/module/retailcrm.php | 5 +++ 11 files changed, 120 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0318268..115a90f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v.3.3.0 +* Добавена настройка записи истории изменения заказов в Opencart +* Устранен баг с вызовом события редактирования заказа при выгрузке истории изменений из retailCRM + ## v.3.2.4 * Добавлена возможность передачи акционных цен для нескольких групп пользователей * Добавлена передача нулевой цены для неустановленных акционных цен diff --git a/VERSION b/VERSION index 351227f..15a2799 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.2.4 +3.3.0 diff --git a/src/upload/admin/controller/extension/module/retailcrm.php b/src/upload/admin/controller/extension/module/retailcrm.php index cf7295d..85ef039 100644 --- a/src/upload/admin/controller/extension/module/retailcrm.php +++ b/src/upload/admin/controller/extension/module/retailcrm.php @@ -304,7 +304,9 @@ class ControllerExtensionModuleRetailcrm extends Controller 'order_number', 'text_order_number', 'text_currency', - 'text_currency_label' + 'text_currency_label', + 'status_changes', + 'text_status_changes' ); $_data = &$data; diff --git a/src/upload/admin/language/en-gb/extension/module/retailcrm.php b/src/upload/admin/language/en-gb/extension/module/retailcrm.php index 579cce8..768b332 100644 --- a/src/upload/admin/language/en-gb/extension/module/retailcrm.php +++ b/src/upload/admin/language/en-gb/extension/module/retailcrm.php @@ -1,8 +1,8 @@ db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE iso_code_2 = '" . $isoCode . "'"); - + return $query->row; } /** * Get zone by name - * + * * @param string $name - * + * * @return array */ public function getZoneByName($name) @@ -137,10 +137,10 @@ class ModelExtensionRetailcrmHistory extends Model /** * Get currency - * + * * @param string $code * @param string $field (default = '') - * + * * @return mixed array | string */ public function getCurrencyByCode($code, $field = '') @@ -156,10 +156,10 @@ class ModelExtensionRetailcrmHistory extends Model /** * Get language - * + * * @param string $code * @param string $field (default = '') - * + * * @return mixed array | string */ public function getLanguageByCode($code, $field = '') @@ -175,10 +175,10 @@ class ModelExtensionRetailcrmHistory extends Model /** * Get product option value - * + * * @param int $option_value_id * @param string $field - * + * * @return mixed array | string */ public function getOptionValue($option_value_id, $field = '') diff --git a/src/upload/admin/model/extension/retailcrm/history/v4_5.php b/src/upload/admin/model/extension/retailcrm/history/v4_5.php index 39b72f6..2202812 100644 --- a/src/upload/admin/model/extension/retailcrm/history/v4_5.php +++ b/src/upload/admin/model/extension/retailcrm/history/v4_5.php @@ -4,6 +4,9 @@ require_once __DIR__ . '/../history.php'; class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory { + /** @var bool */ + public static $history_run = false; + protected $createResult; protected $settings; protected $moduleTitle; @@ -32,7 +35,7 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory $this->load->model('setting/store'); $this->load->model('user/api'); $this->load->model('sale/order'); - $this->load->model('customer/customer'); + $this->load->model('customer/customer'); $this->load->model('extension/retailcrm/references'); $this->load->model('catalog/product'); $this->load->model('catalog/option'); @@ -162,9 +165,9 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory } $this->model_setting_setting->editSetting( - 'retailcrm_history', + 'retailcrm_history', array( - 'retailcrm_history_orders' => $sinceIdOrders, + 'retailcrm_history_orders' => $sinceIdOrders, 'retailcrm_history_customers' => $sinceIdCustomers, 'retailcrm_history_datetime' => $generatedAt ) @@ -183,13 +186,13 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory /** * Update orders from history - * + * * @param array $orders - * + * * @return void */ protected function updateOrders($orders) - { + { foreach ($orders as $order) { $ocOrder = $this->model_sale_order->getOrder($order['externalId']); @@ -468,19 +471,26 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory } $this->editOrder($order['externalId'], $data); - $this->opencartApiClient->addHistory($order['externalId'], $data['order_status_id']); + + if (isset($this->settings[$this->moduleTitle . '_status_changes']) + && $this->settings[$this->moduleTitle . '_status_changes'] + ) { + static::$history_run = true; + $this->opencartApiClient->addHistory($order['externalId'], $data['order_status_id']); + static::$history_run = false; + } } } /** * Create orders from history - * + * * @param array $orders - * + * * @return array */ protected function createOrders($orders) - { + { $customersIdsFix = array(); $ordersIdsFix = array(); diff --git a/src/upload/admin/view/template/extension/module/retailcrm.tpl b/src/upload/admin/view/template/extension/module/retailcrm.tpl index 5f3821f..8151190 100644 --- a/src/upload/admin/view/template/extension/module/retailcrm.tpl +++ b/src/upload/admin/view/template/extension/module/retailcrm.tpl @@ -109,6 +109,26 @@ +
+ +
+ +
+ + +
+
+
@@ -510,7 +530,7 @@
- Retailcrm API error log + retailCRM API error log diff --git a/src/upload/admin/view/template/extension/module/retailcrm.twig b/src/upload/admin/view/template/extension/module/retailcrm.twig index 4e685af..4cbbd26 100644 --- a/src/upload/admin/view/template/extension/module/retailcrm.twig +++ b/src/upload/admin/view/template/extension/module/retailcrm.twig @@ -108,6 +108,28 @@
+
+ {{ status_changes }} +
+ +
+ + +
+
+
{% if saved_settings.module_retailcrm_apikey is defined and saved_settings.module_retailcrm_apikey and saved_settings.module_retailcrm_url is defined and saved_settings.module_retailcrm_url %} {% if retailcrm_errors|length %} {% for retailcrm_error in retailcrm_errors %} @@ -161,16 +183,16 @@
@@ -623,4 +645,4 @@ $('#export_order').button('reset'); } }); - \ No newline at end of file + diff --git a/src/upload/catalog/controller/extension/module/retailcrm.php b/src/upload/catalog/controller/extension/module/retailcrm.php index 236b0ab..40515b5 100644 --- a/src/upload/catalog/controller/extension/module/retailcrm.php +++ b/src/upload/catalog/controller/extension/module/retailcrm.php @@ -31,6 +31,11 @@ class ControllerExtensionModuleRetailcrm extends Controller { * @return void */ public function order_create($trigger, $data, $order_id = null) { + + if (ModelExtensionRetailcrmHistoryV45::$history_run === true) { + return; + } + $this->load->model('checkout/order'); $this->load->model('account/order'); $this->load->library('retailcrm/retailcrm');