From 2c4306dad1df6de6e247db679815a3f4c35d964b Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Thu, 14 Jun 2018 11:26:15 +0300 Subject: [PATCH] Bug fix --- src/upload/catalog/controller/api/retailcrm.php | 12 ++++-------- .../controller/extension/module/retailcrm.php | 8 +++++++- .../catalog/model/extension/retailcrm/order.php | 8 +++++--- src/upload/system/library/retailcrm/retailcrm.php | 4 ---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/upload/catalog/controller/api/retailcrm.php b/src/upload/catalog/controller/api/retailcrm.php index baa97d7..6512dd5 100644 --- a/src/upload/catalog/controller/api/retailcrm.php +++ b/src/upload/catalog/controller/api/retailcrm.php @@ -147,20 +147,16 @@ class ControllerApiRetailcrm extends Controller if ( version_compare(VERSION, '3.0', '<')) { $api = $this->model_account_api->getApiByKey($this->request->get['key']); } else { - $api = $this->model_account_api->login($this->request->get['username'], $this->request->get['key']); - - if (empty($api)) { - $this->load->model('extension/retailcrm/api'); - $api = $this->model_extension_retailcrm_api->login($this->request->get['username'], $this->request->get['key']); - } + $this->load->model('extension/retailcrm/api'); + $api = $this->model_extension_retailcrm_api->login($this->request->get['username'], $this->request->get['key']); } if (!empty($api)) { return $api; } - - return array('error' => 'Invalid api key'); } + + return array('error' => 'Invalid api key'); } private function loadModels() diff --git a/src/upload/catalog/controller/extension/module/retailcrm.php b/src/upload/catalog/controller/extension/module/retailcrm.php index 21a1daf..faf73ae 100644 --- a/src/upload/catalog/controller/extension/module/retailcrm.php +++ b/src/upload/catalog/controller/extension/module/retailcrm.php @@ -13,8 +13,10 @@ class ControllerExtensionModuleRetailcrm extends Controller { private $retailcrmApiClient; - public function __construct() + public function __construct($registry) { + parent::__construct($registry); + $this->load->library('retailcrm/retailcrm'); $this->retailcrmApiClient = $this->retailcrm->getApiClient(); } @@ -29,9 +31,13 @@ class ControllerExtensionModuleRetailcrm extends Controller { * @return void */ public function order_create($trigger, $data, $order_id = null) { + $this->load->model('checkout/order'); $this->load->model('account/order'); $this->load->library('retailcrm/retailcrm'); + $data = $this->model_checkout_order->getOrder($order_id);; + $data['products'] = $this->model_account_order->getOrderProducts($order_id); + $data['totals'] = $this->model_account_order->getOrderTotals($order_id); $moduleTitle = $this->retailcrm->getModuleTitle(); foreach ($data['products'] as $key => $product) { diff --git a/src/upload/catalog/model/extension/retailcrm/order.php b/src/upload/catalog/model/extension/retailcrm/order.php index 73fff67..6c68084 100644 --- a/src/upload/catalog/model/extension/retailcrm/order.php +++ b/src/upload/catalog/model/extension/retailcrm/order.php @@ -295,9 +295,11 @@ class ModelExtensionRetailcrmOrder extends Model { 100 ); - if ($response->isSuccessful()) { - if ($response['customers']) { - $customer = end($response['customers']); + if ($response->isSuccessful() && isset($response['customers'])) { + $customers = $response['customers']; + + if ($customers) { + $customer = end($customers); } } diff --git a/src/upload/system/library/retailcrm/retailcrm.php b/src/upload/system/library/retailcrm/retailcrm.php index 472e45e..525a43b 100644 --- a/src/upload/system/library/retailcrm/retailcrm.php +++ b/src/upload/system/library/retailcrm/retailcrm.php @@ -32,10 +32,6 @@ class Retailcrm { $setting = $this->model_setting_setting->getSetting($this->getModuleTitle()); - if (!$setting) { - return false; - } - if ($apiUrl === null && $apiKey === null) { $apiUrl = isset($setting[$this->getModuleTitle() . '_url']) ? $setting[$this->getModuleTitle() . '_url'] : '';