From 680e1c28fe3240c24e039494d66c3042027a6653 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Mon, 30 Oct 2017 16:49:49 +0300 Subject: [PATCH] Bug fix (#59) --- CHANGELOG.md | 20 ++++++---- README.ru.md | 4 ++ .../controller/extension/module/retailcrm.php | 30 ++++++++++++-- admin/model/extension/retailcrm/order.php | 20 ++-------- .../template/extension/module/retailcrm.tpl | 5 ++- .../template/extension/module/retailcrm.twig | 6 ++- catalog/model/extension/retailcrm/order.php | 40 ++++--------------- 7 files changed, 60 insertions(+), 65 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3366785..fc89396 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ -## v.2.4.0 -* Добавлена возможность работы на 3 версиях API (v3, v4, v5) -* Добавлена совместимость с Opencart 3.0 +## v.2.4.3 +* Устранены некоторые баги, добавлен вывод ошибок при выгрузке единичных заказов + +## v.2.4.2 +* Улучшена синхронизация кастомных полей +* Добавлены настройки дефолтных способов доставки и оплаты +* Улучшена настройка Daemon Collector +* Доработан шаблон twig для совместимости с Opencart 3.0 ## v.2.4.1 * Исправлена работа истории (доработана обработка адресов, добавлена обработка заказов с пустыми полями, доработана история по клиентам) @@ -8,8 +13,7 @@ * Проверка доступных версий API через метод /api/versions * Добавлена возможность сопоставления кастомных полей(для API v5) -## v.2.4.2 -* Доработана синхронизация кастомных полей -* Добавлены настройки дефолтных способов доставки и оплаты -* Доработана настройка Daemon Collector -* Доработан шаблон twig для совместимости с Opencart 3.0 \ No newline at end of file +## v.2.4.0 +* Добавлена возможность работы на 3 версиях API (v3, v4, v5) +* Добавлена совместимость с Opencart 3.0 + diff --git a/README.ru.md b/README.ru.md index b3b4f46..1bda844 100644 --- a/README.ru.md +++ b/README.ru.md @@ -58,3 +58,7 @@ http://youropencartsite.com/retailcrm.xml Запустите команду единожды: /usr/bin/php /path/to/opencart/system/cron/export.php + +#### Кастомизация моделей + +Для создания кастомных классов скопируйте файл модели в директорию custom, в новом файле измените название класса с "ModelExtensionRetailcrmFilename" на "ModelExtensionRetailcrmCustomFilename", где "Filename" - название файла с заглавной буквы. После этого модуль будет использовать методы кастомного класса. \ No newline at end of file diff --git a/admin/controller/extension/module/retailcrm.php b/admin/controller/extension/module/retailcrm.php index 4b77e6d..e1b87c7 100644 --- a/admin/controller/extension/module/retailcrm.php +++ b/admin/controller/extension/module/retailcrm.php @@ -93,7 +93,12 @@ class ControllerExtensionModuleRetailcrm extends Controller ->editSetting($moduleTitle, array($moduleTitle . '_status' => 0)); $this->model_setting_setting->deleteSetting('retailcrm_history'); $this->loadModels(); - $this->{'model_' . $this->modelEvent}->deleteEvent($moduleTitle); + + if (version_compare(VERSION, '3.0', '<')) { + $this->{'model_' . $this->modelEvent}->deleteEvent($moduleTitle); + } else { + $this->{'model_' . $this->modelEvent}->deleteEventByCode($moduleTitle); + } } /** @@ -545,10 +550,29 @@ class ControllerExtensionModuleRetailcrm extends Controller $data['order_status'] = $status[$moduleTitle . '_status'][$data['order_status_id']]; $this->load->model('extension/retailcrm/order'); - $result = $this->model_extension_retailcrm_order->uploadOrder($data); + $response = $this->model_extension_retailcrm_order->uploadOrder($data); } - echo json_encode($result->getStatusCode()); + if (!$response->isSuccessful()) { + if (isset($response['errors'])) { + $error = implode("\n", $response['errors']); + } else { + $error = $response->getErrorMsg(); + } + + echo json_encode( + array( + 'status_code' => $response->getStatusCode(), + 'error_msg' => $error + ) + ); + } else { + echo json_encode( + array( + 'status_code' => $response->getStatusCode() + ) + ); + } } /** diff --git a/admin/model/extension/retailcrm/order.php b/admin/model/extension/retailcrm/order.php index 75e90c4..87d3316 100644 --- a/admin/model/extension/retailcrm/order.php +++ b/admin/model/extension/retailcrm/order.php @@ -72,7 +72,9 @@ class ModelExtensionRetailcrmOrder extends Model { $order['email'] = $order_data['email']; } - $order['customer']['externalId'] = $order_data['customer_id']; + if ($order_data['customer_id']) { + $order['customer']['externalId'] = $order_data['customer_id']; + } $deliveryCost = 0; $orderTotals = isset($order_data['totals']) ? $order_data['totals'] : $order_data['order_total'] ; @@ -192,12 +194,6 @@ class ModelExtensionRetailcrmOrder extends Model { protected function createPayment($order, $order_id) { $this->moduleTitle = $this->getModuleTitle(); - - if (version_compare(VERSION, '3.0', '<')) { - $settingPaid = $this->model_setting_setting->getSetting($order['payment_code']); - } else { - $settingPaid = $this->model_setting_setting->getSetting('payment_' . $order['payment_code']); - } $payment_code = $order['payment_code']; @@ -211,16 +207,6 @@ class ModelExtensionRetailcrmOrder extends Model { 'amount' => $amount ); - if (version_compare(VERSION, '3.0', '<')) { - if ($order['order_status_id'] == $settingPaid[$order['payment_code'] . '_order_status_id']) { - $payment['status'] = 'paid'; - } - } else { - if ($order['order_status_id'] == $settingPaid['payment_' . $order['payment_code'] . '_order_status_id']) { - $payment['status'] = 'paid'; - } - } - $payment['order'] = array( 'externalId' => $order_id ); diff --git a/admin/view/template/extension/module/retailcrm.tpl b/admin/view/template/extension/module/retailcrm.tpl index 2726cfb..d5ed8b2 100644 --- a/admin/view/template/extension/module/retailcrm.tpl +++ b/admin/view/template/extension/module/retailcrm.tpl @@ -376,9 +376,10 @@ alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); }, success: function(data, textStatus, jqXHR) { - if (jqXHR['responseText'] == '400') { + response = JSON.parse(jqXHR['responseText']); + if (response['status_code'] == '400') { $('.alert-danger').remove(); - $('#content > .container-fluid').prepend('
'); + $('#content > .container-fluid').prepend('
' + response['error_msg'] + '
'); $('#export_order').button('reset'); } else { $('.alert-success').remove(); diff --git a/admin/view/template/extension/module/retailcrm.twig b/admin/view/template/extension/module/retailcrm.twig index 45be023..2be398f 100644 --- a/admin/view/template/extension/module/retailcrm.twig +++ b/admin/view/template/extension/module/retailcrm.twig @@ -378,9 +378,11 @@ alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); }, success: function(data, textStatus, jqXHR) { - if (jqXHR['responseText'] == '400') { + response = JSON.parse(jqXHR['responseText']); + + if (response['status_code'] == '400') { $('.alert-danger').remove(); - $('#content > .container-fluid').prepend('
{{ text_error_order }}
'); + $('#content > .container-fluid').prepend('
{{ text_error_order }}' + response['error_msg'] + '
'); $('#export_order').button('reset'); } else { $('.alert-success').remove(); diff --git a/catalog/model/extension/retailcrm/order.php b/catalog/model/extension/retailcrm/order.php index fba3af0..d08c003 100644 --- a/catalog/model/extension/retailcrm/order.php +++ b/catalog/model/extension/retailcrm/order.php @@ -79,6 +79,8 @@ class ModelExtensionRetailcrmOrder extends Model { if ($response->isSuccessful()) { $this->createPayment($order_data, $order_id); } + } elseif (isset($payment) && $payment['type'] == $this->settings[$this->moduleTitle . '_payment'][$order_data['payment_code']]) { + $this->editPayment($order_data, $order_id); } } } @@ -89,12 +91,6 @@ class ModelExtensionRetailcrmOrder extends Model { $this->load->model('setting/setting'); $this->load->model('catalog/product'); $this->settings = $this->model_setting_setting->getSetting($this->moduleTitle); - - if (version_compare(VERSION, '3.0', '<')) { - $settingPaid = $this->model_setting_setting->getSetting($order_data['payment_code']); - } else { - $settingPaid = $this->model_setting_setting->getSetting('payment_' . $order_data['payment_code']); - } $payment_code = $order_data['payment_code']; $order['externalId'] = $order_id; @@ -225,18 +221,6 @@ class ModelExtensionRetailcrmOrder extends Model { $order['status'] = $this->settings[$this->moduleTitle . '_status'][$order_data['order_status_id']]; } - if ($this->settings[$this->moduleTitle . '_apiversion'] != 'v5') { - if (version_compare(VERSION, '3.0', '<')) { - if ($order_data['order_status_id'] == $settingPaid[$order_data['payment_code'] . '_order_status_id']) { - $order['paymentStatus'] = 'paid'; - } - } else { - if ($order_data['order_status_id'] == $settingPaid['payment_' . $order_data['payment_code'] . '_order_status_id']) { - $order['paymentStatus'] = 'paid'; - } - } - } - if (isset($this->settings[$this->moduleTitle . '_custom_field']) && $order_data['custom_field']) { $customFields = $order_data['custom_field']; @@ -256,13 +240,7 @@ class ModelExtensionRetailcrmOrder extends Model { } protected function createPayment($order, $order_id) - { - if (version_compare(VERSION, '3.0', '<')) { - $settingPaid = $this->model_setting_setting->getSetting($order['payment_code']); - } else { - $settingPaid = $this->model_setting_setting->getSetting('payment_' . $order['payment_code']); - } - + { $payment_code = $order['payment_code']; foreach ($order['totals'] as $total) { @@ -283,17 +261,13 @@ class ModelExtensionRetailcrmOrder extends Model { } protected function editPayment($order, $order_id) - { - if (version_compare(VERSION, '3.0', '<')) { - $settingPaid = $this->model_setting_setting->getSetting($order['payment_code']); - } else { - $settingPaid = $this->model_setting_setting->getSetting('payment_' . $order['payment_code']); - } - + { $payment_code = $order['payment_code']; foreach ($order['totals'] as $total) { - if ($total['code'] == 'total') $amount = $total['value']; + if ($total['code'] == 'total') { + $amount = $total['value']; + } } $payment = array(