diff --git a/Changelog.md b/Changelog.md
new file mode 100644
index 0000000..f30fb5a
--- /dev/null
+++ b/Changelog.md
@@ -0,0 +1,32 @@
+Changelog
+=========
+
+####v0.2.0
+
+Общие изменения
+
+* Код приведен в состоянии совместимости с PHP 5.2
+* Убрана необходимость собирать пакет через composer
+* Библиотека api-client-php обновлена до последней версии и добавлена в стандартную поставку
+* Переименованы методы, пути и значения ключей конфигурации в связи с ребрендингом
+* Временая метка последнего запуска получения истории перенесена в таблицу конфигурации БД
+
+Выгрузка каталога (ICML)
+
+* Генерация обновлена в соответствии с последними измениями формата файла выгрузки
+* Генерация вынесена в отдельный класс
+* Добавлена возможность добавлять подкатегории
+* Скорректировано указание активности офера
+* Убрана генерация размера офера вследствие кастомизации этого параметра в разных магазинах
+
+####v0.1.1
+* Устранена ошибка редактирования, при которой терялась часть данных при получении истории из CRM
+* Оптимизирован код получения и обработки истории заказов
+* Актуализированы переводы
+
+####v.0.1
+* Реализован интерфейс настроек модуля
+* Реализована отправка данных о заказе/клиенте в CRM
+* Реализована выгрузка каталога (cron only)
+* Реализовано получение данных о заказах, сделанных на стороне CRM (cron only)
+
diff --git a/README.md b/README.md
index 58fbe97..a459d80 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,91 @@
Opencart module
==============
-Opencart module for interaction with [IntaroCRM](http://www.intarocrm.com) through [REST API](http://docs.intarocrm.ru/rest-api/).
+Opencart module for interaction with [RetailCRM](http://retailcrm.ru) through [REST API](http://www.retailcrm.ru/docs/).
-Module allows:
+###Features
-* Send to IntaroCRM new orders
+* Send orders to RetailCRM
+* Get changes from RetailCRM
* Configure relations between dictionaries of IntaroCRM and Opencart (statuses, payments, delivery types and etc)
-* Generate [ICML](http://docs.intarocrm.ru/index.php?n=Пользователи.ФорматICML) (IntaroCRM Markup Language) for catalog loading by IntaroCRM
+* Generate catalog export file in [ICML](http://retailcrm.ru/docs/Разработчики/ФорматICML) format
-#### Documentation
+###Install
+
+#### Download module
+
+```
+https://github.com/retailcrm/opencart-module/archive/master.zip
+```
+
+
+#### Install module
+```
+unzip master.zip
+cp -r opencart-module/* /path/to/opecart/instance
+```
+
+#### Activate via Admin interface.
+
+Go to Modules -> Intstall module. Before running exchange you must configure module.
+
+#### Export
+
+Setup cron job for periodically catalog export
+
+```
+* */12 * * * /usr/bin/php /path/to/opencart/cli/cli_export.php >> /path/to/opencart/system/logs/cronjob_export.log 2>&1
+```
+
+Into your CRM settings set path to exported file
+
+```
+/download/retailcrm.xml
+```
+
+#### Export new order from shop to CRM
+
+Add this lines:
+
+```
+$this->load->model('retailcrm/order');
+$this->model_retailcrm_order->send($data, $order_id);
+```
+
+into:
+
+```
+/catalog/model/checkout/order.php
+```
+
+script, into addOrder method before return statement
+
+Add this lines:
+
+```
+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->send($data, $order_id);
+}
+```
+
+into:
+
+```
+/admin/model/sale/order.php
+```
+
+script, into addOrder & editOrder methods at the end of these methods
+
+#### Export new order from CRM to shop
+
+Setup cron job for exchange between CRM & your shop
+
+```
+*/5 * * * * /usr/bin/php /path/to/opencart/cli/cli_history.php >> /path/to/opencart/system/logs/cronjob_history.log 2>&1
+```
-* [Install](doc/Install.md)
-* [Changelog](doc/Changelog.md)
-* [TODO](doc/TODO.md)
diff --git a/admin/controller/module/intarocrm.php b/admin/controller/module/retailcrm.php
similarity index 81%
rename from admin/controller/module/intarocrm.php
rename to admin/controller/module/retailcrm.php
index 5ffa43e..bc492bd 100644
--- a/admin/controller/module/intarocrm.php
+++ b/admin/controller/module/retailcrm.php
@@ -1,37 +1,38 @@
load->model('setting/setting');
- $this->model_setting_setting->editSetting('intarocrm', array('intarocrm_status'=>1));
+ $this->model_setting_setting->editSetting(
+ 'retailcrm',
+ array('retailcrm_status' => 1)
+ );
}
public function uninstall() {
$this->load->model('setting/setting');
- $this->model_setting_setting->editSetting('intarocrm', array('intarocrm_status'=>0));
+ $this->model_setting_setting->editSetting(
+ 'retailcrm',
+ array('retailcrm_status' => 0)
+ );
}
public function index() {
- $this->log = new Monolog\Logger('opencart-module');
- $this->log->pushHandler(
- new Monolog\Handler\StreamHandler(DIR_LOGS . 'intarocrm_module.log', Monolog\Logger::INFO)
- );
-
$this->load->model('setting/setting');
$this->load->model('setting/extension');
- $this->load->model('intarocrm/tools');
- $this->load->language('module/intarocrm');
+ $this->load->model('retailcrm/references');
+ $this->load->language('module/retailcrm');
$this->document->setTitle($this->language->get('heading_title'));
- $this->document->addStyle('/admin/view/stylesheet/intarocrm.css');
+ $this->document->addStyle('/admin/view/stylesheet/retailcrm.css');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
- $this->model_setting_setting->editSetting('intarocrm', $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('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
}
@@ -43,29 +44,31 @@ class ControllerModuleIntarocrm extends Controller {
'button_save',
'button_cancel',
'text_notice',
- 'intarocrm_url',
- 'intarocrm_apikey',
- 'intarocrm_base_settings',
- 'intarocrm_dict_settings',
- 'intarocrm_dict_delivery',
- 'intarocrm_dict_status',
- 'intarocrm_dict_payment',
+ 'retailcrm_url',
+ 'retailcrm_apikey',
+ 'retailcrm_base_settings',
+ 'retailcrm_dict_settings',
+ 'retailcrm_dict_delivery',
+ 'retailcrm_dict_status',
+ 'retailcrm_dict_payment',
);
foreach ($text_strings as $text) {
$this->data[$text] = $this->language->get($text);
}
- $this->data['intarocrm_errors'] = array();
- $this->data['saved_settings'] = $this->model_setting_setting->getSetting('intarocrm');
+ $this->data['retailcrm_errors'] = array();
+ $this->data['saved_settings'] = $this->model_setting_setting->getSetting('retailcrm');
- if ($this->data['saved_settings']['intarocrm_url'] != '' &&
- $this->data['saved_settings']['intarocrm_apikey'] != ''
+ if (
+ !empty($this->data['saved_settings']['retailcrm_url'])
+ &&
+ !empty($this->data['saved_settings']['retailcrm_apikey'])
) {
- $this->intarocrm = new \IntaroCrm\RestApi(
- $this->data['saved_settings']['intarocrm_url'],
- $this->data['saved_settings']['intarocrm_apikey']
+ $this->retailcrm = new ApiHelper(
+ $this->data['saved_settings']['retailcrm_url'],
+ $this->data['saved_settings']['retailcrm_apikey']
);
/*
@@ -73,20 +76,20 @@ class ControllerModuleIntarocrm extends Controller {
*/
try {
- $this->deliveryTypes = $this->intarocrm->deliveryTypesList();
+ $this->deliveryTypes = $this->retailcrm->deliveryTypesList();
}
- catch (IntaroCrm\Exception\ApiException $e)
+ catch (CurlException $e)
{
- $this->data['intarocrm_error'][] = $e->getMessage();
+ $this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError(
'[' .
$this->config->get('store_name') .
'] RestApi::deliveryTypesList::Api:' . $e->getMessage()
);
}
- catch (IntaroCrm\Exception\CurlException $e)
+ catch (InvalidJsonException $e)
{
- $this->data['intarocrm_error'][] = $e->getMessage();
+ $this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError(
'[' . $this->config->get('store_name') .
'] RestApi::deliveryTypesList::Curl:' . $e->getMessage()
@@ -94,28 +97,28 @@ class ControllerModuleIntarocrm extends Controller {
}
$this->data['delivery'] = array(
- 'opencart' => $this->model_intarocrm_tools->getOpercartDeliveryMethods(),
- 'intarocrm' => $this->deliveryTypes
+ 'opencart' => $this->model_retailcrm_tools->getOpercartDeliveryMethods(),
+ 'retailcrm' => $this->deliveryTypes
);
/*
* Statuses
*/
try {
- $this->statuses = $this->intarocrm->orderStatusesList();
+ $this->statuses = $this->retailcrm->orderStatusesList();
}
- catch (IntaroCrm\Exception\ApiException $e)
+ catch (CurlException $e)
{
- $this->data['intarocrm_error'][] = $e->getMessage();
+ $this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError(
'[' .
$this->config->get('store_name') .
'] RestApi::orderStatusesList::Api:' . $e->getMessage()
);
}
- catch (IntaroCrm\Exception\CurlException $e)
+ catch (InvalidJsonException $e)
{
- $this->data['intarocrm_error'][] = $e->getMessage();
+ $this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError(
'[' .
$this->config->get('store_name') .
@@ -124,8 +127,8 @@ class ControllerModuleIntarocrm extends Controller {
}
$this->data['statuses'] = array(
- 'opencart' => $this->model_intarocrm_tools->getOpercartOrderStatuses(),
- 'intarocrm' => $this->statuses
+ 'opencart' => $this->model_retailcrm_tools->getOpercartOrderStatuses(),
+ 'retailcrm' => $this->statuses
);
/*
@@ -133,20 +136,20 @@ class ControllerModuleIntarocrm extends Controller {
*/
try {
- $this->payments = $this->intarocrm->paymentTypesList();
+ $this->payments = $this->retailcrm->paymentTypesList();
}
- catch (IntaroCrm\Exception\ApiException $e)
+ catch (CurlException $e)
{
- $this->data['intarocrm_error'][] = $e->getMessage();
+ $this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError(
'[' .
$this->config->get('store_name') .
'] RestApi::paymentTypesList::Api:' . $e->getMessage()
);
}
- catch (IntaroCrm\Exception\CurlException $e)
+ catch (InvalidJsonException $e)
{
- $this->data['intarocrm_error'][] = $e->getMessage();
+ $this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError(
'[' .
$this->config->get('store_name') .
@@ -155,14 +158,14 @@ class ControllerModuleIntarocrm extends Controller {
}
$this->data['payments'] = array(
- 'opencart' => $this->model_intarocrm_tools->getOpercartPaymentTypes(),
- 'intarocrm' => $this->payments
+ 'opencart' => $this->model_retailcrm_tools->getOpercartPaymentTypes(),
+ 'retailcrm' => $this->payments
);
}
$config_data = array(
- 'intarocrm_status'
+ 'retailcrm_status'
);
foreach ($config_data as $conf) {
@@ -195,28 +198,28 @@ class ControllerModuleIntarocrm extends Controller {
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
- 'href' => $this->url->link('module/intarocrm', 'token=' . $this->session->data['token'], 'SSL'),
+ 'href' => $this->url->link('module/retailcrm', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
- $this->data['action'] = $this->url->link('module/intarocrm', 'token=' . $this->session->data['token'], 'SSL');
+ $this->data['action'] = $this->url->link('module/retailcrm', 'token=' . $this->session->data['token'], 'SSL');
$this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
$this->data['modules'] = array();
- if (isset($this->request->post['intarocrm_module'])) {
- $this->data['modules'] = $this->request->post['intarocrm_module'];
- } elseif ($this->config->get('intarocrm_module')) {
- $this->data['modules'] = $this->config->get('intarocrm_module');
+ if (isset($this->request->post['retailcrm_module'])) {
+ $this->data['modules'] = $this->request->post['retailcrm_module'];
+ } elseif ($this->config->get('retailcrm_module')) {
+ $this->data['modules'] = $this->config->get('retailcrm_module');
}
$this->load->model('design/layout');
$this->data['layouts'] = $this->model_design_layout->getLayouts();
- $this->template = 'module/intarocrm.tpl';
+ $this->template = 'module/retailcrm.tpl';
$this->children = array(
'common/header',
'common/footer',
@@ -225,46 +228,41 @@ class ControllerModuleIntarocrm extends Controller {
$this->response->setOutput($this->render());
}
- public function order_history()
+ public function history()
{
- $this->log = new Monolog\Logger('opencart-module');
- $this->log->pushHandler(
- new Monolog\Handler\StreamHandler(DIR_LOGS . 'intarocrm_module.log', Monolog\Logger::INFO)
- );
-
$this->load->model('setting/setting');
$this->load->model('setting/store');
$this->load->model('sale/order');
$this->load->model('sale/customer');
- $this->load->model('intarocrm/tools');
+ $this->load->model('retailcrm/tools');
$this->load->model('catalog/product');
$this->load->model('localisation/zone');
- $this->load->language('module/intarocrm');
+ $this->load->language('module/retailcrm');
- $settings = $this->model_setting_setting->getSetting('intarocrm');
+ $settings = $this->model_setting_setting->getSetting('retailcrm');
$settings['domain'] = parse_url(HTTP_SERVER, PHP_URL_HOST);
- if (isset($settings['intarocrm_url']) &&
- $settings['intarocrm_url'] != '' &&
- isset($settings['intarocrm_apikey']) &&
- $settings['intarocrm_apikey'] != ''
+ if (isset($settings['retailcrm_url']) &&
+ $settings['retailcrm_url'] != '' &&
+ isset($settings['retailcrm_apikey']) &&
+ $settings['retailcrm_apikey'] != ''
) {
- include_once __DIR__ . '/../../../system/library/intarocrm/apihelper.php';
+ DIR_SYSTEM . 'library/retailcrm/Retailcrm.php';
$crm = new ApiHelper($settings);
- $orders = $crm->orderHistory();
+ $orders = $crm->ordersHistory();
$ordersIdsFix = array();
$customersIdsFix = array();
$subtotalSettings = $this->model_setting_setting->getSetting('sub_total');
$totalSettings = $this->model_setting_setting->getSetting('total');
$shippingSettings = $this->model_setting_setting->getSetting('shipping');
- $delivery = array_flip($settings['intarocrm_delivery']);
- $payment = array_flip($settings['intarocrm_payment']);
- $status = array_flip($settings['intarocrm_status']);
+ $delivery = array_flip($settings['retailcrm_delivery']);
+ $payment = array_flip($settings['retailcrm_payment']);
+ $status = array_flip($settings['retailcrm_status']);
- $ocPayment = $this->model_intarocrm_tools->getOpercartPaymentTypes();
- $ocDelivery = $this->model_intarocrm_tools->getOpercartDeliveryMethods();
+ $ocPayment = $this->model_retailcrm_tools->getOpercartPaymentTypes();
+ $ocDelivery = $this->model_retailcrm_tools->getOpercartDeliveryMethods();
$zones = $this->model_localisation_zone->getZones();
@@ -532,19 +530,19 @@ class ControllerModuleIntarocrm extends Controller {
$this->log->addNotice(
'['.
$this->config->get('store_name').
- '] RestApi::orderHistory: you need to configure Intarocrm module first.'
+ '] RestApi::orderHistory: you need to configure retailcrm module first.'
);
}
}
- public function export_icml()
+ public function icml()
{
- $this->load->model('intarocrm/tools');
- $this->model_intarocrm_tools->generateICML();
+ $this->load->model('retailcrm/icml');
+ $this->model_retailcrm_icml->generateICML();
}
private function validate() {
- if (!$this->user->hasPermission('modify', 'module/intarocrm')) {
+ if (!$this->user->hasPermission('modify', 'module/retailcrm')) {
$this->error['warning'] = $this->language->get('error_permission');
}
diff --git a/admin/language/english/module/intarocrm.php b/admin/language/english/module/intarocrm.php
deleted file mode 100644
index b95fcbc..0000000
--- a/admin/language/english/module/intarocrm.php
+++ /dev/null
@@ -1,25 +0,0 @@
-
diff --git a/admin/language/english/module/retailcrm.php b/admin/language/english/module/retailcrm.php
new file mode 100644
index 0000000..a18304d
--- /dev/null
+++ b/admin/language/english/module/retailcrm.php
@@ -0,0 +1,30 @@
+
diff --git a/admin/language/russian/module/intarocrm.php b/admin/language/russian/module/retailcrm.php
similarity index 52%
rename from admin/language/russian/module/intarocrm.php
rename to admin/language/russian/module/retailcrm.php
index dfb4c7a..533334c 100644
--- a/admin/language/russian/module/intarocrm.php
+++ b/admin/language/russian/module/retailcrm.php
@@ -1,25 +1,30 @@
diff --git a/admin/model/intarocrm/order.php b/admin/model/intarocrm/order.php
deleted file mode 100644
index 8779f66..0000000
--- a/admin/model/intarocrm/order.php
+++ /dev/null
@@ -1,19 +0,0 @@
-load->model('setting/setting');
- $settings = $this->model_setting_setting->getSetting('intarocrm');
- $settings['domain'] = parse_url(HTTP_SERVER, PHP_URL_HOST);
-
- if(isset($settings['intarocrm_url']) && $settings['intarocrm_url'] != '' && isset($settings['intarocrm_apikey']) && $settings['intarocrm_apikey'] != '') {
- include_once DIR_SYSTEM . 'library/intarocrm/apihelper.php';
- $order['order_id'] = $order_id;
- $crm = new ApiHelper($settings);
- $crm->processOrder($order);
- }
-
- }
-}
-?>
\ No newline at end of file
diff --git a/admin/model/intarocrm/tools.php b/admin/model/intarocrm/tools.php
deleted file mode 100644
index b3d812a..0000000
--- a/admin/model/intarocrm/tools.php
+++ /dev/null
@@ -1,197 +0,0 @@
-load->language('shipping/' . $extension);
-
- if ($this->config->get($extension . '_status')) {
- $deliveryMethods[$extension.'.'.$extension] = strip_tags($this->language->get('heading_title'));
- }
- }
- }
-
- return $deliveryMethods;
- }
-
- public function getOpercartOrderStatuses()
- {
- $this->load->model('localisation/order_status');
- return $this->model_localisation_order_status->getOrderStatuses(array());
- }
-
- public function getOpercartPaymentTypes()
- {
- $paymentTypes = array();
- $files = glob(DIR_APPLICATION . 'controller/payment/*.php');
-
- if ($files) {
- foreach ($files as $file) {
- $extension = basename($file, '.php');
-
- $this->load->language('payment/' . $extension);
-
- if ($this->config->get($extension . '_status')) {
- $paymentTypes[$extension] = strip_tags($this->language->get('heading_title'));
- }
- }
- }
-
- return $paymentTypes;
- }
-
- public function generateICML()
- {
- $string = '
-