diff --git a/CHANGELOG.md b/CHANGELOG.md
index 631ecf8..ffb2271 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
* Улучшена механика выгрузки изменений из RetailCRM на сайт
* Улучшена механика выборки типов доставки на сайте
* Добавлена возможность периодической выгрузки акционных цен для товаров
+* Улучшена совместимость с Opencart 3.0
## v.2.4.3
* Устранены некоторые баги, добавлен вывод ошибок при выгрузке единичных заказов
diff --git a/admin/model/extension/retailcrm/history/v4_5.php b/admin/model/extension/retailcrm/history/v4_5.php
index 87f24aa..a3ee710 100644
--- a/admin/model/extension/retailcrm/history/v4_5.php
+++ b/admin/model/extension/retailcrm/history/v4_5.php
@@ -511,6 +511,7 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory
'status' => 1,
'approved' => 1,
'safe' => 0,
+ 'affiliate' => '',
'address' => array(
array(
'firstname' => isset($order['patronymic']) ? $order['firstName'] . ' ' . $order['patronymic'] : $order['firstName'],
@@ -626,7 +627,7 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory
if (isset($this->ocDelivery[$shippingModule][$data['shipping']]['title'])) {
$data['shipping_method'] = $this->ocDelivery[$shippingModule][$data['shipping']]['title'];
} else {
- $data['shipping_method'] =$this->ocDelivery[$shippingModule]['title'];
+ $data['shipping_method'] = $this->ocDelivery[$shippingModule]['title'];
}
if (isset($payment)) {
diff --git a/admin/view/template/extension/module/retailcrm.twig b/admin/view/template/extension/module/retailcrm.twig
index 0413bf3..8aa941d 100644
--- a/admin/view/template/extension/module/retailcrm.twig
+++ b/admin/view/template/extension/module/retailcrm.twig
@@ -97,7 +97,7 @@
- {% if saved_settings.retailcrm_apiversion is defined and saved_settings.retailcrm_apiversion. != 'v3' %}
+ {% if saved_settings.retailcrm_apiversion is defined and saved_settings.retailcrm_apiversion != 'v3' %}
{{ special_price_settings }}
diff --git a/catalog/controller/api/retailcrm.php b/catalog/controller/api/retailcrm.php
index a9c0039..e8164fa 100644
--- a/catalog/controller/api/retailcrm.php
+++ b/catalog/controller/api/retailcrm.php
@@ -131,17 +131,27 @@ class ControllerApiRetailcrm extends Controller
private function auth()
{
- if (!isset($this->request->get['token'])
- || !$this->request->get['token']
+ if (!isset($this->request->get['key'])
+ || !$this->request->get['key']
) {
return array('error' => 'Not found api key');
}
- if (isset($this->request->get['token'])
- && !empty($this->request->get['token'])
+ if (isset($this->request->get['key'])
+ && !empty($this->request->get['key'])
) {
$this->load->model('account/api');
- $api = $this->model_account_api->getApiByKey($this->request->get['token']);
+
+ 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']);
+ }
+ }
if (!empty($api)) {
return $api;
diff --git a/catalog/model/extension/retailcrm/api.php b/catalog/model/extension/retailcrm/api.php
new file mode 100644
index 0000000..b884a98
--- /dev/null
+++ b/catalog/model/extension/retailcrm/api.php
@@ -0,0 +1,11 @@
+db->query("SELECT * FROM `" . DB_PREFIX . "api` WHERE `username` = '" . $this->db->escape($username) . "' AND `key` = '" . $this->db->escape($key) . "' AND status = '1'");
+
+ return $query->row;
+ }
+}
diff --git a/system/library/retailcrm/OpencartApiClient.php b/system/library/retailcrm/OpencartApiClient.php
index 0b6f294..28813fc 100644
--- a/system/library/retailcrm/OpencartApiClient.php
+++ b/system/library/retailcrm/OpencartApiClient.php
@@ -39,7 +39,7 @@ class OpencartApiClient {
$cookies[$params[5]] = $params[6];
}
- if(isset($cookies[$cookieName])) {
+ if (isset($cookies[$cookieName])) {
return $cookies[$cookieName];
}
@@ -50,7 +50,20 @@ class OpencartApiClient {
$opencartStoreInfo = $this->model_setting_store->getStore($this->opencartStoreId);
if ($this->apiToken !== false) {
- $getParams['token'] = $this->apiToken;
+ if (version_compare(VERSION, '3.0', '<')) {
+ $getParams['key'] = $this->apiToken['key'];
+ } else {
+ $getParams['key'] = $this->apiToken['key'];
+ $getParams['username'] = $this->apiToken['username'];
+
+ if (isset($this->session->data['user_token'])) {
+ $getParams['api_token'] = $this->session->data['user_token'];
+ } else {
+ $session = $this->registry->get('session');
+ $session->start();
+ $getParams['api_token'] = $session->getId();
+ }
+ }
}
$postParams['fromApi'] = true;
@@ -121,8 +134,8 @@ class OpencartApiClient {
return false;
}
- if (isset($api['key'])) {
- $this->apiToken = $api['key'];
+ if (isset($api) && !empty($api)) {
+ $this->apiToken = $api;
} else {
$this->apiToken = false;
}