mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-22 21:26:08 +03:00
update structure, improve icml
This commit is contained in:
parent
72919a236b
commit
ebd8214e05
32
Changelog.md
Normal file
32
Changelog.md
Normal file
@ -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)
|
||||||
|
|
91
README.md
91
README.md
@ -1,16 +1,91 @@
|
|||||||
Opencart module
|
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)
|
* 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)
|
|
||||||
|
@ -1,37 +1,38 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../system/library/intarocrm/vendor/autoload.php';
|
require_once DIR_SYSTEM . 'library/retailcrm/Retailcrm.php';
|
||||||
|
|
||||||
class ControllerModuleIntarocrm extends Controller {
|
class ControllerModuleRetailcrm extends Controller {
|
||||||
private $error = array();
|
private $error = array();
|
||||||
protected $log, $statuses, $payments, $deliveryTypes;
|
protected $log, $statuses, $payments, $deliveryTypes;
|
||||||
|
|
||||||
public function install() {
|
public function install() {
|
||||||
$this->load->model('setting/setting');
|
$this->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() {
|
public function uninstall() {
|
||||||
$this->load->model('setting/setting');
|
$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() {
|
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/setting');
|
||||||
$this->load->model('setting/extension');
|
$this->load->model('setting/extension');
|
||||||
$this->load->model('intarocrm/tools');
|
$this->load->model('retailcrm/references');
|
||||||
$this->load->language('module/intarocrm');
|
$this->load->language('module/retailcrm');
|
||||||
$this->document->setTitle($this->language->get('heading_title'));
|
$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()) {
|
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->session->data['success'] = $this->language->get('text_success');
|
||||||
$this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
|
$this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
|
||||||
}
|
}
|
||||||
@ -43,29 +44,31 @@ class ControllerModuleIntarocrm extends Controller {
|
|||||||
'button_save',
|
'button_save',
|
||||||
'button_cancel',
|
'button_cancel',
|
||||||
'text_notice',
|
'text_notice',
|
||||||
'intarocrm_url',
|
'retailcrm_url',
|
||||||
'intarocrm_apikey',
|
'retailcrm_apikey',
|
||||||
'intarocrm_base_settings',
|
'retailcrm_base_settings',
|
||||||
'intarocrm_dict_settings',
|
'retailcrm_dict_settings',
|
||||||
'intarocrm_dict_delivery',
|
'retailcrm_dict_delivery',
|
||||||
'intarocrm_dict_status',
|
'retailcrm_dict_status',
|
||||||
'intarocrm_dict_payment',
|
'retailcrm_dict_payment',
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($text_strings as $text) {
|
foreach ($text_strings as $text) {
|
||||||
$this->data[$text] = $this->language->get($text);
|
$this->data[$text] = $this->language->get($text);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->data['intarocrm_errors'] = array();
|
$this->data['retailcrm_errors'] = array();
|
||||||
$this->data['saved_settings'] = $this->model_setting_setting->getSetting('intarocrm');
|
$this->data['saved_settings'] = $this->model_setting_setting->getSetting('retailcrm');
|
||||||
|
|
||||||
if ($this->data['saved_settings']['intarocrm_url'] != '' &&
|
if (
|
||||||
$this->data['saved_settings']['intarocrm_apikey'] != ''
|
!empty($this->data['saved_settings']['retailcrm_url'])
|
||||||
|
&&
|
||||||
|
!empty($this->data['saved_settings']['retailcrm_apikey'])
|
||||||
) {
|
) {
|
||||||
|
|
||||||
$this->intarocrm = new \IntaroCrm\RestApi(
|
$this->retailcrm = new ApiHelper(
|
||||||
$this->data['saved_settings']['intarocrm_url'],
|
$this->data['saved_settings']['retailcrm_url'],
|
||||||
$this->data['saved_settings']['intarocrm_apikey']
|
$this->data['saved_settings']['retailcrm_apikey']
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -73,20 +76,20 @@ class ControllerModuleIntarocrm extends Controller {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
try {
|
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->log->addError(
|
||||||
'[' .
|
'[' .
|
||||||
$this->config->get('store_name') .
|
$this->config->get('store_name') .
|
||||||
'] RestApi::deliveryTypesList::Api:' . $e->getMessage()
|
'] 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->log->addError(
|
||||||
'[' . $this->config->get('store_name') .
|
'[' . $this->config->get('store_name') .
|
||||||
'] RestApi::deliveryTypesList::Curl:' . $e->getMessage()
|
'] RestApi::deliveryTypesList::Curl:' . $e->getMessage()
|
||||||
@ -94,28 +97,28 @@ class ControllerModuleIntarocrm extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->data['delivery'] = array(
|
$this->data['delivery'] = array(
|
||||||
'opencart' => $this->model_intarocrm_tools->getOpercartDeliveryMethods(),
|
'opencart' => $this->model_retailcrm_tools->getOpercartDeliveryMethods(),
|
||||||
'intarocrm' => $this->deliveryTypes
|
'retailcrm' => $this->deliveryTypes
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Statuses
|
* Statuses
|
||||||
*/
|
*/
|
||||||
try {
|
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->log->addError(
|
||||||
'[' .
|
'[' .
|
||||||
$this->config->get('store_name') .
|
$this->config->get('store_name') .
|
||||||
'] RestApi::orderStatusesList::Api:' . $e->getMessage()
|
'] 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->log->addError(
|
||||||
'[' .
|
'[' .
|
||||||
$this->config->get('store_name') .
|
$this->config->get('store_name') .
|
||||||
@ -124,8 +127,8 @@ class ControllerModuleIntarocrm extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->data['statuses'] = array(
|
$this->data['statuses'] = array(
|
||||||
'opencart' => $this->model_intarocrm_tools->getOpercartOrderStatuses(),
|
'opencart' => $this->model_retailcrm_tools->getOpercartOrderStatuses(),
|
||||||
'intarocrm' => $this->statuses
|
'retailcrm' => $this->statuses
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -133,20 +136,20 @@ class ControllerModuleIntarocrm extends Controller {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
try {
|
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->log->addError(
|
||||||
'[' .
|
'[' .
|
||||||
$this->config->get('store_name') .
|
$this->config->get('store_name') .
|
||||||
'] RestApi::paymentTypesList::Api:' . $e->getMessage()
|
'] 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->log->addError(
|
||||||
'[' .
|
'[' .
|
||||||
$this->config->get('store_name') .
|
$this->config->get('store_name') .
|
||||||
@ -155,14 +158,14 @@ class ControllerModuleIntarocrm extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->data['payments'] = array(
|
$this->data['payments'] = array(
|
||||||
'opencart' => $this->model_intarocrm_tools->getOpercartPaymentTypes(),
|
'opencart' => $this->model_retailcrm_tools->getOpercartPaymentTypes(),
|
||||||
'intarocrm' => $this->payments
|
'retailcrm' => $this->payments
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$config_data = array(
|
$config_data = array(
|
||||||
'intarocrm_status'
|
'retailcrm_status'
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($config_data as $conf) {
|
foreach ($config_data as $conf) {
|
||||||
@ -195,28 +198,28 @@ class ControllerModuleIntarocrm extends Controller {
|
|||||||
|
|
||||||
$this->data['breadcrumbs'][] = array(
|
$this->data['breadcrumbs'][] = array(
|
||||||
'text' => $this->language->get('heading_title'),
|
'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' => ' :: '
|
'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['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
|
||||||
|
|
||||||
|
|
||||||
$this->data['modules'] = array();
|
$this->data['modules'] = array();
|
||||||
|
|
||||||
if (isset($this->request->post['intarocrm_module'])) {
|
if (isset($this->request->post['retailcrm_module'])) {
|
||||||
$this->data['modules'] = $this->request->post['intarocrm_module'];
|
$this->data['modules'] = $this->request->post['retailcrm_module'];
|
||||||
} elseif ($this->config->get('intarocrm_module')) {
|
} elseif ($this->config->get('retailcrm_module')) {
|
||||||
$this->data['modules'] = $this->config->get('intarocrm_module');
|
$this->data['modules'] = $this->config->get('retailcrm_module');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->load->model('design/layout');
|
$this->load->model('design/layout');
|
||||||
|
|
||||||
$this->data['layouts'] = $this->model_design_layout->getLayouts();
|
$this->data['layouts'] = $this->model_design_layout->getLayouts();
|
||||||
|
|
||||||
$this->template = 'module/intarocrm.tpl';
|
$this->template = 'module/retailcrm.tpl';
|
||||||
$this->children = array(
|
$this->children = array(
|
||||||
'common/header',
|
'common/header',
|
||||||
'common/footer',
|
'common/footer',
|
||||||
@ -225,46 +228,41 @@ class ControllerModuleIntarocrm extends Controller {
|
|||||||
$this->response->setOutput($this->render());
|
$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/setting');
|
||||||
$this->load->model('setting/store');
|
$this->load->model('setting/store');
|
||||||
$this->load->model('sale/order');
|
$this->load->model('sale/order');
|
||||||
$this->load->model('sale/customer');
|
$this->load->model('sale/customer');
|
||||||
$this->load->model('intarocrm/tools');
|
$this->load->model('retailcrm/tools');
|
||||||
$this->load->model('catalog/product');
|
$this->load->model('catalog/product');
|
||||||
$this->load->model('localisation/zone');
|
$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);
|
$settings['domain'] = parse_url(HTTP_SERVER, PHP_URL_HOST);
|
||||||
|
|
||||||
if (isset($settings['intarocrm_url']) &&
|
if (isset($settings['retailcrm_url']) &&
|
||||||
$settings['intarocrm_url'] != '' &&
|
$settings['retailcrm_url'] != '' &&
|
||||||
isset($settings['intarocrm_apikey']) &&
|
isset($settings['retailcrm_apikey']) &&
|
||||||
$settings['intarocrm_apikey'] != ''
|
$settings['retailcrm_apikey'] != ''
|
||||||
) {
|
) {
|
||||||
include_once __DIR__ . '/../../../system/library/intarocrm/apihelper.php';
|
DIR_SYSTEM . 'library/retailcrm/Retailcrm.php';
|
||||||
$crm = new ApiHelper($settings);
|
$crm = new ApiHelper($settings);
|
||||||
$orders = $crm->orderHistory();
|
$orders = $crm->ordersHistory();
|
||||||
$ordersIdsFix = array();
|
$ordersIdsFix = array();
|
||||||
$customersIdsFix = array();
|
$customersIdsFix = array();
|
||||||
$subtotalSettings = $this->model_setting_setting->getSetting('sub_total');
|
$subtotalSettings = $this->model_setting_setting->getSetting('sub_total');
|
||||||
$totalSettings = $this->model_setting_setting->getSetting('total');
|
$totalSettings = $this->model_setting_setting->getSetting('total');
|
||||||
$shippingSettings = $this->model_setting_setting->getSetting('shipping');
|
$shippingSettings = $this->model_setting_setting->getSetting('shipping');
|
||||||
|
|
||||||
$delivery = array_flip($settings['intarocrm_delivery']);
|
$delivery = array_flip($settings['retailcrm_delivery']);
|
||||||
$payment = array_flip($settings['intarocrm_payment']);
|
$payment = array_flip($settings['retailcrm_payment']);
|
||||||
$status = array_flip($settings['intarocrm_status']);
|
$status = array_flip($settings['retailcrm_status']);
|
||||||
|
|
||||||
$ocPayment = $this->model_intarocrm_tools->getOpercartPaymentTypes();
|
$ocPayment = $this->model_retailcrm_tools->getOpercartPaymentTypes();
|
||||||
$ocDelivery = $this->model_intarocrm_tools->getOpercartDeliveryMethods();
|
$ocDelivery = $this->model_retailcrm_tools->getOpercartDeliveryMethods();
|
||||||
|
|
||||||
$zones = $this->model_localisation_zone->getZones();
|
$zones = $this->model_localisation_zone->getZones();
|
||||||
|
|
||||||
@ -532,19 +530,19 @@ class ControllerModuleIntarocrm extends Controller {
|
|||||||
$this->log->addNotice(
|
$this->log->addNotice(
|
||||||
'['.
|
'['.
|
||||||
$this->config->get('store_name').
|
$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->load->model('retailcrm/icml');
|
||||||
$this->model_intarocrm_tools->generateICML();
|
$this->model_retailcrm_icml->generateICML();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function validate() {
|
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');
|
$this->error['warning'] = $this->language->get('error_permission');
|
||||||
}
|
}
|
||||||
|
|
@ -1,25 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// Heading Goes here:
|
|
||||||
$_['heading_title'] = 'IntaroCRM';
|
|
||||||
|
|
||||||
// Text
|
|
||||||
$_['text_module'] = 'Modules';
|
|
||||||
$_['text_success'] = 'Setting saved';
|
|
||||||
$_['text_notice'] = 'Warning! Timezone in CRM & your shop must be equal, you must setup it here:';
|
|
||||||
$_['intarocrm_base_settings'] = 'Connection settings';
|
|
||||||
$_['intarocrm_dict_settings'] = 'Dictionary settings';
|
|
||||||
|
|
||||||
$_['intarocrm_url'] = 'IntaroCRM URL';
|
|
||||||
$_['intarocrm_apikey'] = 'Api key';
|
|
||||||
|
|
||||||
$_['intarocrm_dict_delivery'] = 'Shipment methods';
|
|
||||||
$_['intarocrm_dict_status'] = 'Order statuses';
|
|
||||||
$_['intarocrm_dict_payment'] = 'Payment methods';
|
|
||||||
|
|
||||||
$_['column_total'] = 'Total';
|
|
||||||
$_['product_summ'] = 'Amount';
|
|
||||||
|
|
||||||
// Errors
|
|
||||||
$_['error_permission'] = 'Warning! You do not have permission to modify module';
|
|
||||||
?>
|
|
30
admin/language/english/module/retailcrm.php
Normal file
30
admin/language/english/module/retailcrm.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// Heading Goes here:
|
||||||
|
$_['heading_title'] = 'RetailCRM';
|
||||||
|
|
||||||
|
// Text
|
||||||
|
$_['text_module'] = 'Modules';
|
||||||
|
$_['text_success'] = 'Setting saved';
|
||||||
|
$_['text_notice'] = 'Warning! Timezone in CRM & your shop must be equal, you must setup it here:';
|
||||||
|
$_['retailcrm_base_settings'] = 'Connection settings';
|
||||||
|
$_['retailcrm_dict_settings'] = 'Dictionary settings';
|
||||||
|
|
||||||
|
$_['retailcrm_url'] = 'RetailCRM URL';
|
||||||
|
$_['retailcrm_apikey'] = 'RetailCRM API Key';
|
||||||
|
|
||||||
|
$_['retailcrm_dict_delivery'] = 'Shipment methods';
|
||||||
|
$_['retailcrm_dict_status'] = 'Order statuses';
|
||||||
|
$_['retailcrm_dict_payment'] = 'Payment methods';
|
||||||
|
|
||||||
|
$_['column_total'] = 'Total';
|
||||||
|
$_['product_summ'] = 'Amount';
|
||||||
|
|
||||||
|
$_['article'] = 'SKU';
|
||||||
|
$_['color'] = 'Color';
|
||||||
|
$_['weight'] = 'Weight';
|
||||||
|
$_['size'] = 'Size';
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
$_['error_permission'] = 'Warning! You do not have permission to modify module';
|
||||||
|
?>
|
@ -1,25 +1,30 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Heading Goes here:
|
// Heading Goes here:
|
||||||
$_['heading_title'] = 'IntaroCRM';
|
$_['heading_title'] = 'RetailCRM';
|
||||||
|
|
||||||
// Text
|
// Text
|
||||||
$_['text_module'] = 'Модули';
|
$_['text_module'] = 'Модули';
|
||||||
$_['text_success'] = 'Настройки успешно сохранены';
|
$_['text_success'] = 'Настройки успешно сохранены';
|
||||||
$_['text_notice'] = 'Внимание! Часовой пояс в CRM должен совпадать с часовым поясом в магазине, настроки часового пояса CRM можно задать по адресу:';
|
$_['text_notice'] = 'Внимание! Часовой пояс в CRM должен совпадать с часовым поясом в магазине, настроки часового пояса CRM можно задать по адресу:';
|
||||||
$_['intarocrm_base_settings'] = 'Настройки соединения';
|
$_['retailcrm_base_settings'] = 'Настройки соединения';
|
||||||
$_['intarocrm_dict_settings'] = 'Настройки соответствия справочников';
|
$_['retailcrm_dict_settings'] = 'Настройки соответствия справочников';
|
||||||
|
|
||||||
$_['intarocrm_url'] = 'Адрес IntaroCRM';
|
$_['retailcrm_url'] = 'Адрес RetailCRM';
|
||||||
$_['intarocrm_apikey'] = 'Api ключ';
|
$_['retailcrm_apikey'] = 'Api ключ RetailCRM';
|
||||||
|
|
||||||
$_['intarocrm_dict_delivery'] = 'Способы доставки';
|
$_['retailcrm_dict_delivery'] = 'Способы доставки';
|
||||||
$_['intarocrm_dict_status'] = 'Статусы';
|
$_['retailcrm_dict_status'] = 'Статусы';
|
||||||
$_['intarocrm_dict_payment'] = 'Способы оплаты';
|
$_['retailcrm_dict_payment'] = 'Способы оплаты';
|
||||||
|
|
||||||
$_['column_total'] = 'Итого';
|
$_['column_total'] = 'Итого';
|
||||||
$_['product_summ'] = 'Сумма';
|
$_['product_summ'] = 'Сумма';
|
||||||
|
|
||||||
|
$_['article'] = 'Артикул';
|
||||||
|
$_['color'] = 'Цвет';
|
||||||
|
$_['weight'] = 'Вес';
|
||||||
|
$_['size'] = 'Размер';
|
||||||
|
|
||||||
// Errors
|
// Errors
|
||||||
$_['error_permission'] = 'У вас недостаточно прав на изменение настроек модуля';
|
$_['error_permission'] = 'У вас недостаточно прав на изменение настроек модуля';
|
||||||
?>
|
?>
|
@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
class ModelIntarocrmOrder extends Model {
|
|
||||||
|
|
||||||
public function send($order, $order_id)
|
|
||||||
{
|
|
||||||
$this->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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,197 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class ModelIntarocrmTools extends Model {
|
|
||||||
|
|
||||||
protected $dd, $eCategories, $eOffers;
|
|
||||||
|
|
||||||
public function getOpercartDeliveryMethods()
|
|
||||||
{
|
|
||||||
$deliveryMethods = array();
|
|
||||||
$files = glob(DIR_APPLICATION . 'controller/shipping/*.php');
|
|
||||||
|
|
||||||
if ($files) {
|
|
||||||
foreach ($files as $file) {
|
|
||||||
$extension = basename($file, '.php');
|
|
||||||
|
|
||||||
$this->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 = '<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<yml_catalog date="'.date('Y-m-d H:i:s').'">
|
|
||||||
<shop>
|
|
||||||
<name>'.$this->config->get('config_name').'</name>
|
|
||||||
<categories/>
|
|
||||||
<offers/>
|
|
||||||
</shop>
|
|
||||||
</yml_catalog>
|
|
||||||
';
|
|
||||||
|
|
||||||
$xml = new SimpleXMLElement($string, LIBXML_NOENT |LIBXML_NOCDATA | LIBXML_COMPACT | LIBXML_PARSEHUGE);
|
|
||||||
|
|
||||||
$this->dd = new DOMDocument();
|
|
||||||
$this->dd->preserveWhiteSpace = false;
|
|
||||||
$this->dd->formatOutput = true;
|
|
||||||
$this->dd->loadXML($xml->asXML());
|
|
||||||
|
|
||||||
$this->eCategories = $this->dd->getElementsByTagName('categories')->item(0);
|
|
||||||
$this->eOffers = $this->dd->getElementsByTagName('offers')->item(0);
|
|
||||||
|
|
||||||
$this->addCategories();
|
|
||||||
$this->addOffers();
|
|
||||||
|
|
||||||
$this->dd->saveXML();
|
|
||||||
|
|
||||||
$downloadPath = DIR_SYSTEM . '/../download/';
|
|
||||||
|
|
||||||
if (!file_exists($downloadPath)) {
|
|
||||||
mkdir($downloadPath, 0755);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->dd->save($downloadPath . 'intarocrm.xml');
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addCategories()
|
|
||||||
{
|
|
||||||
$this->load->model('catalog/category');
|
|
||||||
|
|
||||||
foreach ($this->model_catalog_category->getCategories(array()) as $category) {
|
|
||||||
$e = $this->eCategories->appendChild($this->dd->createElement('category', $category['name']));
|
|
||||||
$e->setAttribute('id',$category['category_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addOffers()
|
|
||||||
{
|
|
||||||
$this->load->model('catalog/product');
|
|
||||||
$this->load->model('catalog/manufacturer');
|
|
||||||
$this->load->model('tool/image');
|
|
||||||
|
|
||||||
$offerManufacturers = array();
|
|
||||||
|
|
||||||
$manufacturers = $this->model_catalog_manufacturer->getManufacturers(array());
|
|
||||||
|
|
||||||
foreach ($manufacturers as $manufacturer) {
|
|
||||||
$offerManufacturers[$manufacturer['manufacturer_id']] = $manufacturer['name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->model_catalog_product->getProducts(array()) as $offer) {
|
|
||||||
|
|
||||||
$e = $this->eOffers->appendChild($this->dd->createElement('offer'));
|
|
||||||
$e->setAttribute('id', $offer['product_id']);
|
|
||||||
$e->setAttribute('productId', $offer['product_id']);
|
|
||||||
$e->setAttribute('quantity', $offer['quantity']);
|
|
||||||
$e->setAttribute('available', $offer['status'] ? 'true' : 'false');
|
|
||||||
|
|
||||||
/*
|
|
||||||
* DIRTY HACK, NEED TO REFACTOR
|
|
||||||
*/
|
|
||||||
|
|
||||||
$sql = "SELECT * FROM `" .
|
|
||||||
DB_PREFIX .
|
|
||||||
"product_to_category` WHERE `product_id` = " .$offer['product_id']. ";"
|
|
||||||
;
|
|
||||||
$result = $this->db->query($sql);
|
|
||||||
foreach ($result->rows as $row) {
|
|
||||||
$e->appendChild($this->dd->createElement('categoryId', $row['category_id']));
|
|
||||||
}
|
|
||||||
|
|
||||||
$e->appendChild($this->dd->createElement('name'))->appendChild($this->dd->createTextNode($offer['name']));
|
|
||||||
$e->appendChild($this->dd->createElement('productName'))
|
|
||||||
->appendChild($this->dd->createTextNode($offer['name']));
|
|
||||||
$e->appendChild($this->dd->createElement('price', $offer['price']));
|
|
||||||
|
|
||||||
if ($offer['manufacturer_id'] != 0) {
|
|
||||||
$e->appendChild($this->dd->createElement('vendor'))
|
|
||||||
->appendChild($this->dd->createTextNode($offerManufacturers[$offer['manufacturer_id']]));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($offer['image']) {
|
|
||||||
$e->appendChild(
|
|
||||||
$this->dd->createElement(
|
|
||||||
'picture',
|
|
||||||
$this->model_tool_image->resize(
|
|
||||||
$offer['image'],
|
|
||||||
$this->config->get('config_image_product_width'),
|
|
||||||
$this->config->get('config_image_product_height')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->url = new Url(HTTP_CATALOG, $this->config->get('config_secure') ? HTTP_CATALOG : HTTPS_CATALOG);
|
|
||||||
$e->appendChild($this->dd->createElement('url'))->appendChild(
|
|
||||||
$this->dd->createTextNode(
|
|
||||||
$this->url->link('product/product&product_id=' . $offer['product_id'])
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($offer['sku'] != '') {
|
|
||||||
$sku = $this->dd->createElement('param');
|
|
||||||
$sku->setAttribute('name', 'article');
|
|
||||||
$sku->appendChild($this->dd->createTextNode($offer['sku']));
|
|
||||||
$e->appendChild($sku);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($offer['weight'] != '') {
|
|
||||||
$weight = $this->dd->createElement('param');
|
|
||||||
$weight->setAttribute('name', 'weight');
|
|
||||||
$weightValue = (isset($offer['weight_class']))
|
|
||||||
? round($offer['weight'], 3) . ' ' . $offer['weight_class']
|
|
||||||
: round($offer['weight'], 3)
|
|
||||||
;
|
|
||||||
$weight->appendChild($this->dd->createTextNode($weightValue));
|
|
||||||
$e->appendChild($weight);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($offer['length'] != '' && $offer['width'] != '' && $offer['height'] != '') {
|
|
||||||
$size = $this->dd->createElement('param');
|
|
||||||
$size->setAttribute('name', 'size');
|
|
||||||
$size->appendChild(
|
|
||||||
$this->dd->createTextNode(
|
|
||||||
round($offer['length'], 2) .'x'.
|
|
||||||
round($offer['width'], 2) .'x'.
|
|
||||||
round($offer['height'], 2)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$e->appendChild($size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
207
admin/model/retailcrm/icml.php
Normal file
207
admin/model/retailcrm/icml.php
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ModelRetailcrmIcml extends Model {
|
||||||
|
protected $shop;
|
||||||
|
protected $file;
|
||||||
|
protected $properties;
|
||||||
|
protected $params;
|
||||||
|
protected $dd;
|
||||||
|
protected $eCategories;
|
||||||
|
protected $eOffers;
|
||||||
|
|
||||||
|
public function generateICML()
|
||||||
|
{
|
||||||
|
$this->load->language('module/retailcrm');
|
||||||
|
$this->load->model('catalog/category');
|
||||||
|
$this->load->model('catalog/product');
|
||||||
|
$this->load->model('catalog/manufacturer');
|
||||||
|
|
||||||
|
$string = '<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<yml_catalog date="'.date('Y-m-d H:i:s').'">
|
||||||
|
<shop>
|
||||||
|
<name>'.$this->config->get('config_name').'</name>
|
||||||
|
<categories/>
|
||||||
|
<offers/>
|
||||||
|
</shop>
|
||||||
|
</yml_catalog>
|
||||||
|
';
|
||||||
|
|
||||||
|
$xml = new SimpleXMLElement(
|
||||||
|
$string,
|
||||||
|
LIBXML_NOENT |LIBXML_NOCDATA | LIBXML_COMPACT | LIBXML_PARSEHUGE
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->dd = new DOMDocument();
|
||||||
|
$this->dd->preserveWhiteSpace = false;
|
||||||
|
$this->dd->formatOutput = true;
|
||||||
|
$this->dd->loadXML($xml->asXML());
|
||||||
|
|
||||||
|
$this->eCategories = $this->dd
|
||||||
|
->getElementsByTagName('categories')->item(0);
|
||||||
|
$this->eOffers = $this->dd
|
||||||
|
->getElementsByTagName('offers')->item(0);
|
||||||
|
|
||||||
|
$this->addCategories($categories);
|
||||||
|
$this->addOffers($offers);
|
||||||
|
|
||||||
|
$this->dd->saveXML();
|
||||||
|
|
||||||
|
$downloadPath = DIR_SYSTEM . '/../download/';
|
||||||
|
|
||||||
|
if (!file_exists($downloadPath)) {
|
||||||
|
mkdir($downloadPath, 0755);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->dd->save($downloadPath . 'retailcrm.xml');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addCategories()
|
||||||
|
{
|
||||||
|
$categories = $this->model_catalog_category->getCategories(array());
|
||||||
|
foreach($categories as $category) {
|
||||||
|
$e = $this->eCategories->appendChild(
|
||||||
|
$this->dd->createElement(
|
||||||
|
'category', $category['name']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$e->setAttribute('id', $category['id']);
|
||||||
|
|
||||||
|
if ($category['parent_id'] > 0) {
|
||||||
|
$e->setAttribute('parentId', $category['parent_id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addOffers()
|
||||||
|
{
|
||||||
|
$offerManufacturers = array();
|
||||||
|
|
||||||
|
$manufacturers = $this->model_catalog_manufacturer
|
||||||
|
->getManufacturers(array());
|
||||||
|
|
||||||
|
foreach ($manufacturers as $manufacturer) {
|
||||||
|
$offerManufacturers[
|
||||||
|
$manufacturer['manufacturer_id']
|
||||||
|
] = $manufacturer['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$products = $this->model_catalog_product->getProducts(array());
|
||||||
|
|
||||||
|
foreach ($products as $offer) {
|
||||||
|
|
||||||
|
$e = $this->eOffers->appendChild($this->dd->createElement('offer'));
|
||||||
|
$e->setAttribute('id', $offer['product_id']);
|
||||||
|
$e->setAttribute('productId', $offer['product_id']);
|
||||||
|
$e->setAttribute('quantity', $offer['quantity']);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Offer activity
|
||||||
|
*/
|
||||||
|
$offer['status'] ? 'Y' : 'N';
|
||||||
|
$e->appendChild(
|
||||||
|
$this->dd->createElement('productActivity')
|
||||||
|
)->appendChild(
|
||||||
|
$this->dd->createTextNode($offer['status'])
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Offer categories
|
||||||
|
*/
|
||||||
|
$categories = $this->model_catalog_product
|
||||||
|
->getProductCategories($offer['product_id']);
|
||||||
|
|
||||||
|
if (!empty($categories)) {
|
||||||
|
foreach ($categories as $category) {
|
||||||
|
$e->appendChild($this->dd->createElement('category'))
|
||||||
|
->appendChild(
|
||||||
|
$this->dd->createTextNode($category)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name & price
|
||||||
|
*/
|
||||||
|
$e->appendChild($this->dd->createElement('name'))
|
||||||
|
->appendChild($this->dd->createTextNode($offer['name']));
|
||||||
|
$e->appendChild($this->dd->createElement('productName'))
|
||||||
|
->appendChild($this->dd->createTextNode($offer['name']));
|
||||||
|
$e->appendChild($this->dd->createElement('price'))
|
||||||
|
->appendChild($this->dd->createTextNode($offer['price']));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vendor
|
||||||
|
*/
|
||||||
|
if ($offer['manufacturer_id'] != 0) {
|
||||||
|
$e->appendChild($this->dd->createElement('vendor'))
|
||||||
|
->appendChild(
|
||||||
|
$this->dd->createTextNode(
|
||||||
|
$offerManufacturers[$offer['manufacturer_id']]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Image
|
||||||
|
*/
|
||||||
|
if ($offer['image']) {
|
||||||
|
$image = $this->generateImage($offer['image']);
|
||||||
|
$e->appendChild($this->dd->createElement('picture'))
|
||||||
|
->appendChild($this->dd->createTextNode($image));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Url
|
||||||
|
*/
|
||||||
|
$this->url = new Url(
|
||||||
|
HTTP_CATALOG,
|
||||||
|
$this->config->get('config_secure')
|
||||||
|
? HTTP_CATALOG
|
||||||
|
: HTTPS_CATALOG
|
||||||
|
);
|
||||||
|
|
||||||
|
$e->appendChild($this->dd->createElement('url'))
|
||||||
|
->appendChild(
|
||||||
|
$this->dd->createTextNode(
|
||||||
|
$this->url->link(
|
||||||
|
'product/product&product_id=' . $offer['product_id']
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
if ($offer['sku']) {
|
||||||
|
$sku = $this->dd->createElement('param');
|
||||||
|
$sku->setAttribute('code', 'article');
|
||||||
|
$sku->setAttribute('name', $this->language->get('article'));
|
||||||
|
$sku->appendChild($this->dd->createTextNode($offer['sku']));
|
||||||
|
$e->appendChild($sku);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($offer['weight'] != '') {
|
||||||
|
$weight = $this->dd->createElement('param');
|
||||||
|
$weight->setAttribute('color', 'weight');
|
||||||
|
$weight->setAttribute('name', $this->language->get('weight'));
|
||||||
|
$weightValue = (isset($offer['weight_class']))
|
||||||
|
? round($offer['weight'], 3) . ' ' . $offer['weight_class']
|
||||||
|
: round($offer['weight'], 3)
|
||||||
|
;
|
||||||
|
$weight->appendChild($this->dd->createTextNode($weightValue));
|
||||||
|
$e->appendChild($weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function generateImage($image)
|
||||||
|
{
|
||||||
|
$this->load->model('tool/image');
|
||||||
|
|
||||||
|
return $this->model_tool_image->resize(
|
||||||
|
$image,
|
||||||
|
$this->config->get('config_image_product_width'),
|
||||||
|
$this->config->get('config_image_product_height')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
22
admin/model/retailcrm/order.php
Normal file
22
admin/model/retailcrm/order.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
class ModelRetailcrmOrder extends Model {
|
||||||
|
|
||||||
|
public function send($order, $order_id)
|
||||||
|
{
|
||||||
|
$this->load->model('setting/setting');
|
||||||
|
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
||||||
|
$settings['domain'] = parse_url(HTTP_SERVER, PHP_URL_HOST);
|
||||||
|
|
||||||
|
if(
|
||||||
|
!empty($settings['retailcrm_url'])
|
||||||
|
&&
|
||||||
|
!empty($settings['retailcrm_apikey'])
|
||||||
|
) {
|
||||||
|
require_once DIR_SYSTEM . 'library/retailcrm/Retailcrm.php';
|
||||||
|
$order['order_id'] = $order_id;
|
||||||
|
$crm = new ApiHelper($settings);
|
||||||
|
$crm->processOrder($order);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
56
admin/model/retailcrm/references.php
Normal file
56
admin/model/retailcrm/references.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ModelRetailcrmReferences extends Model {
|
||||||
|
|
||||||
|
public function getOpercartDeliveryMethods()
|
||||||
|
{
|
||||||
|
$deliveryMethods = array();
|
||||||
|
$files = glob(DIR_APPLICATION . 'controller/shipping/*.php');
|
||||||
|
|
||||||
|
if ($files) {
|
||||||
|
foreach ($files as $file) {
|
||||||
|
$extension = basename($file, '.php');
|
||||||
|
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,2 +0,0 @@
|
|||||||
.intarocrm_unit {margin-bottom: 10px;}
|
|
||||||
.intarocrm_unit input {width: 30%;}
|
|
2
admin/view/stylesheet/retailcrm.css
Normal file
2
admin/view/stylesheet/retailcrm.css
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
.retailcrm_unit {margin-bottom: 10px;}
|
||||||
|
.retailcrm_unit input {width: 30%;}
|
@ -9,10 +9,10 @@
|
|||||||
<?php if ($error_warning) : ?>
|
<?php if ($error_warning) : ?>
|
||||||
<div class="warning"><?php echo $error_warning; ?></div>
|
<div class="warning"><?php echo $error_warning; ?></div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php if (isset($saved_settings['intarocrm_url'])): ?>
|
<?php if (isset($saved_settings['retailcrm_url'])): ?>
|
||||||
<div class="success">
|
<div class="success">
|
||||||
<?php echo $text_notice; ?>
|
<?php echo $text_notice; ?>
|
||||||
<a href="<?php echo $saved_settings['intarocrm_url']; ?>/admin/settings#t-main"><?php echo $saved_settings['intarocrm_url']; ?>/admin/settings#t-main</a>
|
<a href="<?php echo $saved_settings['retailcrm_url']; ?>/admin/settings#t-main"><?php echo $saved_settings['retailcrm_url']; ?>/admin/settings#t-main</a>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
@ -23,67 +23,67 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
|
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
|
||||||
<input type="hidden" name="intarocrm_status" value="1">
|
<input type="hidden" name="retailcrm_status" value="1">
|
||||||
|
|
||||||
<h3><?php echo $intarocrm_base_settings; ?></h3>
|
<h3><?php echo $retailcrm_base_settings; ?></h3>
|
||||||
<div class="intarocrm_unit">
|
<div class="retailcrm_unit">
|
||||||
<label for="intarocrm_url"><?php echo $intarocrm_url; ?></label><br>
|
<label for="retailcrm_url"><?php echo $retailcrm_url; ?></label><br>
|
||||||
<input id="intarocrm_url" type="text" name="intarocrm_url" value="<?php if (isset($saved_settings['intarocrm_url'])): echo $saved_settings['intarocrm_url']; endif; ?>">
|
<input id="retailcrm_url" type="text" name="retailcrm_url" value="<?php if (isset($saved_settings['retailcrm_url'])): echo $saved_settings['retailcrm_url']; endif; ?>">
|
||||||
</div>
|
</div>
|
||||||
<div class="intarocrm_unit">
|
<div class="retailcrm_unit">
|
||||||
<label for="intarocrm_apikey"><?php echo $intarocrm_apikey; ?></label><br>
|
<label for="retailcrm_apikey"><?php echo $retailcrm_apikey; ?></label><br>
|
||||||
<input id="intarocrm_apikey" type="text" name="intarocrm_apikey" value="<?php if (isset($saved_settings['intarocrm_apikey'])): echo $saved_settings['intarocrm_apikey']; endif;?>">
|
<input id="retailcrm_apikey" type="text" name="retailcrm_apikey" value="<?php if (isset($saved_settings['retailcrm_apikey'])): echo $saved_settings['retailcrm_apikey']; endif;?>">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php if (isset($saved_settings['intarocrm_apikey']) && $saved_settings['intarocrm_apikey'] != '' && isset($saved_settings['intarocrm_url']) && $saved_settings['intarocrm_url'] != ''): ?>
|
<?php if (isset($saved_settings['retailcrm_apikey']) && $saved_settings['retailcrm_apikey'] != '' && isset($saved_settings['retailcrm_url']) && $saved_settings['retailcrm_url'] != ''): ?>
|
||||||
|
|
||||||
<?php if (!empty($intarocrm_errors)) : ?>
|
<?php if (!empty($retailcrm_errors)) : ?>
|
||||||
<?php foreach($intarocrm_errors as $intarocrm_error): ?>
|
<?php foreach($retailcrm_errors as $retailcrm_error): ?>
|
||||||
<div class="warning"><?php echo $intarocrm_error ?></div>
|
<div class="warning"><?php echo $retailcrm_error ?></div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<h3><?php echo $intarocrm_dict_settings; ?></h3>
|
<h3><?php echo $retailcrm_dict_settings; ?></h3>
|
||||||
|
|
||||||
<h4><?php echo $intarocrm_dict_delivery; ?></h4>
|
<h4><?php echo $retailcrm_dict_delivery; ?></h4>
|
||||||
<?php foreach ($delivery['opencart'] as $key => $value): ?>
|
<?php foreach ($delivery['opencart'] as $key => $value): ?>
|
||||||
<div class="intarocrm_unit">
|
<div class="retailcrm_unit">
|
||||||
<select id="intarocrm_delivery_<?php echo $key; ?>" name="intarocrm_delivery[<?php echo $key; ?>]" >
|
<select id="retailcrm_delivery_<?php echo $key; ?>" name="retailcrm_delivery[<?php echo $key; ?>]" >
|
||||||
<?php foreach ($delivery['intarocrm'] as $k => $v): ?>
|
<?php foreach ($delivery['retailcrm'] as $k => $v): ?>
|
||||||
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['intarocrm_delivery'][$key]) && $v['code'] == $saved_settings['intarocrm_delivery'][$key]):?>selected="selected"<?php endif;?>>
|
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_delivery'][$key]) && $v['code'] == $saved_settings['retailcrm_delivery'][$key]):?>selected="selected"<?php endif;?>>
|
||||||
<?php echo $v['name'];?>
|
<?php echo $v['name'];?>
|
||||||
</option>
|
</option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
<label for="intarocrm_delivery_<?php echo $key; ?>"><?php echo $value; ?></label>
|
<label for="retailcrm_delivery_<?php echo $key; ?>"><?php echo $value; ?></label>
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
<h4><?php echo $intarocrm_dict_status; ?></h4>
|
<h4><?php echo $retailcrm_dict_status; ?></h4>
|
||||||
<?php foreach ($statuses['opencart'] as $status): ?>
|
<?php foreach ($statuses['opencart'] as $status): ?>
|
||||||
<?php $uid = $status['order_status_id']?>
|
<?php $uid = $status['order_status_id']?>
|
||||||
<div class="intarocrm_unit">
|
<div class="retailcrm_unit">
|
||||||
<select id="intarocrm_status_<?php echo $uid; ?>" name="intarocrm_status[<?php echo $uid; ?>]" >
|
<select id="retailcrm_status_<?php echo $uid; ?>" name="retailcrm_status[<?php echo $uid; ?>]" >
|
||||||
<?php foreach ($statuses['intarocrm'] as $k => $v): ?>
|
<?php foreach ($statuses['retailcrm'] as $k => $v): ?>
|
||||||
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['intarocrm_status'][$uid]) && $v['code'] == $saved_settings['intarocrm_status'][$uid]):?>selected="selected"<?php endif;?>>
|
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_status'][$uid]) && $v['code'] == $saved_settings['retailcrm_status'][$uid]):?>selected="selected"<?php endif;?>>
|
||||||
<?php echo $v['name'];?>
|
<?php echo $v['name'];?>
|
||||||
</option>
|
</option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
<label for="intarocrm_status_<?php echo $status['order_status_id']; ?>"><?php echo $status['name']; ?></label>
|
<label for="retailcrm_status_<?php echo $status['order_status_id']; ?>"><?php echo $status['name']; ?></label>
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
<h4><?php echo $intarocrm_dict_payment; ?></h4>
|
<h4><?php echo $retailcrm_dict_payment; ?></h4>
|
||||||
<?php foreach ($payments['opencart'] as $key => $value): ?>
|
<?php foreach ($payments['opencart'] as $key => $value): ?>
|
||||||
<div class="intarocrm_unit">
|
<div class="retailcrm_unit">
|
||||||
<select id="intarocrm_payment_<?php echo $key; ?>" name="intarocrm_payment[<?php echo $key; ?>]" >
|
<select id="retailcrm_payment_<?php echo $key; ?>" name="retailcrm_payment[<?php echo $key; ?>]" >
|
||||||
<?php foreach ($payments['intarocrm'] as $k => $v): ?>
|
<?php foreach ($payments['retailcrm'] as $k => $v): ?>
|
||||||
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['intarocrm_payment'][$key]) && $v['code'] == $saved_settings['intarocrm_payment'][$key]):?>selected="selected"<?php endif;?>>
|
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_payment'][$key]) && $v['code'] == $saved_settings['retailcrm_payment'][$key]):?>selected="selected"<?php endif;?>>
|
||||||
<?php echo $v['name'];?>
|
<?php echo $v['name'];?>
|
||||||
</option>
|
</option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
<label for="intarocrm_payment_<?php echo $key; ?>"><?php echo $value; ?></label>
|
<label for="retailcrm_payment_<?php echo $key; ?>"><?php echo $value; ?></label>
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
@ -93,7 +93,6 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php //var_dump($saved_settings);?>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
class ModelIntarocrmOrder extends Model {
|
|
||||||
|
|
||||||
public function send($order, $order_id)
|
|
||||||
{
|
|
||||||
$this->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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
22
catalog/model/retailcrm/order.php
Normal file
22
catalog/model/retailcrm/order.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
class ModelRetailcrmOrder extends Model {
|
||||||
|
|
||||||
|
public function send($order, $order_id)
|
||||||
|
{
|
||||||
|
$this->load->model('setting/setting');
|
||||||
|
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
||||||
|
$settings['domain'] = parse_url(HTTP_SERVER, PHP_URL_HOST);
|
||||||
|
|
||||||
|
if(
|
||||||
|
!empty($settings['retailcrm_url'])
|
||||||
|
&&
|
||||||
|
!empty($settings['retailcrm_apikey'])
|
||||||
|
) {
|
||||||
|
require_once DIR_SYSTEM . 'library/retailcrm/Retailcrm.php';
|
||||||
|
$order['order_id'] = $order_id;
|
||||||
|
$crm = new ApiHelper($settings);
|
||||||
|
$crm->processOrder($order);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
$cli_action = 'module/intarocrm/export_icml';
|
$cli_action = 'module/retailcrm/icml';
|
||||||
require_once('cli_dispatch.php');
|
require_once('cli_dispatch.php');
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
$cli_action = 'module/intarocrm/order_history';
|
$cli_action = 'module/retailcrm/history';
|
||||||
require_once('cli_dispatch.php');
|
require_once('cli_dispatch.php');
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
Changelog
|
|
||||||
=========
|
|
||||||
|
|
||||||
### v.0.1.1
|
|
||||||
|
|
||||||
* Устранена ошибка редактирования, при которой терялась часть данных при получении истории из CRM
|
|
||||||
* Оптимизирован код получения и обработки истории заказов
|
|
||||||
* Актуализированы переводы
|
|
||||||
|
|
||||||
|
|
||||||
### v.0.1
|
|
||||||
|
|
||||||
* Реализован интерфейс настроек модуля
|
|
||||||
* Реализована отправка данных о заказе/клиенте в CRM
|
|
||||||
* Реализована выгрузка каталога (cron only)
|
|
||||||
* Реализовано получение данных о заказах, сделанных на стороне CRM (cron only)
|
|
||||||
|
|
@ -1,72 +0,0 @@
|
|||||||
Installation
|
|
||||||
============
|
|
||||||
|
|
||||||
### Clone module.
|
|
||||||
```
|
|
||||||
git clone git@github.com:/retailcrm/opencart-module.git
|
|
||||||
```
|
|
||||||
|
|
||||||
### Install Rest API Client.
|
|
||||||
|
|
||||||
```
|
|
||||||
cd opencart-module/system/library/intarocrm
|
|
||||||
./composer.phar install
|
|
||||||
```
|
|
||||||
|
|
||||||
### Install module
|
|
||||||
```
|
|
||||||
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/intarocrm.xml
|
|
||||||
```
|
|
||||||
|
|
||||||
### Exchange setup
|
|
||||||
|
|
||||||
|
|
||||||
#### Export new order from shop to CRM
|
|
||||||
|
|
||||||
```
|
|
||||||
$this->load->model('intarocrm/order');
|
|
||||||
$this->model_intarocrm_order->send($data, $order_id);
|
|
||||||
```
|
|
||||||
|
|
||||||
Add this lines into:
|
|
||||||
* /catalog/model/checkout/order.php script, into addOrder method before return statement
|
|
||||||
|
|
||||||
```
|
|
||||||
if (!isset($data['fromApi'])) {
|
|
||||||
$this->load->model('setting/setting');
|
|
||||||
$status = $this->model_setting_setting->getSetting('intarocrm');
|
|
||||||
$data['order_status'] = $status['intarocrm_status'][$data['order_status_id']];
|
|
||||||
|
|
||||||
$this->load->model('intarocrm/order');
|
|
||||||
$this->model_intarocrm_order->send($data, $order_id);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Add this lines 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
|
|
||||||
```
|
|
@ -1,6 +0,0 @@
|
|||||||
TODO
|
|
||||||
====
|
|
||||||
|
|
||||||
* Export old customers & orders
|
|
||||||
* New customers export
|
|
||||||
* Make sources PSR-2 compatible
|
|
2
system/library/intarocrm/.gitignore
vendored
2
system/library/intarocrm/.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
/vendor
|
|
||||||
composer.lock
|
|
@ -1,231 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
require_once __DIR__ . '/vendor/autoload.php';
|
|
||||||
|
|
||||||
class ApiHelper
|
|
||||||
{
|
|
||||||
private $dir, $fileDate;
|
|
||||||
protected $intaroApi, $log, $settings;
|
|
||||||
|
|
||||||
public function __construct($settings) {
|
|
||||||
$this->dir = __DIR__ . '/../../logs/';
|
|
||||||
$this->fileDate = $this->dir . 'intarocrm_history.log';
|
|
||||||
$this->settings = $settings;
|
|
||||||
$this->domain = $settings['domain'];
|
|
||||||
|
|
||||||
$this->log = new Monolog\Logger('intarocrm');
|
|
||||||
$this->log->pushHandler(
|
|
||||||
new Monolog\Handler\StreamHandler($this->dir . 'intarocrm_module.log', Monolog\Logger::INFO)
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->intaroApi = new IntaroCrm\RestApi(
|
|
||||||
$settings['intarocrm_url'],
|
|
||||||
$settings['intarocrm_apikey']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function processOrder($data) {
|
|
||||||
|
|
||||||
$order = array();
|
|
||||||
$customer = array();
|
|
||||||
$customers = array();
|
|
||||||
|
|
||||||
$payment_code = $data['payment_code'];
|
|
||||||
$delivery_code = $data['shipping_code'];
|
|
||||||
$settings = $this->settings;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$customers = $this->intaroApi->customers($data['telephone'], $data['email'], $data['lastname'], 200, 0);
|
|
||||||
} catch (IntaroCrm\Exception\ApiException $e) {
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::customers:' . $e->getMessage());
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::customers:' . json_encode($data));
|
|
||||||
} catch (IntaroCrm\Exception\CurlException $e) {
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::customers::Curl:' . $e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(count($customers) > 0 && isset($customers[0]['externalId'])) {
|
|
||||||
$order['customerId'] = $customers[0]['externalId'];
|
|
||||||
} else {
|
|
||||||
$order['customerId'] = ($data['customer_id'] != '') ? $data['customer_id'] : (int) substr((microtime(true) * 10000) . mt_rand(1, 1000), 10, -1);
|
|
||||||
$customer['externalId'] = $order['customerId'];
|
|
||||||
$customer['firstName'] = $data['firstname'];
|
|
||||||
$customer['lastName'] = $data['lastname'];
|
|
||||||
$customer['email'] = $data['email'];
|
|
||||||
$customer['phones'] = array(array('number' => $data['telephone']));
|
|
||||||
|
|
||||||
$customer['address']['country'] = $data['payment_country_id'];
|
|
||||||
$customer['address']['region'] = $data['payment_zone_id'];
|
|
||||||
|
|
||||||
$customer['address']['text'] = implode(', ', array(
|
|
||||||
$data['payment_postcode'],
|
|
||||||
$data['payment_country'],
|
|
||||||
$data['payment_city'],
|
|
||||||
$data['payment_address_1'],
|
|
||||||
$data['payment_address_2']
|
|
||||||
));
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->customer = $this->intaroApi->customerEdit($customer);
|
|
||||||
} catch (IntaroCrm\Exception\ApiException $e) {
|
|
||||||
$this->customer = $e->getMessage();
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderCreate:' . $e->getMessage());
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderCreate:' . json_encode($order));
|
|
||||||
} catch (IntaroCrm\Exception\CurlException $e) {
|
|
||||||
$this->customer = $e->getMessage();
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderCreate::Curl:' . $e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($customer);
|
|
||||||
unset($customers);
|
|
||||||
|
|
||||||
$order['externalId'] = $data['order_id'];
|
|
||||||
$order['firstName'] = $data['firstname'];
|
|
||||||
$order['lastName'] = $data['lastname'];
|
|
||||||
$order['email'] = $data['email'];
|
|
||||||
$order['phone'] = $data['telephone'];
|
|
||||||
$order['customerComment'] = $data['comment'];
|
|
||||||
|
|
||||||
$deliveryCost = 0;
|
|
||||||
$orderTotals = isset($data['totals']) ? $data['totals'] : $data['order_total'] ;
|
|
||||||
|
|
||||||
foreach ($orderTotals as $totals) {
|
|
||||||
if ($totals['code'] == 'shipping') {
|
|
||||||
$deliveryCost = $totals['value'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$order['createdAt'] = date('Y-m-d H:i:s');
|
|
||||||
$order['paymentType'] = $settings['intarocrm_payment'][$payment_code];
|
|
||||||
|
|
||||||
$country = (isset($data['shipping_country'])) ? $data['shipping_country'] : '' ;
|
|
||||||
|
|
||||||
$order['delivery'] = array(
|
|
||||||
'code' => $settings['intarocrm_delivery'][$delivery_code],
|
|
||||||
'cost' => $deliveryCost,
|
|
||||||
'address' => array(
|
|
||||||
'index' => $data['shipping_postcode'],
|
|
||||||
'city' => $data['shipping_city'],
|
|
||||||
'country' => $data['shipping_country_id'],
|
|
||||||
'region' => $data['shipping_zone_id'],
|
|
||||||
'text' => implode(', ', array(
|
|
||||||
$data['shipping_postcode'],
|
|
||||||
$country,
|
|
||||||
$data['shipping_city'],
|
|
||||||
$data['shipping_address_1'],
|
|
||||||
$data['shipping_address_2']
|
|
||||||
))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$orderProducts = isset($data['products']) ? $data['products'] : $data['order_product'];
|
|
||||||
|
|
||||||
foreach ($orderProducts as $product) {
|
|
||||||
$order['items'][] = array(
|
|
||||||
'productId' => $product['product_id'],
|
|
||||||
'productName' => $product['name'],
|
|
||||||
'initialPrice' => $product['price'],
|
|
||||||
'quantity' => $product['quantity'],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($data['order_status_id'])) {
|
|
||||||
$order['status'] = $data['order_status'];
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->intaroApi->orderEdit($order);
|
|
||||||
} catch (IntaroCrm\Exception\ApiException $e) {
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderCreate:' . $e->getMessage());
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderCreate:' . json_encode($order));
|
|
||||||
} catch (IntaroCrm\Exception\CurlException $e) {
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderCreate::Curl:' . $e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function orderHistory() {
|
|
||||||
|
|
||||||
$orders = array();
|
|
||||||
|
|
||||||
try {
|
|
||||||
$orders = $this->intaroApi->orderHistory($this->getDate());
|
|
||||||
$this->saveDate($this->intaroApi->getGeneratedAt()->format('Y-m-d H:i:s'));
|
|
||||||
} catch (IntaroCrm\Exception\ApiException $e) {
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderHistory:' . $e->getMessage());
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderHistory:' . json_encode($orders));
|
|
||||||
|
|
||||||
return false;
|
|
||||||
} catch (IntaroCrm\Exception\CurlException $e) {
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderHistory::Curl:' . $e->getMessage());
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $orders;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function orderFixExternalIds($data)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
return $this->intaroApi->orderFixExternalIds($data);
|
|
||||||
} catch (IntaroCrm\Exception\ApiException $e) {
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds:' . $e->getMessage());
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds:' . json_encode($data));
|
|
||||||
|
|
||||||
return false;
|
|
||||||
} catch (IntaroCrm\Exception\CurlException $e) {
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds::Curl:' . $e->getMessage());
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function customerFixExternalIds($data)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
return $this->intaroApi->customerFixExternalIds($data);
|
|
||||||
} catch (IntaroCrm\Exception\ApiException $e) {
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::customerFixExternalIds:' . $e->getMessage());
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::customerFixExternalIds:' . json_encode($data));
|
|
||||||
|
|
||||||
return false;
|
|
||||||
} catch (IntaroCrm\Exception\CurlException $e) {
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::customerFixExternalIds::Curl:' . $e->getMessage());
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getOrder($order_id)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
return $this->intaroApi->orderGet($order_id);
|
|
||||||
} catch (IntaroCrm\Exception\ApiException $e) {
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds:' . $e->getMessage());
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds:' . json_encode($order));
|
|
||||||
|
|
||||||
return false;
|
|
||||||
} catch (IntaroCrm\Exception\CurlException $e) {
|
|
||||||
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds::Curl:' . $e->getMessage());
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private function saveDate($date) {
|
|
||||||
file_put_contents($this->fileDate, $date, LOCK_EX);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getDate() {
|
|
||||||
if (file_exists($this->fileDate)) {
|
|
||||||
$result = file_get_contents($this->fileDate);
|
|
||||||
} else {
|
|
||||||
$result = date('Y-m-d H:i:s', strtotime('-2 days', strtotime(date('Y-m-d H:i:s'))));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "retailcrm/opencart-module",
|
|
||||||
"description": "Opencart integration for IntaroCRM",
|
|
||||||
"type": "library",
|
|
||||||
"keywords": ["api", "Intaro CRM", "rest"],
|
|
||||||
"homepage": "http://www.retailcrm.ru/",
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Alex Lushpai",
|
|
||||||
"email": "lushpai@intaro.ru",
|
|
||||||
"role": "Developer"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"support": {
|
|
||||||
"email": "support@intarocrm.ru"
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": ">=5.3",
|
|
||||||
"retailcrm/api-client-php": "1.3.*",
|
|
||||||
"symfony/console": "2.6.*",
|
|
||||||
"monolog/monolog": "1.12.*"
|
|
||||||
},
|
|
||||||
"autoload": {
|
|
||||||
"psr-0": {
|
|
||||||
"": "/"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
1279
system/library/retailcrm.php
Normal file
1279
system/library/retailcrm.php
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user