From c4230bbadd1078ad52fab9de9ed585fdce7484e8 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Thu, 10 Mar 2016 02:07:25 +0300 Subject: [PATCH 1/2] update for 2.x --- README.md | 53 +++--- README.ru.md | 99 ++++++++++ admin/controller/module/retailcrm.php | 169 ++++++++++++++---- admin/language/english/module/retailcrm.php | 1 + admin/language/russian/module/retailcrm.php | 1 + .../{retailcrm.tpl => retailcrm.1.x.tpl} | 0 admin/view/template/module/retailcrm.2.x.tpl | 110 ++++++++++++ catalog/controller/module/retailcrm.php | 38 ++++ system/cron/dispatch.php | 2 - 9 files changed, 405 insertions(+), 68 deletions(-) create mode 100644 README.ru.md rename admin/view/template/module/{retailcrm.tpl => retailcrm.1.x.tpl} (100%) create mode 100644 admin/view/template/module/retailcrm.2.x.tpl create mode 100644 catalog/controller/module/retailcrm.php diff --git a/README.md b/README.md index 97f3217..87b318f 100644 --- a/README.md +++ b/README.md @@ -1,62 +1,59 @@ Opencart module =============== -Модуль интеграции CMS Openacrt c [RetailCRM](http://retailcrm.ru) +Module allows integrate CMS Openacart with [retailCRM](http://retailcrm.ru) -#### Модуль позволяет: +#### Module allows: -* Экспортировать в CRM данные о заказах и клиентах и получать обратно изменения по этим данным -* Синхронизировать справочники (способы доставки и оплаты, статусы заказов и т.п.) -* Выгружать каталог товаров в формате [ICML](http://retailcrm.ru/docs/Разработчики/ФорматICML) (IntaroCRM Markup Language) +* Export orders to retailCRM & fetch changes back +* Export product catalog into [ICML](http://www.retailcrm.ru/docs/Developers/ICML) format -#### Установка +#### Install -Установите модуль скопировав необходимые файлы в корень сайта +Copy files to the site root ``` unzip master.zip cp -r opencart-module/* /path/to/site/root ``` -#### Активируйте модуль +#### Setup -В списке модулей нажмите "Установить" - -#### Настройте параметры интеграции - -На странице настроек модуля укажите URL Вашей CRM и ключ авторизации, после сохранения этих данных укажите соответствия справочников типов доставок, оплат и статусов заказа. +* Go to Admin -> Extensions -> Modules -> retailCRM +* Fill you api url & api key +* Specify directories matching -#### Выгрузка новых заказов в CRM (для версии opencart 1.5.x.x, для версии 2.0 и старше не требуется) +#### Export orders to retailCRM (for opencart 1.5.x, for version 2.x this step is unnecessary) ##### VQmod -Скопируйте xml-файл модифицирующий работу моделей _admin/model/sale/order.php_ и _catalog/model/checkout/order.php_ в _/path/to/site/root/vqmod/xml_. +Copy _retailcrm_create_order.xml_ into _/path/to/site/root/vqmod/xml_. -Для обновления кеша VQmod может потрбоваться удалить файлы _/path/to/site/root/vqmod/vqcache/vq2-admin_model_sale_order.php_ и _/path/to/site/root/vqmod/vqcache/vq2-catalog_model_checkout_order.php_ +For VQmod cache renewal you may need to delete files _/path/to/site/root/vqmod/vqcache/vq2-admin_model_sale_order.php_ & _/path/to/site/root/vqmod/vqcache/vq2-catalog_model_checkout_order.php_ -##### Ручная установка +##### Manual setup -В файле: +In the file: ``` /catalog/model/checkout/order.php ``` -Добавьте следующие строки в метод addOrder непосредственно перед языковой конструкцией return: +add theese lines into addOrder method right before return statement: ```php $this->load->model('retailcrm/order'); $this->model_retailcrm_order->sendToCrm($data, $order_id); ``` -В файле: +In the file: ``` /admin/model/sale/order.php ``` -Добавьте следующие строки в методы addOrder и editOrder в самом конце каждого метода: +add theese lines into addOrder & editOrder methods right before return statement: ```php if (!isset($data['fromApi'])) { @@ -76,24 +73,24 @@ if (!isset($data['fromApi'])) { } ``` -#### Получение измений из CRM +#### Getting changes in orders -Для получения изменений и новых данных добавьте в cron следующую запись: +Add to cron: ``` -*/5 * * * * /usr/bin/php /path/to/opencart/system/cron/retailcrm/history.php >> /path/to/opencart/system/logs/cronjob_history.log 2>&1 +*/5 * * * * /usr/bin/php /path/to/opencart/system/cron/history.php >> /path/to/opencart/system/logs/cronjob_history.log 2>&1 ``` -#### Настройка экспорта каталога +#### Setting product catalog export -Для периодической выгрузки каталога добавьте в cron следующую запись: +Add to cron: ``` * */4 * * * /usr/bin/php /path/to/opencart/system/cron/export.php >> /path/to/opencart/system/logs/cronjob_export.log 2>&1 ``` -В настройках CRM установите путь к файлу выгрузки +Your export file will be available by following url ``` -http://myopencartsite.ru/download/retailcrm.xml +http://youropencartsite.com/retailcrm.xml ``` diff --git a/README.ru.md b/README.ru.md new file mode 100644 index 0000000..b13b2fd --- /dev/null +++ b/README.ru.md @@ -0,0 +1,99 @@ +Opencart module +=============== + +Модуль интеграции CMS Openacart c [RetailCRM](http://retailcrm.ru) + +#### Модуль позволяет: + +* Экспортировать в CRM данные о заказах и клиентах и получать обратно изменения по этим данным +* Синхронизировать справочники (способы доставки и оплаты, статусы заказов и т.п.) +* Выгружать каталог товаров в формате [ICML](http://www.retailcrm.ru/docs/Developers/ICML) + +#### Установка + +Установите модуль скопировав необходимые файлы в корень сайта + +``` +unzip master.zip +cp -r opencart-module/* /path/to/site/root +``` + +#### Активируйте модуль + +В списке модулей нажмите "Установить" + +#### Настройте параметры интеграции + +На странице настроек модуля укажите URL Вашей CRM и ключ авторизации, после сохранения этих данных укажите соответствия справочников типов доставок, оплат и статусов заказа. + + +#### Выгрузка новых заказов в CRM (для версии opencart 1.5.x.x, для версии 2.0 и старше не требуется) + +##### VQmod + +Скопируйте файл _retailcrm_create_order.xml_ в _/path/to/site/root/vqmod/xml_. + +Для обновления кеша VQmod может потрбоваться удалить файлы _/path/to/site/root/vqmod/vqcache/vq2-admin_model_sale_order.php_ и _/path/to/site/root/vqmod/vqcache/vq2-catalog_model_checkout_order.php_ + +##### Ручная установка + +В файле: + +``` +/catalog/model/checkout/order.php +``` + +Добавьте следующие строки в метод addOrder непосредственно перед языковой конструкцией return: + +```php +$this->load->model('retailcrm/order'); +$this->model_retailcrm_order->sendToCrm($data, $order_id); +``` + +В файле: + +``` +/admin/model/sale/order.php +``` + +Добавьте следующие строки в методы addOrder и editOrder в самом конце каждого метода: + +```php +if (!isset($data['fromApi'])) { + $this->load->model('setting/setting'); + $status = $this->model_setting_setting->getSetting('retailcrm'); + + if (!empty($data['order_status_id'])) { + $data['order_status'] = $status['retailcrm_status'][$data['order_status_id']]; + } + + $this->load->model('retailcrm/order'); + if (isset ($order_query)) { + $this->model_retailcrm_order->changeInCrm($data, $order_id); + } else { + $this->model_retailcrm_order->sendToCrm($data, $order_id); + } +} +``` + +#### Получение измений из CRM + +Для получения изменений и новых данных добавьте в cron следующую запись: + +``` +*/5 * * * * /usr/bin/php /path/to/opencart/system/cron/history.php >> /path/to/opencart/system/logs/cronjob_history.log 2>&1 +``` + +#### Настройка экспорта каталога + +Для периодической выгрузки каталога добавьте в cron следующую запись: + +``` +* */4 * * * /usr/bin/php /path/to/opencart/system/cron/export.php >> /path/to/opencart/system/logs/cronjob_export.log 2>&1 +``` + +В настройках CRM установите путь к файлу выгрузки + +``` +http://youropencartsite.com/retailcrm.xml +``` diff --git a/admin/controller/module/retailcrm.php b/admin/controller/module/retailcrm.php index f03525f..d2b78f0 100644 --- a/admin/controller/module/retailcrm.php +++ b/admin/controller/module/retailcrm.php @@ -4,6 +4,12 @@ require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php'; /** * Class ControllerModule + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 */ class ControllerModuleRetailcrm extends Controller { @@ -21,6 +27,17 @@ class ControllerModuleRetailcrm extends Controller $this->load->model('setting/setting'); $this->model_setting_setting ->editSetting('retailcrm', array('retailcrm_status' => 1)); + + if (version_compare(VERSION, '2.0.1.0', '>')) { + $this->load->model('extension/event'); + + $this->model_extension_event + ->addEvent( + 'retailcrm', + 'post.order.add', + 'module/retailcrm/order_create' + ); + } } /** @@ -33,25 +50,45 @@ class ControllerModuleRetailcrm extends Controller $this->load->model('setting/setting'); $this->model_setting_setting ->editSetting('retailcrm', array('retailcrm_status' => 0)); + + if (version_compare(VERSION, '2.0.1.0', '>')) { + $this->load->model('extension/event'); + $this->model_extension_event->deleteEvent('retailcrm'); + } } /** * Setup page + * + * @return void */ public function index() { $this->load->model('setting/setting'); - $this->load->model('setting/extension'); + $this->load->model('extension/module'); $this->load->model('retailcrm/references'); $this->load->language('module/retailcrm'); $this->document->setTitle($this->language->get('heading_title')); $this->document->addStyle('/admin/view/stylesheet/retailcrm.css'); if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) { - $this->model_setting_setting->editSetting('retailcrm', $this->request->post); + $this->model_setting_setting->editSetting( + 'retailcrm', + $this->request->post + ); + $this->session->data['success'] = $this->language->get('text_success'); - $this->redirect($this->url->link('module/retailcrm', 'token=' . $this->session->data['token'], 'SSL')); + $redirect = $this->url->link( + 'module/retailcrm', 'token=' . $this->session->data['token'], + 'SSL' + ); + + if (version_compare(VERSION, '2.0.1.0', '<')) { + $this->redirect($redirect); + } else { + $this->response->redirect($redirect); + } } $text_strings = array( @@ -61,6 +98,7 @@ class ControllerModuleRetailcrm extends Controller 'button_save', 'button_cancel', 'text_notice', + 'retailcrm_title', 'retailcrm_url', 'retailcrm_apikey', 'retailcrm_base_settings', @@ -70,27 +108,43 @@ class ControllerModuleRetailcrm extends Controller 'retailcrm_dict_payment', ); - foreach ($text_strings as $text) { - $this->data[$text] = $this->language->get($text); + if (version_compare(VERSION, '2.0.1.0', '<')) { + $_data = &$this->data; + $this->load->model('setting/extension'); + } else { + $this->load->model('extension/extension'); + $_data = &$data; } - $this->data['retailcrm_errors'] = array(); - $this->data['saved_settings'] = $this->model_setting_setting->getSetting('retailcrm'); + foreach ($text_strings as $text) { + $_data[$text] = $this->language->get($text); + } - $url = isset($this->data['saved_settings']['retailcrm_url']) - ? $this->data['saved_settings']['retailcrm_url'] + $_data['retailcrm_errors'] = array(); + $_data['saved_settings'] = $this->model_setting_setting + ->getSetting('retailcrm'); + + $url = isset($_data['saved_settings']['retailcrm_url']) + ? $_data['saved_settings']['retailcrm_url'] : null; - $key = isset($this->data['saved_settings']['retailcrm_apikey']) - ? $this->data['saved_settings']['retailcrm_apikey'] + $key = isset($_data['saved_settings']['retailcrm_apikey']) + ? $_data['saved_settings']['retailcrm_apikey'] : null; if (!empty($url) && !empty($key)) { - $this->retailcrm = new RetailcrmProxy($url, $key, DIR_SYSTEM . 'logs/retailcrm.log'); + $this->retailcrm = new RetailcrmProxy( + $url, + $key, + DIR_SYSTEM . 'logs/retailcrm.log' + ); - $this->data['delivery'] = $this->model_retailcrm_references->getDeliveryTypes(); - $this->data['statuses'] = $this->model_retailcrm_references->getOrderStatuses(); - $this->data['payments'] = $this->model_retailcrm_references->getPaymentTypes(); + $_data['delivery'] = $this->model_retailcrm_references + ->getDeliveryTypes(); + $_data['statuses'] = $this->model_retailcrm_references + ->getOrderStatuses(); + $_data['payments'] = $this->model_retailcrm_references + ->getPaymentTypes(); } @@ -100,21 +154,21 @@ class ControllerModuleRetailcrm extends Controller foreach ($config_data as $conf) { if (isset($this->request->post[$conf])) { - $this->data[$conf] = $this->request->post[$conf]; + $_data[$conf] = $this->request->post[$conf]; } else { - $this->data[$conf] = $this->config->get($conf); + $_data[$conf] = $this->config->get($conf); } } if (isset($this->error['warning'])) { - $this->data['error_warning'] = $this->error['warning']; + $_data['error_warning'] = $this->error['warning']; } else { - $this->data['error_warning'] = ''; + $_data['error_warning'] = ''; } - $this->data['breadcrumbs'] = array(); + $_data['breadcrumbs'] = array(); - $this->data['breadcrumbs'][] = array( + $_data['breadcrumbs'][] = array( 'text' => $this->language->get('text_home'), 'href' => $this->url->link( 'common/home', @@ -123,7 +177,7 @@ class ControllerModuleRetailcrm extends Controller 'separator' => false ); - $this->data['breadcrumbs'][] = array( + $_data['breadcrumbs'][] = array( 'text' => $this->language->get('text_module'), 'href' => $this->url->link( 'extension/module', @@ -132,8 +186,8 @@ class ControllerModuleRetailcrm extends Controller 'separator' => ' :: ' ); - $this->data['breadcrumbs'][] = array( - 'text' => $this->language->get('heading_title'), + $_data['breadcrumbs'][] = array( + 'text' => $this->language->get('retailcrm_title'), 'href' => $this->url->link( 'module/retailcrm', 'token=' . $this->session->data['token'], 'SSL' @@ -141,40 +195,51 @@ class ControllerModuleRetailcrm extends Controller 'separator' => ' :: ' ); - $this->data['action'] = $this->url->link( + $_data['action'] = $this->url->link( 'module/retailcrm', 'token=' . $this->session->data['token'], 'SSL' ); - $this->data['cancel'] = $this->url->link( + $_data['cancel'] = $this->url->link( 'extension/module', 'token=' . $this->session->data['token'], 'SSL' ); - $this->data['modules'] = array(); + $_data['modules'] = array(); if (isset($this->request->post['retailcrm_module'])) { - $this->data['modules'] = $this->request->post['retailcrm_module']; + $_data['modules'] = $this->request->post['retailcrm_module']; } elseif ($this->config->get('retailcrm_module')) { - $this->data['modules'] = $this->config->get('retailcrm_module'); + $_data['modules'] = $this->config->get('retailcrm_module'); } $this->load->model('design/layout'); + $_data['layouts'] = $this->model_design_layout->getLayouts(); - $this->data['layouts'] = $this->model_design_layout->getLayouts(); + if (version_compare(VERSION, '2.0.1.0', '<')) { + $this->template = 'module/retailcrm.1.x.tpl'; + $this->children = array( + 'common/header', + 'common/footer', + ); - $this->template = 'module/retailcrm.tpl'; - $this->children = array( - 'common/header', - 'common/footer', - ); + $this->response->setOutput($this->render()); + } else { + $_data['header'] = $this->load->controller('common/header'); + $_data['column_left'] = $this->load->controller('common/column_left'); + $_data['footer'] = $this->load->controller('common/footer'); - $this->response->setOutput($this->render()); + $this->response->setOutput( + $this->load->view('module/retailcrm.2.x.tpl', $_data) + ); + } } /** * History method + * + * @return void */ public function history() { @@ -189,6 +254,8 @@ class ControllerModuleRetailcrm extends Controller /** * ICML generation + * + * @return void */ public function icml() { @@ -201,6 +268,32 @@ class ControllerModuleRetailcrm extends Controller } } + /** + * Create order on event + * + * @param int $order_id order identificator + * + * @return void + */ + public function order_create($order_id) + { + + $this->load->model('checkout/order'); + $this->load->model('account/order'); + + $data = $this->model_checkout_order->getOrder($order_id); + $data['products'] = $this->model_account_order->getOrderProducts($order_id); + + if (!isset($data['fromApi'])) { + $this->load->model('setting/setting'); + $status = $this->model_setting_setting->getSetting('retailcrm'); + $data['order_status'] = $status['retailcrm_status'][$data['order_status_id']]; + + $this->load->model('retailcrm/order'); + $this->model_retailcrm_order->sendToCrm($data, $order['order_id']); + } + } + /** * Validate * @@ -213,9 +306,9 @@ class ControllerModuleRetailcrm extends Controller } if (!$this->_error) { - return TRUE; + return true; } else { - return FALSE; + return false; } } } diff --git a/admin/language/english/module/retailcrm.php b/admin/language/english/module/retailcrm.php index 06385bc..f1baabb 100644 --- a/admin/language/english/module/retailcrm.php +++ b/admin/language/english/module/retailcrm.php @@ -2,6 +2,7 @@ // Heading Goes here: $_['heading_title'] = 'RetailCRM'; +$_['retailcrm_title'] = 'RetailCRM'; // Text $_['text_module'] = 'Modules'; diff --git a/admin/language/russian/module/retailcrm.php b/admin/language/russian/module/retailcrm.php index b2389d9..b2062ff 100644 --- a/admin/language/russian/module/retailcrm.php +++ b/admin/language/russian/module/retailcrm.php @@ -2,6 +2,7 @@ // Heading Goes here: $_['heading_title'] = 'RetailCRM'; +$_['retailcrm_title'] = 'RetailCRM'; // Text $_['text_module'] = 'Модули'; diff --git a/admin/view/template/module/retailcrm.tpl b/admin/view/template/module/retailcrm.1.x.tpl similarity index 100% rename from admin/view/template/module/retailcrm.tpl rename to admin/view/template/module/retailcrm.1.x.tpl diff --git a/admin/view/template/module/retailcrm.2.x.tpl b/admin/view/template/module/retailcrm.2.x.tpl new file mode 100644 index 0000000..144f68b --- /dev/null +++ b/admin/view/template/module/retailcrm.2.x.tpl @@ -0,0 +1,110 @@ + + + +
+ +
+ +
+ + +
+ + + + + + +
+
+
+ + +

+
+
+ +
+
+
+ +
+ + + + + +
+ + +

+ +

+ $value): ?> +
+ + +
+ + +

+ + +
+ + +
+ + +

+ $value): ?> +
+ + +
+ + + + + +
+
+
+
+
+ + diff --git a/catalog/controller/module/retailcrm.php b/catalog/controller/module/retailcrm.php new file mode 100644 index 0000000..fb1e349 --- /dev/null +++ b/catalog/controller/module/retailcrm.php @@ -0,0 +1,38 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 + */ +class ControllerModuleRetailcrm extends Controller +{ + /** + * Create order on event + * + * @param int $order_id order identificator + * + * @return void + */ + public function order_create($order_id) + { + $this->load->model('checkout/order'); + $this->load->model('account/order'); + + $data = $this->model_checkout_order->getOrder($order_id); + $data['products'] = $this->model_account_order->getOrderProducts($order_id); + + if (!isset($data['fromApi'])) { + $this->load->model('setting/setting'); + $status = $this->model_setting_setting->getSetting('retailcrm'); + $data['order_status'] = $status['retailcrm_status'][$data['order_status_id']]; + + $this->load->model('retailcrm/order'); + $this->model_retailcrm_order->sendToCrm($data, $order['order_id']); + } + } +} diff --git a/system/cron/dispatch.php b/system/cron/dispatch.php index 1c756ed..8f29648 100644 --- a/system/cron/dispatch.php +++ b/system/cron/dispatch.php @@ -102,8 +102,6 @@ $registry->set('request', $request); $response = new Response(); $response->addHeader('Content-Type: text/html; charset=utf-8'); $registry->set('response', $response); -$cache = new Cache(); -$registry->set('cache', $cache); $session = new Session(); $registry->set('session', $session); $languages = array(); From 8835251d808862a0ca63703504096f781e66eb3d Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Fri, 11 Mar 2016 14:15:24 +0300 Subject: [PATCH 2/2] fix delivery & hook data --- admin/controller/module/retailcrm.php | 3 +-- admin/model/retailcrm/order.php | 4 ++-- catalog/controller/module/retailcrm.php | 6 ++++-- catalog/model/retailcrm/order.php | 13 ++++++++----- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/admin/controller/module/retailcrm.php b/admin/controller/module/retailcrm.php index d2b78f0..cefd63c 100644 --- a/admin/controller/module/retailcrm.php +++ b/admin/controller/module/retailcrm.php @@ -205,7 +205,6 @@ class ControllerModuleRetailcrm extends Controller 'token=' . $this->session->data['token'], 'SSL' ); - $_data['modules'] = array(); if (isset($this->request->post['retailcrm_module'])) { @@ -290,7 +289,7 @@ class ControllerModuleRetailcrm extends Controller $data['order_status'] = $status['retailcrm_status'][$data['order_status_id']]; $this->load->model('retailcrm/order'); - $this->model_retailcrm_order->sendToCrm($data, $order['order_id']); + $this->model_retailcrm_order->sendToCrm($data, $data['order_id']); } } diff --git a/admin/model/retailcrm/order.php b/admin/model/retailcrm/order.php index 5ef90c5..cf89d9a 100644 --- a/admin/model/retailcrm/order.php +++ b/admin/model/retailcrm/order.php @@ -86,7 +86,7 @@ class ModelRetailcrmOrder extends Model { ); } - if (isset($order_data['order_status_id'])) { + if (isset($order_data['order_status_id']) && $order_data['order_status_id'] > 0) { $order['status'] = $settings['retailcrm_status'][$order_data['order_status_id']]; } @@ -163,7 +163,7 @@ class ModelRetailcrmOrder extends Model { ); } - if (isset($order_data['order_status_id'])) { + if (isset($order_data['order_status_id']) && $order_data['order_status_id'] > 0) { $order['status'] = $settings['retailcrm_status'][$order_data['order_status_id']]; } diff --git a/catalog/controller/module/retailcrm.php b/catalog/controller/module/retailcrm.php index fb1e349..331cfed 100644 --- a/catalog/controller/module/retailcrm.php +++ b/catalog/controller/module/retailcrm.php @@ -29,10 +29,12 @@ class ControllerModuleRetailcrm extends Controller if (!isset($data['fromApi'])) { $this->load->model('setting/setting'); $status = $this->model_setting_setting->getSetting('retailcrm'); - $data['order_status'] = $status['retailcrm_status'][$data['order_status_id']]; + if ($data['order_status_id'] > 0) { + $data['order_status'] = $status['retailcrm_status'][$data['order_status_id']]; + } $this->load->model('retailcrm/order'); - $this->model_retailcrm_order->sendToCrm($data, $order['order_id']); + $this->model_retailcrm_order->sendToCrm($data, $data['order_id']); } } } diff --git a/catalog/model/retailcrm/order.php b/catalog/model/retailcrm/order.php index e021e30..f2df393 100644 --- a/catalog/model/retailcrm/order.php +++ b/catalog/model/retailcrm/order.php @@ -44,11 +44,14 @@ class ModelRetailcrmOrder extends Model { $order['customerComment'] = $order_data['comment']; $deliveryCost = 0; - $orderTotals = isset($order_data['totals']) ? $order_data['totals'] : $order_data['order_total'] ; + $altTotals = isset($order_data['order_total']) ? $order_data['order_total'] : ""; + $orderTotals = isset($order_data['totals']) ? $order_data['totals'] : $altTotals ; - foreach ($orderTotals as $totals) { - if ($totals['code'] == 'shipping') { - $deliveryCost = $totals['value']; + if (!empty($orderTotals)) { + foreach ($orderTotals as $totals) { + if ($totals['code'] == 'shipping') { + $deliveryCost = $totals['value']; + } } } @@ -86,7 +89,7 @@ class ModelRetailcrmOrder extends Model { ); } - if (isset($order_data['order_status_id'])) { + if (isset($order_data['order_status_id']) && $order_data['order_status_id'] > 0) { $order['status'] = $settings['retailcrm_status'][$order_data['order_status_id']]; }