Update to v2.3 (#22)

* restruct for 2.3
* new files for 2.3
This commit is contained in:
iyzoer 2017-03-22 12:12:54 +03:00 committed by Alex Lushpai
parent 10459281f7
commit 3be4ac76a9
22 changed files with 166 additions and 234 deletions

View File

@ -1,39 +0,0 @@
Changelog
=========
####v0.3.0
* Расширена библиотека клиента
* Добавлена возможность кастомизации моделей заказа через vqmod
* Устранены мелкие баги, проведен рефакторинг кода.
####v0.2.0
Общие изменения
* Код приведен в состоянии совместимости с PHP 5.2
* Убрана необходимость собирать пакет через composer
* Библиотека api-client-php обновлена до последней версии и добавлена в стандартную поставку
* Переименованы методы, пути и значения ключей конфигурации в связи с ребрендингом
* Временая метка последнего запуска получения истории перенесена в таблицу конфигурации БД
Выгрузка каталога (ICML)
* Генерация обновлена в соответствии с последними измениями формата файла выгрузки
* Генерация вынесена в отдельный класс
* Добавлена возможность добавлять подкатегории
* Скорректировано указание активности офера
* Убрана генерация размера офера вследствие кастомизации этого параметра в разных магазинах
####v0.1.1
* Устранена ошибка редактирования, при которой терялась часть данных при получении истории из CRM
* Оптимизирован код получения и обработки истории заказов
* Актуализированы переводы
####v.0.1
* Реализован интерфейс настроек модуля
* Реализована отправка данных о заказе/клиенте в CRM
* Реализована выгрузка каталога (cron only)
* Реализовано получение данных о заказах, сделанных на стороне CRM (cron only)

View File

@ -1,7 +1,13 @@
Opencart module Opencart module
=============== ===============
Module allows integrate CMS Opencart 2.x with [retailCRM](http://retailcrm.pro) Module allows integrate CMS Opencart >= 2.3 with [retailCRM](http://retailcrm.pro)
### Previous versions:
[v1.x](https://github.com/retailcrm/opencart-module/tree/v1.x)
[v2.x (2.0, 2.1, 2.2)](https://github.com/retailcrm/opencart-module/tree/v2.2)
#### Features: #### Features:

View File

@ -1,7 +1,13 @@
Opencart module Opencart module
=============== ===============
Модуль интеграции CMS Openacart 2.x c [RetailCRM](http://retailcrm.ru) Модуль интеграции CMS Opencart >= 2.3 c [RetailCRM](http://retailcrm.ru)
### Предыдущие версии:
[v1.x](https://github.com/retailcrm/opencart-module/tree/v1.x)
[v2.x (2.0, 2.1, 2.2)](https://github.com/retailcrm/opencart-module/tree/v2.2)
#### Модуль позволяет: #### Модуль позволяет:

View File

@ -11,7 +11,7 @@ require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
* @license https://opensource.org/licenses/MIT MIT License * @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3
*/ */
class ControllerModuleRetailcrm extends Controller class ControllerExtensionModuleRetailcrm extends Controller
{ {
private $_error = array(); private $_error = array();
protected $log, $statuses, $payments, $deliveryTypes, $retailcrm; protected $log, $statuses, $payments, $deliveryTypes, $retailcrm;
@ -33,22 +33,29 @@ class ControllerModuleRetailcrm extends Controller
$this->model_extension_event $this->model_extension_event
->addEvent( ->addEvent(
'retailcrm', 'retailcrm',
version_compare(VERSION, '2.2', '>=') ? 'catalog/model/checkout/order/addOrder/after' : 'post.order.add', 'catalog/model/checkout/order/addOrder/after',
'module/retailcrm/order_create' 'extension/module/retailcrm/order_create'
); );
$this->model_extension_event $this->model_extension_event
->addEvent( ->addEvent(
'retailcrm', 'retailcrm',
version_compare(VERSION, '2.2', '>=') ? 'catalog/model/checkout/order/addOrderHistory/after' : 'post.order.history.add', 'catalog/model/checkout/order/addOrderHistory/after',
'module/retailcrm/order_edit' 'extension/module/retailcrm/order_edit'
); );
$this->model_extension_event $this->model_extension_event
->addEvent( ->addEvent(
'retailcrm', 'retailcrm',
version_compare(VERSION, '2.2', '>=') ? 'catalog/model/account/customer/addCustomer/after' : 'post.customer.add', 'catalog/model/account/customer/addCustomer/after',
'module/retailcrm/customer_create' 'extension/module/retailcrm/customer_create'
);
$this->model_extension_event
->addEvent(
'retailcrm',
'catalog/model/checkout/order/editOrder/after',
'extension/module/retailcrm/order_edit'
); );
} }
@ -77,12 +84,16 @@ class ControllerModuleRetailcrm extends Controller
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$this->load->model('extension/module'); $this->load->model('extension/module');
$this->load->model('retailcrm/references'); $this->load->model('extension/retailcrm/references');
$this->load->language('module/retailcrm'); $this->load->language('extension/module/retailcrm');
$this->document->setTitle($this->language->get('heading_title')); $this->document->setTitle($this->language->get('heading_title'));
$this->document->addStyle('/admin/view/stylesheet/retailcrm.css'); $this->document->addStyle('/admin/view/stylesheet/retailcrm.css');
if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) { if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
if (parse_url($this->request->post['retailcrm_url'])){
$crm_url = parse_url($this->request->post['retailcrm_url'], PHP_URL_HOST);
$this->request->post['retailcrm_url'] = 'https://'.$crm_url;
}
$this->model_setting_setting->editSetting( $this->model_setting_setting->editSetting(
'retailcrm', 'retailcrm',
$this->request->post $this->request->post
@ -90,7 +101,7 @@ class ControllerModuleRetailcrm extends Controller
$this->session->data['success'] = $this->language->get('text_success'); $this->session->data['success'] = $this->language->get('text_success');
$redirect = $this->url->link( $redirect = $this->url->link(
'module/retailcrm', 'token=' . $this->session->data['token'], 'extension/module/retailcrm', 'token=' . $this->session->data['token'],
'SSL' 'SSL'
); );
@ -137,14 +148,14 @@ class ControllerModuleRetailcrm extends Controller
$this->retailcrm = new RetailcrmProxy( $this->retailcrm = new RetailcrmProxy(
$url, $url,
$key, $key,
DIR_SYSTEM . 'logs/retailcrm.log' DIR_SYSTEM . 'storage/logs/retailcrm.log'
); );
$_data['delivery'] = $this->model_retailcrm_references $_data['delivery'] = $this->model_extension_retailcrm_references
->getDeliveryTypes(); ->getDeliveryTypes();
$_data['statuses'] = $this->model_retailcrm_references $_data['statuses'] = $this->model_extension_retailcrm_references
->getOrderStatuses(); ->getOrderStatuses();
$_data['payments'] = $this->model_retailcrm_references $_data['payments'] = $this->model_extension_retailcrm_references
->getPaymentTypes(); ->getPaymentTypes();
} }
@ -181,7 +192,7 @@ class ControllerModuleRetailcrm extends Controller
$_data['breadcrumbs'][] = array( $_data['breadcrumbs'][] = array(
'text' => $this->language->get('text_module'), 'text' => $this->language->get('text_module'),
'href' => $this->url->link( 'href' => $this->url->link(
'extension/module', 'extension/extension/module',
'token=' . $this->session->data['token'], 'SSL' 'token=' . $this->session->data['token'], 'SSL'
), ),
'separator' => ' :: ' 'separator' => ' :: '
@ -190,19 +201,19 @@ class ControllerModuleRetailcrm extends Controller
$_data['breadcrumbs'][] = array( $_data['breadcrumbs'][] = array(
'text' => $this->language->get('retailcrm_title'), 'text' => $this->language->get('retailcrm_title'),
'href' => $this->url->link( 'href' => $this->url->link(
'module/retailcrm', 'extension/module/retailcrm',
'token=' . $this->session->data['token'], 'SSL' 'token=' . $this->session->data['token'], 'SSL'
), ),
'separator' => ' :: ' 'separator' => ' :: '
); );
$_data['action'] = $this->url->link( $_data['action'] = $this->url->link(
'module/retailcrm', 'extension/module/retailcrm',
'token=' . $this->session->data['token'], 'SSL' 'token=' . $this->session->data['token'], 'SSL'
); );
$_data['cancel'] = $this->url->link( $_data['cancel'] = $this->url->link(
'extension/module', 'extension/extension',
'token=' . $this->session->data['token'], 'SSL' 'token=' . $this->session->data['token'], 'SSL'
); );
@ -222,7 +233,7 @@ class ControllerModuleRetailcrm extends Controller
$_data['footer'] = $this->load->controller('common/footer'); $_data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput( $this->response->setOutput(
$this->load->view('module/retailcrm.tpl', $_data) $this->load->view('extension/module/retailcrm.tpl', $_data)
); );
} }
@ -233,12 +244,12 @@ class ControllerModuleRetailcrm extends Controller
*/ */
public function history() public function history()
{ {
if (file_exists(DIR_APPLICATION . 'model/retailcrm/custom/history.php')) { if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/history.php')) {
$this->load->model('retailcrm/custom/history'); $this->load->model('extension/retailcrm/custom/history');
$this->model_retailcrm_custom_history->request(); $this->model_extension_retailcrm_custom_history->request();
} else { } else {
$this->load->model('retailcrm/history'); $this->load->model('extension/retailcrm/history');
$this->model_retailcrm_history->request(); $this->model_extension_retailcrm_history->request();
} }
} }
@ -249,12 +260,12 @@ class ControllerModuleRetailcrm extends Controller
*/ */
public function icml() public function icml()
{ {
if (file_exists(DIR_APPLICATION . 'model/retailcrm/custom/icml.php')) { if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/icml.php')) {
$this->load->model('retailcrm/custom/icml'); $this->load->model('extension/retailcrm/custom/icml');
$this->model_retailcrm_custom_icml->generateICML(); $this->model_extension_retailcrm_custom_icml->generateICML();
} else { } else {
$this->load->model('retailcrm/icml'); $this->load->model('extension/retailcrm/icml');
$this->model_retailcrm_icml->generateICML(); $this->model_extension_retailcrm_icml->generateICML();
} }
} }
@ -278,8 +289,8 @@ class ControllerModuleRetailcrm extends Controller
$status = $this->model_setting_setting->getSetting('retailcrm'); $status = $this->model_setting_setting->getSetting('retailcrm');
$data['order_status'] = $status['retailcrm_status'][$data['order_status_id']]; $data['order_status'] = $status['retailcrm_status'][$data['order_status_id']];
$this->load->model('retailcrm/order'); $this->load->model('extension/retailcrm/order');
$this->model_retailcrm_order->sendToCrm($data, $data['order_id']); $this->model_extension_retailcrm_order->sendToCrm($data, $data['order_id']);
} }
} }
@ -289,16 +300,12 @@ class ControllerModuleRetailcrm extends Controller
* *
*/ */
public function export() { public function export() {
if(version_compare(VERSION, '2.1', '<')) {
$this->load->model('sale/customer');
$customers = $this->model_sale_customer->getCustomers();
} else {
$this->load->model('customer/customer');
$customers = $this->model_customer_customer->getCustomers();
}
$this->load->model('retailcrm/customer'); $this->load->model('customer/customer');
$this->model_retailcrm_customer->uploadToCrm($customers); $customers = $this->model_customer_customer->getCustomers();
$this->load->model('extension/retailcrm/customer');
$this->model_extension_retailcrm_customer->uploadToCrm($customers);
$this->load->model('sale/order'); $this->load->model('sale/order');
$orders = $this->model_sale_order->getOrders(); $orders = $this->model_sale_order->getOrders();
@ -317,8 +324,8 @@ class ControllerModuleRetailcrm extends Controller
$fullOrders[] = $fullOrder; $fullOrders[] = $fullOrder;
} }
$this->load->model('retailcrm/order'); $this->load->model('extension/retailcrm/order');
$this->model_retailcrm_order->uploadToCrm($fullOrders); $this->model_extension_retailcrm_order->uploadToCrm($fullOrders);
} }
/** /**
@ -328,7 +335,7 @@ class ControllerModuleRetailcrm extends Controller
*/ */
private function validate() private function validate()
{ {
if (!$this->user->hasPermission('modify', 'module/retailcrm')) { if (!$this->user->hasPermission('modify', 'extension/module/retailcrm')) {
$this->_error['warning'] = $this->language->get('error_permission'); $this->_error['warning'] = $this->language->get('error_permission');
} }

View File

@ -1,6 +1,6 @@
<?php <?php
class ModelRetailcrmCustomer extends Model { class ModelExtensionRetailcrmCustomer extends Model {
public function uploadToCrm($customers) { public function uploadToCrm($customers) {
$this->load->model('setting/setting'); $this->load->model('setting/setting');
@ -16,7 +16,7 @@ class ModelRetailcrmCustomer extends Model {
$this->retailcrmApi = new RetailcrmProxy( $this->retailcrmApi = new RetailcrmProxy(
$settings['retailcrm_url'], $settings['retailcrm_url'],
$settings['retailcrm_apikey'], $settings['retailcrm_apikey'],
DIR_SYSTEM . 'logs/retailcrm.log' DIR_SYSTEM . 'storage/logs/retailcrm.log'
); );
$customersToCrm = array(); $customersToCrm = array();

View File

@ -1,6 +1,6 @@
<?php <?php
class ModelRetailcrmHistory extends Model class ModelExtensionRetailcrmHistory extends Model
{ {
protected $createResult; protected $createResult;
@ -12,17 +12,13 @@ class ModelRetailcrmHistory extends Model
$this->load->model('setting/store'); $this->load->model('setting/store');
$this->load->model('user/api'); $this->load->model('user/api');
$this->load->model('sale/order'); $this->load->model('sale/order');
if (version_compare(VERSION, '2.1.0.0', '>=')) { $this->load->model('customer/customer');
$this->load->model('customer/customer'); $this->load->model('extension/retailcrm/references');
} else {
$this->load->model('sale/customer');
}
$this->load->model('retailcrm/references');
$this->load->model('catalog/product'); $this->load->model('catalog/product');
$this->load->model('catalog/option'); $this->load->model('catalog/option');
$this->load->model('localisation/zone'); $this->load->model('localisation/zone');
$this->load->language('module/retailcrm'); $this->load->language('extension/module/retailcrm');
$settings = $this->model_setting_setting->getSetting('retailcrm'); $settings = $this->model_setting_setting->getSetting('retailcrm');
$history = $this->model_setting_setting->getSetting('retailcrm_history'); $history = $this->model_setting_setting->getSetting('retailcrm_history');
@ -41,7 +37,7 @@ class ModelRetailcrmHistory extends Model
$crm = new RetailcrmProxy( $crm = new RetailcrmProxy(
$settings['retailcrm_url'], $settings['retailcrm_url'],
$settings['retailcrm_apikey'], $settings['retailcrm_apikey'],
DIR_SYSTEM . 'logs/retailcrm.log' DIR_SYSTEM . 'storage/logs/retailcrm.log'
); );
$lastRun = !empty($history['retailcrm_history']) $lastRun = !empty($history['retailcrm_history'])
@ -65,10 +61,10 @@ class ModelRetailcrmHistory extends Model
$this->payment = array_flip($settings['retailcrm_payment']); $this->payment = array_flip($settings['retailcrm_payment']);
$this->status = array_flip($settings['retailcrm_status']); $this->status = array_flip($settings['retailcrm_status']);
$this->ocPayment = $this->model_retailcrm_references $this->ocPayment = $this->model_extension_retailcrm_references
->getOpercartPaymentTypes(); ->getOpercartPaymentTypes();
$this->ocDelivery = $this->model_retailcrm_references $this->ocDelivery = $this->model_extension_retailcrm_references
->getOpercartDeliveryTypes(); ->getOpercartDeliveryTypes();
$this->zones = $this->model_localisation_zone->getZones(); $this->zones = $this->model_localisation_zone->getZones();
@ -314,25 +310,14 @@ class ModelRetailcrmHistory extends Model
), ),
); );
if (version_compare(VERSION, '2.1.0.0', '>=')) {
$this->model_customer_customer->addCustomer($cData); $this->model_customer_customer->addCustomer($cData);
} else {
$this->model_sale_customer->addCustomer($cData);
}
if (!empty($order['email'])) { if (!empty($order['email'])) {
if (version_compare(VERSION, '2.1.0.0', '>=')) { $tryToFind = $this->model_customer_customer->getCustomerByEmail($order['email']);
$tryToFind = $this->model_customer_customer->getCustomerByEmail($order['email']);
} else {
$tryToFind = $this->model_sale_customer->getCustomerByEmail($order['email']);
}
$customer_id = $tryToFind['customer_id']; $customer_id = $tryToFind['customer_id'];
} else { } else {
if (version_compare(VERSION, '2.1.0.0', '>=')) { $last = $this->model_customer_customer->getCustomers($data = array('order' => 'DESC', 'limit' => 1));
$last = $this->model_customer_customer->getCustomers($data = array('order' => 'DESC', 'limit' => 1));
} else {
$last = $this->model_sale_customer->getCustomers($data = array('order' => 'DESC', 'limit' => 1));
}
$customer_id = $last[0]['customer_id']; $customer_id = $last[0]['customer_id'];
} }

View File

@ -1,6 +1,6 @@
<?php <?php
class ModelRetailcrmIcml extends Model class ModelExtensionRetailcrmIcml extends Model
{ {
protected $shop; protected $shop;
protected $file; protected $file;
@ -15,7 +15,7 @@ class ModelRetailcrmIcml extends Model
public function generateICML() public function generateICML()
{ {
$this->load->language('module/retailcrm'); $this->load->language('extension/module/retailcrm');
$this->load->model('catalog/category'); $this->load->model('catalog/category');
$this->load->model('catalog/product'); $this->load->model('catalog/product');
$this->load->model('catalog/option'); $this->load->model('catalog/option');
@ -297,17 +297,16 @@ class ModelRetailcrmIcml extends Model
{ {
$this->load->model('tool/image'); $this->load->model('tool/image');
if (version_compare(VERSION, '2.2', '>=')) { $currentTheme = $this->config->get('config_theme');
$currentTheme = $this->config->get('config_theme'); $width = $this->config->get($currentTheme . '_image_related_width') ? $this->config->get($currentTheme . '_image_related_width') : 200;
$width = $this->config->get($currentTheme . '_image_related_width') ? $this->config->get($currentTheme . '_image_related_width') : 200; $height = $this->config->get($currentTheme . '_image_related_height') ? $this->config->get($currentTheme . '_image_related_height') : 200;
$height = $this->config->get($currentTheme . '_image_related_height') ? $this->config->get($currentTheme . '_image_related_height') : 200;
return $this->model_tool_image->resize(
$image,
$width,
$height
);
return $this->model_tool_image->resize(
$image,
$width,
$height
);
}
return $this->model_tool_image->resize( return $this->model_tool_image->resize(
$image, $image,

View File

@ -1,6 +1,6 @@
<?php <?php
class ModelRetailcrmOrder extends Model { class ModelExtensionRetailcrmOrder extends Model {
public function uploadToCrm($orders) { public function uploadToCrm($orders) {
$this->load->model('catalog/product'); $this->load->model('catalog/product');

View File

@ -2,7 +2,7 @@
require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php'; require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
class ModelRetailcrmReferences extends Model class ModelExtensionRetailcrmReferences extends Model
{ {
protected $retailcrm; protected $retailcrm;
@ -33,13 +33,13 @@ class ModelRetailcrmReferences extends Model
public function getOpercartDeliveryTypes() public function getOpercartDeliveryTypes()
{ {
$deliveryMethods = array(); $deliveryMethods = array();
$files = glob(DIR_APPLICATION . 'controller/shipping/*.php'); $files = glob(DIR_APPLICATION . 'controller/extension/shipping/*.php');
if ($files) { if ($files) {
foreach ($files as $file) { foreach ($files as $file) {
$extension = basename($file, '.php'); $extension = basename($file, '.php');
$this->load->language('shipping/' . $extension); $this->load->language('extension/shipping/' . $extension);
if ($this->config->get($extension . '_status')) { if ($this->config->get($extension . '_status')) {
$deliveryMethods[$extension.'.'.$extension] = strip_tags( $deliveryMethods[$extension.'.'.$extension] = strip_tags(
@ -63,13 +63,13 @@ class ModelRetailcrmReferences extends Model
public function getOpercartPaymentTypes() public function getOpercartPaymentTypes()
{ {
$paymentTypes = array(); $paymentTypes = array();
$files = glob(DIR_APPLICATION . 'controller/payment/*.php'); $files = glob(DIR_APPLICATION . 'controller/extension/payment/*.php');
if ($files) { if ($files) {
foreach ($files as $file) { foreach ($files as $file) {
$extension = basename($file, '.php'); $extension = basename($file, '.php');
$this->load->language('payment/' . $extension); $this->load->language('extension/payment/' . $extension);
if ($this->config->get($extension . '_status')) { if ($this->config->get($extension . '_status')) {
$paymentTypes[$extension] = strip_tags( $paymentTypes[$extension] = strip_tags(
@ -91,7 +91,7 @@ class ModelRetailcrmReferences extends Model
$this->retailcrm = new RetailcrmProxy( $this->retailcrm = new RetailcrmProxy(
$settings['retailcrm_url'], $settings['retailcrm_url'],
$settings['retailcrm_apikey'], $settings['retailcrm_apikey'],
DIR_SYSTEM . 'logs/retailcrm.log' DIR_SYSTEM . 'storage/logs/retailcrm.log'
); );
$response = $this->retailcrm->deliveryTypesList(); $response = $this->retailcrm->deliveryTypesList();
@ -109,7 +109,7 @@ class ModelRetailcrmReferences extends Model
$this->retailcrm = new RetailcrmProxy( $this->retailcrm = new RetailcrmProxy(
$settings['retailcrm_url'], $settings['retailcrm_url'],
$settings['retailcrm_apikey'], $settings['retailcrm_apikey'],
DIR_SYSTEM . 'logs/retailcrm.log' DIR_SYSTEM . 'storage/logs/retailcrm.log'
); );
$response = $this->retailcrm->statusesList(); $response = $this->retailcrm->statusesList();
@ -127,7 +127,7 @@ class ModelRetailcrmReferences extends Model
$this->retailcrm = new RetailcrmProxy( $this->retailcrm = new RetailcrmProxy(
$settings['retailcrm_url'], $settings['retailcrm_url'],
$settings['retailcrm_apikey'], $settings['retailcrm_apikey'],
DIR_SYSTEM . 'logs/retailcrm.log' DIR_SYSTEM . 'storage/logs/retailcrm.log'
); );
$response = $this->retailcrm->paymentTypesList(); $response = $this->retailcrm->paymentTypesList();

View File

@ -9,7 +9,7 @@
* @license https://opensource.org/licenses/MIT MIT License * @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion3 * @link http://www.retailcrm.ru/docs/Developers/ApiVersion3
*/ */
class ControllerModuleRetailcrm extends Controller class ControllerExtensionModuleRetailcrm extends Controller
{ {
/** /**
* Create order on event * Create order on event
@ -18,15 +18,12 @@ class ControllerModuleRetailcrm extends Controller
* *
* @return void * @return void
*/ */
public function order_create($parameter1, $parameter2 = null) public function order_create($parameter1, $parameter2 = null, $parameter3 = null)
{ {
$this->load->model('checkout/order'); $this->load->model('checkout/order');
$this->load->model('account/order'); $this->load->model('account/order');
if($parameter2 != null) $order_id = $parameter3;
$order_id = $parameter2;
else
$order_id = $parameter1;
$data = $this->model_checkout_order->getOrder($order_id); $data = $this->model_checkout_order->getOrder($order_id);
@ -50,16 +47,13 @@ class ControllerModuleRetailcrm extends Controller
'value' => $this->session->data['shipping_method']['cost'] 'value' => $this->session->data['shipping_method']['cost']
); );
$this->load->model('retailcrm/order'); $this->load->model('extension/retailcrm/order');
$this->model_retailcrm_order->sendToCrm($data, $data['order_id']); $this->model_extension_retailcrm_order->sendToCrm($data, $data['order_id']);
} }
} }
public function order_edit($parameter1, $parameter2 = null, $parameter3 = null, $parameter4 = null) { public function order_edit($parameter1, $parameter2 = null) {
if($parameter4 != null) $order_id = $parameter2[0];
$order_id = $parameter3;
else
$order_id = $parameter1;
$this->load->model('checkout/order'); $this->load->model('checkout/order');
$this->load->model('account/order'); $this->load->model('account/order');
@ -90,8 +84,8 @@ class ControllerModuleRetailcrm extends Controller
'value' => isset($this->session->data['shipping_method']) ? $this->session->data['shipping_method']['cost'] : '' 'value' => isset($this->session->data['shipping_method']) ? $this->session->data['shipping_method']['cost'] : ''
); );
$this->load->model('retailcrm/order'); $this->load->model('extension/retailcrm/order');
$this->model_retailcrm_order->changeInCrm($data, $data['order_id']); $this->model_extension_retailcrm_order->changeInCrm($data, $data['order_id']);
} }
} }
@ -102,16 +96,13 @@ class ControllerModuleRetailcrm extends Controller
* *
* @return void * @return void
*/ */
public function customer_create($parameter1, $parameter2 = null) { public function customer_create($parameter1, $parameter2 = null, $parameter3 = null) {
if($parameter2 != null) $customerId = $parameter3;
$customerId = $parameter2;
else
$customerId = $parameter1;
$this->load->model('account/customer'); $this->load->model('account/customer');
$customer = $this->model_account_customer->getCustomer($customerId); $customer = $this->model_account_customer->getCustomer($customerId);
$this->load->model('retailcrm/customer'); $this->load->model('extension/retailcrm/customer');
$this->model_retailcrm_customer->sendToCrm($customer); $this->model_extension_retailcrm_customer->sendToCrm($customer);
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
class ModelRetailcrmCustomer extends Model { class ModelExtensionRetailcrmCustomer extends Model {
public function sendToCrm($customer) { public function sendToCrm($customer) {
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$settings = $this->model_setting_setting->getSetting('retailcrm'); $settings = $this->model_setting_setting->getSetting('retailcrm');
@ -15,7 +15,7 @@ class ModelRetailcrmCustomer extends Model {
$this->retailcrmApi = new RetailcrmProxy( $this->retailcrmApi = new RetailcrmProxy(
$settings['retailcrm_url'], $settings['retailcrm_url'],
$settings['retailcrm_apikey'], $settings['retailcrm_apikey'],
DIR_SYSTEM . 'logs/retailcrm.log' DIR_SYSTEM . 'storage/logs/retailcrm.log'
); );
$customerToCrm = $this->process($customer); $customerToCrm = $this->process($customer);

View File

@ -1,6 +1,6 @@
<?php <?php
class ModelRetailcrmOrder extends Model { class ModelExtensionRetailcrmOrder extends Model {
public function sendToCrm($order_data, $order_id) public function sendToCrm($order_data, $order_id)
{ {
@ -17,7 +17,7 @@ class ModelRetailcrmOrder extends Model {
$this->retailcrm = new RetailcrmProxy( $this->retailcrm = new RetailcrmProxy(
$settings['retailcrm_url'], $settings['retailcrm_url'],
$settings['retailcrm_apikey'], $settings['retailcrm_apikey'],
DIR_SYSTEM . 'logs/retailcrm.log' DIR_SYSTEM . 'storage/logs/retailcrm.log'
); );
$order = array(); $order = array();
@ -157,7 +157,7 @@ class ModelRetailcrmOrder extends Model {
$this->retailcrm = new RetailcrmProxy( $this->retailcrm = new RetailcrmProxy(
$settings['retailcrm_url'], $settings['retailcrm_url'],
$settings['retailcrm_apikey'], $settings['retailcrm_apikey'],
DIR_SYSTEM . 'logs/retailcrm.log' DIR_SYSTEM . 'storage/logs/retailcrm.log'
); );
$order = array(); $order = array();
@ -191,7 +191,6 @@ class ModelRetailcrmOrder extends Model {
$order['delivery'] = array( $order['delivery'] = array(
'code' => !empty($delivery_code) ? $settings['retailcrm_delivery'][$delivery_code] : '', 'code' => !empty($delivery_code) ? $settings['retailcrm_delivery'][$delivery_code] : '',
'cost' => $deliveryCost,
'address' => array( 'address' => array(
'index' => $order_data['shipping_postcode'], 'index' => $order_data['shipping_postcode'],
'city' => $order_data['shipping_city'], 'city' => $order_data['shipping_city'],
@ -206,6 +205,9 @@ class ModelRetailcrmOrder extends Model {
)) ))
) )
); );
if(!empty($deliveryCost)){
$order['delivery']['cost'] = $deliveryCost;
}
$orderProducts = isset($order_data['products']) ? $order_data['products'] : $order_data['order_product']; $orderProducts = isset($order_data['products']) ? $order_data['products'] : $order_data['order_product'];
$offerOptions = array('select', 'radio'); $offerOptions = array('select', 'radio');

View File

@ -34,17 +34,12 @@ if (!defined('DIR_APPLICATION')) {
require_once(DIR_SYSTEM . 'startup.php'); require_once(DIR_SYSTEM . 'startup.php');
// Application Classes // Application Classes
if (version_compare(VERSION, '2.2', '>=')) { require_once(DIR_SYSTEM . 'library/cart/currency.php');
require_once(DIR_SYSTEM . 'library/cart/currency.php'); require_once(DIR_SYSTEM . 'library/cart/user.php');
require_once(DIR_SYSTEM . 'library/cart/user.php'); require_once(DIR_SYSTEM . 'library/cart/weight.php');
require_once(DIR_SYSTEM . 'library/cart/weight.php'); require_once(DIR_SYSTEM . 'library/cart/length.php');
require_once(DIR_SYSTEM . 'library/cart/length.php');
} else {
require_once(DIR_SYSTEM . 'library/currency.php');
require_once(DIR_SYSTEM . 'library/user.php');
require_once(DIR_SYSTEM . 'library/weight.php');
require_once(DIR_SYSTEM . 'library/length.php');
}
// Registry // Registry
$registry = new Registry(); $registry = new Registry();
@ -68,10 +63,7 @@ foreach ($query->rows as $setting) {
if (!$setting['serialized']) { if (!$setting['serialized']) {
$config->set($setting['key'], $setting['value']); $config->set($setting['key'], $setting['value']);
} else { } else {
if (version_compare(VERSION, '2.1', '>=')) $config->set($setting['key'], json_decode($setting['value']), true);
$config->set($setting['key'], json_decode($setting['value']), true);
else
$config->set($setting['key'], unserialize($setting['value']));
} }
} }
@ -85,10 +77,9 @@ $registry->set('log', $log);
// Event // Event
if (version_compare(VERSION, '2.2', '>=')) { $event = new Event($registry);
$event = new Event($registry); $registry->set('event', $event);
$registry->set('event', $event);
}
function error_handler($errno, $errstr, $errfile, $errline) { function error_handler($errno, $errstr, $errfile, $errline) {
global $log, $config; global $log, $config;
@ -153,17 +144,12 @@ $registry->set('language', $language);
$document = new Document(); $document = new Document();
$registry->set('document', $document); $registry->set('document', $document);
if (version_compare(VERSION, '2.2', '>=')) {
$registry->set('currency', new Cart\Currency($registry)); $registry->set('currency', new Cart\Currency($registry));
$registry->set('weight', new Cart\Weight($registry)); $registry->set('weight', new Cart\Weight($registry));
$registry->set('length', new Cart\Length($registry)); $registry->set('length', new Cart\Length($registry));
$registry->set('user', new Cart\User($registry)); $registry->set('user', new Cart\User($registry));
} else {
$registry->set('currency', new Currency($registry));
$registry->set('weight', new Weight($registry));
$registry->set('length', new Length($registry));
$registry->set('user', new User($registry));
}
$controller = new Front($registry); $controller = new Front($registry);
$action = new Action($cli_action); $action = new Action($cli_action);

View File

@ -1,3 +1,3 @@
<?php <?php
$cli_action = 'module/retailcrm/export'; $cli_action = 'extension/module/retailcrm/export';
require_once('dispatch.php'); require_once('dispatch.php');

View File

@ -1,3 +1,3 @@
<?php <?php
$cli_action = 'module/retailcrm/history'; $cli_action = 'extension/module/retailcrm/history';
require_once('dispatch.php'); require_once('dispatch.php');

View File

@ -1,3 +1,3 @@
<?php <?php
$cli_action = 'module/retailcrm/icml'; $cli_action = 'extension/module/retailcrm/icml';
require_once('dispatch.php'); require_once('dispatch.php');

View File

@ -43,7 +43,7 @@ class OpencartApiClient {
public function request($method, $getParams, $postParams) { public function request($method, $getParams, $postParams) {
$opencartStoreInfo = $this->model_setting_store->getStore($this->opencartStoreId); $opencartStoreInfo = $this->model_setting_store->getStore($this->opencartStoreId);
if(version_compare(VERSION, '2.1.0', '>=') && !empty($this->apiToken)) { if(!empty($this->apiToken)) {
$getParams['token'] = $this->apiToken; $getParams['token'] = $this->apiToken;
} }
@ -89,19 +89,10 @@ class OpencartApiClient {
$api = array(); $api = array();
foreach ($apiUsers as $apiUser) { foreach ($apiUsers as $apiUser) {
if($apiUser['status'] == 1) { if($apiUser['status'] == 1) {
if(version_compare(VERSION, '2.1.0', '>=')) { $api = array(
$api = array( 'api_id' => $apiUser['api_id'],
'api_id' => $apiUser['api_id'], 'key' => $apiUser['key']
'key' => $apiUser['key'] );
);
} else {
$api = array(
'api_id' => $apiUser['api_id'],
'username' => $apiUser['username'],
'password' => $apiUser['password']
);
}
break; break;
} }
} }
@ -109,26 +100,24 @@ class OpencartApiClient {
if(!isset($api['api_id'])) if(!isset($api['api_id']))
return false; return false;
if(version_compare(VERSION, '2.1.0', '>=')) {
$alreadyBinded = false;
$innerIp = $this->getInnerIpAddr(); $alreadyBinded = false;
$apiIps = $this->model_user_api->getApiIps($api['api_id']);
foreach($apiIps as $apiIp) {
if($apiIp['ip'] == $innerIp)
$alreadyBinded = true;
}
if(!$alreadyBinded) { $innerIp = $this->getInnerIpAddr();
$this->model_user_api->addApiIp($api['api_id'], $innerIp); $apiIps = $this->model_user_api->getApiIps($api['api_id']);
} foreach($apiIps as $apiIp) {
if($apiIp['ip'] == $innerIp)
$alreadyBinded = true;
} }
if(!$alreadyBinded) {
$this->model_user_api->addApiIp($api['api_id'], $innerIp);
}
$apiAnswer = $this->request('login', array(), $apiUser); $apiAnswer = $this->request('login', array(), $apiUser);
if(version_compare(VERSION, '2.1.0', '>=')) { $this->apiToken = $apiAnswer['token'];
$this->apiToken = $apiAnswer['token'];
}
return $apiAnswer; return $apiAnswer;
} }

View File

@ -12,7 +12,7 @@ class RetailcrmHistoryHelper {
$orders = array(); $orders = array();
foreach ($orderHistory as $change) { foreach ($orderHistory as $change) {
$change['order'] = self::removeEmpty($change['order']); $change['order'] = self::removeEmpty($change['order']);
if($change['order']['items']) { if(isset($change['order']['items']) && $change['order']['items']) {
$items = array(); $items = array();
foreach($change['order']['items'] as $item) { foreach($change['order']['items'] as $item) {
if(isset($change['created'])) { if(isset($change['created'])) {
@ -23,18 +23,18 @@ class RetailcrmHistoryHelper {
$change['order']['items'] = $items; $change['order']['items'] = $items;
} }
if($change['order']['contragent']['contragentType']) { if(isset($change['order']['contragent']['contragentType']) && $change['order']['contragent']['contragentType']) {
$change['order']['contragentType'] = $change['order']['contragent']['contragentType']; $change['order']['contragentType'] = $change['order']['contragent']['contragentType'];
unset($change['order']['contragent']); unset($change['order']['contragent']);
} }
if($orders[$change['order']['id']]) { if(!empty($orders) && $orders[$change['order']['id']]) {
$orders[$change['order']['id']] = array_merge($orders[$change['order']['id']], $change['order']); $orders[$change['order']['id']] = array_merge($orders[$change['order']['id']], $change['order']);
} else { } else {
$orders[$change['order']['id']] = $change['order']; $orders[$change['order']['id']] = $change['order'];
} }
if($change['item']) { if(isset($change['item']) && $change['item']) {
if($orders[$change['order']['id']]['items'][$change['item']['id']]) { if($orders[$change['order']['id']]['items'][$change['item']['id']]) {
$orders[$change['order']['id']]['items'][$change['item']['id']] = array_merge($orders[$change['order']['id']]['items'][$change['item']['id']], $change['item']); $orders[$change['order']['id']]['items'][$change['item']['id']] = array_merge($orders[$change['order']['id']]['items'][$change['item']['id']], $change['item']);
} else { } else {
@ -51,15 +51,15 @@ class RetailcrmHistoryHelper {
$orders[$change['order']['id']]['items'][$change['item']['id']][$fields['item'][$change['field']]] = $change['newValue']; $orders[$change['order']['id']]['items'][$change['item']['id']][$fields['item'][$change['field']]] = $change['newValue'];
} }
} else { } else {
if($fields['delivery'][$change['field']] == 'service') { if(isset($fields['delivery'][$change['field']]) && $fields['delivery'][$change['field']] == 'service'){
$orders[$change['order']['id']]['delivery']['service']['code'] = self::newValue($change['newValue']); $orders[$change['order']['id']]['delivery']['service']['code'] = self::newValue($change['newValue']);
} elseif($fields['delivery'][$change['field']]) { } elseif(isset($fields['delivery'][$change['field']]) && $fields['delivery'][$change['field']]) {
$orders[$change['order']['id']]['delivery'][$fields['delivery'][$change['field']]] = self::newValue($change['newValue']); $orders[$change['order']['id']]['delivery'][$fields['delivery'][$change['field']]] = self::newValue($change['newValue']);
} elseif($fields['orderAddress'][$change['field']]) { } elseif(isset($fields['orderAddress'][$change['field']]) && $fields['orderAddress'][$change['field']]){
$orders[$change['order']['id']]['delivery']['address'][$fields['orderAddress'][$change['field']]] = $change['newValue']; $orders[$change['order']['id']]['delivery']['address'][$fields['orderAddress'][$change['field']]] = $change['newValue'];
} elseif($fields['integrationDelivery'][$change['field']]) { } elseif(isset($fields['integrationDelivery'][$change['field']]) && $fields['integrationDelivery'][$change['field']]) {
$orders[$change['order']['id']]['delivery']['service'][$fields['integrationDelivery'][$change['field']]] = self::newValue($change['newValue']); $orders[$change['order']['id']]['delivery']['service'][$fields['integrationDelivery'][$change['field']]] = self::newValue($change['newValue']);
} elseif($fields['customerContragent'][$change['field']]) { } elseif(isset($fields['customerContragent'][$change['field']]) && $fields['customerContragent'][$change['field']]) {
$orders[$change['order']['id']][$fields['customerContragent'][$change['field']]] = self::newValue($change['newValue']); $orders[$change['order']['id']][$fields['customerContragent'][$change['field']]] = self::newValue($change['newValue']);
} elseif(strripos($change['field'], 'custom_') !== false) { } elseif(strripos($change['field'], 'custom_') !== false) {
$orders[$change['order']['id']]['customFields'][str_replace('custom_', '', $change['field'])] = self::newValue($change['newValue']); $orders[$change['order']['id']]['customFields'][str_replace('custom_', '', $change['field'])] = self::newValue($change['newValue']);