mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-25 06:36:06 +03:00
compatibility with opencart versions 2.3-3.0 and RetailCRM API v3, v4, v5
This commit is contained in:
parent
0aff088a69
commit
71537c7482
@ -9,7 +9,7 @@ require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
|
|||||||
* @package RetailCrm
|
* @package RetailCrm
|
||||||
* @author RetailCrm <integration@retailcrm.ru>
|
* @author RetailCrm <integration@retailcrm.ru>
|
||||||
* @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/ApiVersion5
|
||||||
*/
|
*/
|
||||||
class ControllerExtensionModuleRetailcrm extends Controller
|
class ControllerExtensionModuleRetailcrm extends Controller
|
||||||
{
|
{
|
||||||
@ -24,54 +24,56 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
*/
|
*/
|
||||||
public function install()
|
public function install()
|
||||||
{
|
{
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
$this->load->model('setting/setting');
|
$this->load->model('setting/setting');
|
||||||
|
|
||||||
$this->model_setting_setting
|
$this->model_setting_setting
|
||||||
->editSetting('retailcrm', array(
|
->editSetting($moduleTitle, array(
|
||||||
'retailcrm_status' => 1,
|
$moduleTitle . '_status' => 1,
|
||||||
'retailcrm_country' => array($this->config->get('config_country_id'))
|
$moduleTitle . '_country' => array($this->config->get('config_country_id'))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->load->model('extension/event');
|
$this->loadModels();
|
||||||
|
|
||||||
$this->model_extension_event
|
$this->{'model_' . $this->modelEvent}
|
||||||
->addEvent(
|
->addEvent(
|
||||||
'retailcrm',
|
$moduleTitle,
|
||||||
'catalog/model/checkout/order/addOrder/after',
|
'catalog/model/checkout/order/addOrder/after',
|
||||||
'extension/module/retailcrm/order_create'
|
'extension/module/retailcrm/order_create'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->model_extension_event
|
$this->{'model_' . $this->modelEvent}
|
||||||
->addEvent(
|
->addEvent(
|
||||||
'retailcrm',
|
$moduleTitle,
|
||||||
'catalog/model/checkout/order/addOrderHistory/after',
|
'catalog/model/checkout/order/addOrderHistory/after',
|
||||||
'extension/module/retailcrm/order_edit'
|
'extension/module/retailcrm/order_edit'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->model_extension_event
|
$this->{'model_' . $this->modelEvent}
|
||||||
->addEvent(
|
->addEvent(
|
||||||
'retailcrm',
|
$moduleTitle,
|
||||||
'catalog/model/account/customer/addCustomer/after',
|
'catalog/model/account/customer/addCustomer/after',
|
||||||
'extension/module/retailcrm/customer_create'
|
'extension/module/retailcrm/customer_create'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->model_extension_event
|
$this->{'model_' . $this->modelEvent}
|
||||||
->addEvent(
|
->addEvent(
|
||||||
'retailcrm',
|
$moduleTitle,
|
||||||
'catalog/model/account/customer/editCustomer/after',
|
'catalog/model/account/customer/editCustomer/after',
|
||||||
'extension/module/retailcrm/customer_edit'
|
'extension/module/retailcrm/customer_edit'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->model_extension_event
|
$this->{'model_' . $this->modelEvent}
|
||||||
->addEvent(
|
->addEvent(
|
||||||
'retailcrm',
|
$moduleTitle,
|
||||||
'catalog/model/account/address/editAddress/after',
|
'catalog/model/account/address/editAddress/after',
|
||||||
'extension/module/retailcrm/customer_edit'
|
'extension/module/retailcrm/customer_edit'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->model_extension_event
|
$this->{'model_' . $this->modelEvent}
|
||||||
->addEvent(
|
->addEvent(
|
||||||
'retailcrm',
|
$moduleTitle,
|
||||||
'admin/model/customer/customer/editCustomer/after',
|
'admin/model/customer/customer/editCustomer/after',
|
||||||
'extension/module/retailcrm/customer_edit'
|
'extension/module/retailcrm/customer_edit'
|
||||||
);
|
);
|
||||||
@ -84,13 +86,15 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
*/
|
*/
|
||||||
public function uninstall()
|
public function uninstall()
|
||||||
{
|
{
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
$this->uninstall_collector();
|
$this->uninstall_collector();
|
||||||
$this->load->model('setting/setting');
|
$this->load->model('setting/setting');
|
||||||
$this->model_setting_setting
|
$this->model_setting_setting
|
||||||
->editSetting('retailcrm', array('retailcrm_status' => 0));
|
->editSetting($moduleTitle, array($moduleTitle . '_status' => 0));
|
||||||
|
|
||||||
$this->load->model('extension/event');
|
$this->loadModels();
|
||||||
$this->model_extension_event->deleteEvent('retailcrm');
|
|
||||||
|
$this->{'model_' . $this->modelEvent}->deleteEvent($moduleTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -100,10 +104,12 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
*/
|
*/
|
||||||
public function install_collector()
|
public function install_collector()
|
||||||
{
|
{
|
||||||
$this->load->model('extension/extension');
|
$collector = $this->getCollectorTitle();
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
|
$this->loadModels();
|
||||||
$this->load->model('setting/setting');
|
$this->load->model('setting/setting');
|
||||||
$this->model_extension_extension->install('analytics', 'daemon_collector');
|
$this->{'model_' . $this->modelExtension}->install('analytics', $collector);
|
||||||
$this->model_setting_setting->editSetting('daemon_collector', array('daemon_collector_status' => 1));
|
$this->model_setting_setting->editSetting($collector, array($collector . '_status' => 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -113,10 +119,11 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
*/
|
*/
|
||||||
public function uninstall_collector()
|
public function uninstall_collector()
|
||||||
{
|
{
|
||||||
$this->load->model('extension/extension');
|
$collector = $this->getCollectorTitle();
|
||||||
|
$this->loadModels();
|
||||||
$this->load->model('setting/setting');
|
$this->load->model('setting/setting');
|
||||||
$this->model_setting_setting->editSetting('daemon_collector', array('daemon_collector_status' => 0));
|
$this->model_setting_setting->editSetting($collector, array($collector . '_status' => 0));
|
||||||
$this->model_extension_extension->uninstall('analytics', 'daemon_collector');
|
$this->{'model_' . $this->modelExtension}->uninstall('analytics', $collector);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,38 +133,41 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$this->load->model('extension/extension');
|
$this->loadModels();
|
||||||
$this->load->model('localisation/country');
|
$this->load->model('localisation/country');
|
||||||
$this->load->model('setting/setting');
|
$this->load->model('setting/setting');
|
||||||
$this->load->model('extension/module');
|
|
||||||
$this->load->model('extension/retailcrm/references');
|
$this->load->model('extension/retailcrm/references');
|
||||||
$this->load->language('extension/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()) {
|
$tokenTitle = $this->getTokenTitle();
|
||||||
$analytics = $this->model_extension_extension->getInstalled('analytics');
|
$moduleTitle = $this->getModuleTitle();
|
||||||
|
$collector = $this->getCollectorTitle();
|
||||||
|
|
||||||
if ($this->request->post['retailcrm_collector_active'] == 1 &&
|
if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
|
||||||
!in_array('daemon_collector', $analytics)) {
|
$analytics = $this->{'model_' . $this->modelExtension}->getInstalled('analytics');
|
||||||
|
|
||||||
|
if ($this->request->post[$moduleTitle . '_collector_active'] == 1 &&
|
||||||
|
!in_array($collector, $analytics)) {
|
||||||
$this->install_collector();
|
$this->install_collector();
|
||||||
} elseif ($this->request->post['retailcrm_collector_active'] == 0 &&
|
} elseif ($this->request->post[$moduleTitle . '_collector_active'] == 0 &&
|
||||||
in_array('daemon_collector', $analytics)) {
|
in_array($collector, $analytics)) {
|
||||||
$this->uninstall_collector();
|
$this->uninstall_collector();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parse_url($this->request->post['retailcrm_url'])){
|
if (parse_url($this->request->post[$moduleTitle . '_url'])){
|
||||||
$crm_url = parse_url($this->request->post['retailcrm_url'], PHP_URL_HOST);
|
$crm_url = parse_url($this->request->post[$moduleTitle . '_url'], PHP_URL_HOST);
|
||||||
$this->request->post['retailcrm_url'] = 'https://'.$crm_url;
|
$this->request->post[$moduleTitle . '_url'] = 'https://'.$crm_url;
|
||||||
}
|
}
|
||||||
$this->model_setting_setting->editSetting(
|
$this->model_setting_setting->editSetting(
|
||||||
'retailcrm',
|
$moduleTitle,
|
||||||
$this->request->post
|
$this->request->post
|
||||||
);
|
);
|
||||||
|
|
||||||
$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(
|
||||||
'extension/module/retailcrm', 'token=' . $this->session->data['token'],
|
'extension/module/retailcrm', $tokenTitle . '=' . $this->session->data[$tokenTitle],
|
||||||
'SSL'
|
'SSL'
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -172,6 +182,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
'button_cancel',
|
'button_cancel',
|
||||||
'text_notice',
|
'text_notice',
|
||||||
'retailcrm_title',
|
'retailcrm_title',
|
||||||
|
'retailcrm_apiversion',
|
||||||
'retailcrm_url',
|
'retailcrm_url',
|
||||||
'retailcrm_apikey',
|
'retailcrm_apikey',
|
||||||
'retailcrm_base_settings',
|
'retailcrm_base_settings',
|
||||||
@ -205,7 +216,6 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
'text_require'
|
'text_require'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->load->model('extension/extension');
|
|
||||||
$_data = &$data;
|
$_data = &$data;
|
||||||
|
|
||||||
foreach ($text_strings as $text) {
|
foreach ($text_strings as $text) {
|
||||||
@ -214,13 +224,16 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
|
|
||||||
$_data['retailcrm_errors'] = array();
|
$_data['retailcrm_errors'] = array();
|
||||||
$_data['saved_settings'] = $this->model_setting_setting
|
$_data['saved_settings'] = $this->model_setting_setting
|
||||||
->getSetting('retailcrm');
|
->getSetting($moduleTitle);
|
||||||
|
|
||||||
$url = isset($_data['saved_settings']['retailcrm_url'])
|
$url = isset($_data['saved_settings'][$moduleTitle . '_url'])
|
||||||
? $_data['saved_settings']['retailcrm_url']
|
? $_data['saved_settings'][$moduleTitle . '_url']
|
||||||
: null;
|
: null;
|
||||||
$key = isset($_data['saved_settings']['retailcrm_apikey'])
|
$key = isset($_data['saved_settings'][$moduleTitle . '_apikey'])
|
||||||
? $_data['saved_settings']['retailcrm_apikey']
|
? $_data['saved_settings'][$moduleTitle . '_apikey']
|
||||||
|
: null;
|
||||||
|
$apiVersion = isset($_data['saved_settings'][$moduleTitle . '_apiversion'])
|
||||||
|
? $_data['saved_settings'][$moduleTitle . '_apiversion']
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
if (!empty($url) && !empty($key)) {
|
if (!empty($url) && !empty($key)) {
|
||||||
@ -228,7 +241,8 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
$this->retailcrm = new RetailcrmProxy(
|
$this->retailcrm = new RetailcrmProxy(
|
||||||
$url,
|
$url,
|
||||||
$key,
|
$key,
|
||||||
DIR_SYSTEM . 'storage/logs/retailcrm.log'
|
DIR_SYSTEM . 'storage/logs/retailcrm.log',
|
||||||
|
$apiVersion
|
||||||
);
|
);
|
||||||
|
|
||||||
$_data['delivery'] = $this->model_extension_retailcrm_references
|
$_data['delivery'] = $this->model_extension_retailcrm_references
|
||||||
@ -241,7 +255,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$config_data = array(
|
$config_data = array(
|
||||||
'retailcrm_status'
|
$moduleTitle . '_status'
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($config_data as $conf) {
|
foreach ($config_data as $conf) {
|
||||||
@ -270,7 +284,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
'text' => $this->language->get('text_home'),
|
'text' => $this->language->get('text_home'),
|
||||||
'href' => $this->url->link(
|
'href' => $this->url->link(
|
||||||
'common/home',
|
'common/home',
|
||||||
'token=' . $this->session->data['token'], 'SSL'
|
$tokenTitle . '=' . $this->session->data[$tokenTitle], 'SSL'
|
||||||
),
|
),
|
||||||
'separator' => false
|
'separator' => false
|
||||||
);
|
);
|
||||||
@ -279,7 +293,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
'text' => $this->language->get('text_module'),
|
'text' => $this->language->get('text_module'),
|
||||||
'href' => $this->url->link(
|
'href' => $this->url->link(
|
||||||
'extension/extension/module',
|
'extension/extension/module',
|
||||||
'token=' . $this->session->data['token'], 'SSL'
|
$tokenTitle . '=' . $this->session->data[$tokenTitle], 'SSL'
|
||||||
),
|
),
|
||||||
'separator' => ' :: '
|
'separator' => ' :: '
|
||||||
);
|
);
|
||||||
@ -288,19 +302,19 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
'text' => $this->language->get('retailcrm_title'),
|
'text' => $this->language->get('retailcrm_title'),
|
||||||
'href' => $this->url->link(
|
'href' => $this->url->link(
|
||||||
'extension/module/retailcrm',
|
'extension/module/retailcrm',
|
||||||
'token=' . $this->session->data['token'], 'SSL'
|
$tokenTitle . '=' . $this->session->data[$tokenTitle], 'SSL'
|
||||||
),
|
),
|
||||||
'separator' => ' :: '
|
'separator' => ' :: '
|
||||||
);
|
);
|
||||||
|
|
||||||
$_data['action'] = $this->url->link(
|
$_data['action'] = $this->url->link(
|
||||||
'extension/module/retailcrm',
|
'extension/module/retailcrm',
|
||||||
'token=' . $this->session->data['token'], 'SSL'
|
$tokenTitle . '=' . $this->session->data[$tokenTitle], 'SSL'
|
||||||
);
|
);
|
||||||
|
|
||||||
$_data['cancel'] = $this->url->link(
|
$_data['cancel'] = $this->url->link(
|
||||||
'extension/extension',
|
version_compare(VERSION, '3.0', '<') ? 'extension/extension' : 'marketplace/extension',
|
||||||
'token=' . $this->session->data['token'], 'SSL'
|
$tokenTitle . '=' . $this->session->data[$tokenTitle], 'SSL'
|
||||||
);
|
);
|
||||||
|
|
||||||
$_data['modules'] = array();
|
$_data['modules'] = array();
|
||||||
@ -319,7 +333,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
$_data['footer'] = $this->load->controller('common/footer');
|
$_data['footer'] = $this->load->controller('common/footer');
|
||||||
$_data['countries'] = $this->model_localisation_country->getCountries();
|
$_data['countries'] = $this->model_localisation_country->getCountries();
|
||||||
$_data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG;
|
$_data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG;
|
||||||
$_data['token'] = $this->request->get['token'];
|
$_data[$tokenTitle] = $this->request->get[$tokenTitle];
|
||||||
|
|
||||||
if(file_exists(DIR_SYSTEM . '/cron/export_done')) {
|
if(file_exists(DIR_SYSTEM . '/cron/export_done')) {
|
||||||
$_data['export_file'] = false;
|
$_data['export_file'] = false;
|
||||||
@ -334,10 +348,13 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
);
|
);
|
||||||
|
|
||||||
$_data['collectorFields'] = $collectorFields;
|
$_data['collectorFields'] = $collectorFields;
|
||||||
|
$_data['api_versions'] = array('v3', 'v4', 'v5');
|
||||||
|
$_data['default_apiversion'] = 'v5';
|
||||||
|
|
||||||
$this->response->setOutput(
|
$this->response->setOutput(
|
||||||
$this->load->view('extension/module/retailcrm.tpl', $_data)
|
$this->load->view('extension/module/retailcrm', $_data)
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -347,12 +364,28 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
*/
|
*/
|
||||||
public function history()
|
public function history()
|
||||||
{
|
{
|
||||||
if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/history.php')) {
|
$moduleTitle = $this->getModuleTitle();
|
||||||
$this->load->model('extension/retailcrm/custom/history');
|
$this->load->model('setting/setting');
|
||||||
$this->model_extension_retailcrm_custom_history->request();
|
$settings = $this->model_setting_setting->getSetting($moduleTitle);
|
||||||
|
|
||||||
|
if ($settings[$moduleTitle . '_apiversion'] == 'v3') {
|
||||||
|
|
||||||
|
if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/history/v3.php')) {
|
||||||
|
$this->load->model('extension/retailcrm/custom/history/v3');
|
||||||
|
$this->model_extension_retailcrm_custom_history_v3->request();
|
||||||
|
} else {
|
||||||
|
$this->load->model('extension/retailcrm/history/v3');
|
||||||
|
$this->model_extension_retailcrm_history_v3->request();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->load->model('extension/retailcrm/history');
|
|
||||||
$this->model_extension_retailcrm_history->request();
|
if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/history/v4-5.php')) {
|
||||||
|
$this->load->model('extension/retailcrm/custom/history/v4-5');
|
||||||
|
$this->model_extension_retailcrm_custom_history_v4_5->request();
|
||||||
|
} else {
|
||||||
|
$this->load->model('extension/retailcrm/history/v4_5');
|
||||||
|
$this->model_extension_retailcrm_history_v4_5->request();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -444,6 +477,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
{
|
{
|
||||||
$order_id = isset($this->request->get['order_id']) ? $this->request->get['order_id'] : '';
|
$order_id = isset($this->request->get['order_id']) ? $this->request->get['order_id'] : '';
|
||||||
$this->load->model('sale/order');
|
$this->load->model('sale/order');
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
|
|
||||||
$data = $this->model_sale_order->getOrder($order_id);
|
$data = $this->model_sale_order->getOrder($order_id);
|
||||||
$data['products'] = $this->model_sale_order->getOrderProducts($order_id);
|
$data['products'] = $this->model_sale_order->getOrderProducts($order_id);
|
||||||
@ -451,8 +485,8 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
|
|
||||||
if (!isset($data['fromApi'])) {
|
if (!isset($data['fromApi'])) {
|
||||||
$this->load->model('setting/setting');
|
$this->load->model('setting/setting');
|
||||||
$status = $this->model_setting_setting->getSetting('retailcrm');
|
$status = $this->model_setting_setting->getSetting($moduleTitle);
|
||||||
$data['order_status'] = $status['retailcrm_status'][$data['order_status_id']];
|
$data['order_status'] = $status[$moduleTitle . '_status'][$data['order_status_id']];
|
||||||
|
|
||||||
$this->load->model('extension/retailcrm/order');
|
$this->load->model('extension/retailcrm/order');
|
||||||
$result = $this->model_extension_retailcrm_order->uploadOrder($data);
|
$result = $this->model_extension_retailcrm_order->uploadOrder($data);
|
||||||
@ -478,12 +512,13 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
$orders = $this->model_sale_order->getOrders();
|
$orders = $this->model_sale_order->getOrders();
|
||||||
|
|
||||||
$fullOrders = array();
|
$fullOrders = array();
|
||||||
|
|
||||||
foreach($orders as $order) {
|
foreach($orders as $order) {
|
||||||
$fullOrder = $this->model_sale_order->getOrder($order['order_id']);
|
$fullOrder = $this->model_sale_order->getOrder($order['order_id']);
|
||||||
|
|
||||||
$fullOrder['order_total'] = $this->model_sale_order->getOrderTotals($order['order_id']);
|
$fullOrder['order_total'] = $this->model_sale_order->getOrderTotals($order['order_id']);
|
||||||
|
|
||||||
$fullOrder['products'] = $this->model_sale_order->getOrderProducts($order['order_id']);
|
$fullOrder['products'] = $this->model_sale_order->getOrderProducts($order['order_id']);
|
||||||
|
|
||||||
foreach($fullOrder['products'] as $key=>$product) {
|
foreach($fullOrder['products'] as $key=>$product) {
|
||||||
$fullOrder['products'][$key]['option'] = $this->model_sale_order->getOrderOptions($product['order_id'], $product['order_product_id']);
|
$fullOrder['products'][$key]['option'] = $this->model_sale_order->getOrderOptions($product['order_id'], $product['order_product_id']);
|
||||||
}
|
}
|
||||||
@ -503,13 +538,15 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
*/
|
*/
|
||||||
private function validate()
|
private function validate()
|
||||||
{
|
{
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
|
|
||||||
if (!$this->user->hasPermission('modify', 'extension/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');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->request->post['retailcrm_collector']['custom']) &&
|
if (isset($this->request->post[$moduleTitle . '_collector']['custom']) &&
|
||||||
$this->request->post['retailcrm_collector']['custom_form'] == 1) {
|
$this->request->post[$moduleTitle . '_collector']['custom_form'] == 1) {
|
||||||
$customField = $this->request->post['retailcrm_collector']['custom'];
|
$customField = $this->request->post[$moduleTitle . '_collector']['custom'];
|
||||||
|
|
||||||
if (empty($customField['name']) && empty($customField['email']) && empty($customField['phone'])) {
|
if (empty($customField['name']) && empty($customField['email']) && empty($customField['phone'])) {
|
||||||
$this->_error['fields'] = $this->language->get('text_error_collector_fields');
|
$this->_error['fields'] = $this->language->get('text_error_collector_fields');
|
||||||
@ -522,4 +559,58 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function loadModels()
|
||||||
|
{
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$this->load->model('extension/event');
|
||||||
|
$this->load->model('extension/extension');
|
||||||
|
// $this->load->model('extension/module');
|
||||||
|
|
||||||
|
$this->modelEvent = 'extension_event';
|
||||||
|
$this->modelExtension = 'extension_extension';
|
||||||
|
// $this->modelModule = 'extension_module';
|
||||||
|
} else {
|
||||||
|
$this->load->model('setting/event');
|
||||||
|
$this->load->model('setting/extension');
|
||||||
|
// $this->load->model('setting/module');
|
||||||
|
|
||||||
|
$this->modelEvent = 'setting_event';
|
||||||
|
$this->modelExtension = 'setting_extension';
|
||||||
|
// $this->modelModule = 'setting_module';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getTokenTitle()
|
||||||
|
{
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$token = 'token';
|
||||||
|
} else {
|
||||||
|
$token = 'user_token';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $token;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getModuleTitle()
|
||||||
|
{
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$title = 'retailcrm';
|
||||||
|
} else {
|
||||||
|
$title = 'module_retailcrm';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getCollectorTitle()
|
||||||
|
{
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$title = 'daemon_collector';
|
||||||
|
} else {
|
||||||
|
$title = 'analytics_daemon_collector';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ $_['references_tab_text'] = 'References';
|
|||||||
$_['collector_tab_text'] = 'Collector';
|
$_['collector_tab_text'] = 'Collector';
|
||||||
$_['collector_custom_text'] = 'Custom form';
|
$_['collector_custom_text'] = 'Custom form';
|
||||||
|
|
||||||
|
$_['retailcrm_apiversion'] = 'API Version';
|
||||||
$_['retailcrm_url'] = 'RetailCRM URL';
|
$_['retailcrm_url'] = 'RetailCRM URL';
|
||||||
$_['retailcrm_apikey'] = 'RetailCRM API Key';
|
$_['retailcrm_apikey'] = 'RetailCRM API Key';
|
||||||
$_['collector_site_key'] = 'Site key';
|
$_['collector_site_key'] = 'Site key';
|
||||||
|
@ -18,6 +18,7 @@ $_['references_tab_text'] = 'Справочники';
|
|||||||
$_['collector_tab_text'] = 'Collector';
|
$_['collector_tab_text'] = 'Collector';
|
||||||
$_['collector_custom_text'] = 'Настройка полей формы';
|
$_['collector_custom_text'] = 'Настройка полей формы';
|
||||||
|
|
||||||
|
$_['retailcrm_apiversion'] = 'Версия API';
|
||||||
$_['retailcrm_url'] = 'Адрес RetailCRM';
|
$_['retailcrm_url'] = 'Адрес RetailCRM';
|
||||||
$_['retailcrm_apikey'] = 'Api ключ RetailCRM';
|
$_['retailcrm_apikey'] = 'Api ключ RetailCRM';
|
||||||
$_['collector_site_key'] = 'Ключ сайта';
|
$_['collector_site_key'] = 'Ключ сайта';
|
||||||
|
@ -2,22 +2,12 @@
|
|||||||
|
|
||||||
class ModelExtensionRetailcrmCustomer extends Model {
|
class ModelExtensionRetailcrmCustomer extends Model {
|
||||||
|
|
||||||
public function uploadToCrm($customers) {
|
public function uploadToCrm($customers)
|
||||||
$this->load->model('setting/setting');
|
{
|
||||||
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
$this->initApi();
|
||||||
|
|
||||||
if(empty($customers))
|
if(empty($customers))
|
||||||
return false;
|
return false;
|
||||||
if(empty($settings['retailcrm_url']) || empty($settings['retailcrm_apikey']))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
|
|
||||||
|
|
||||||
$this->retailcrmApi = new RetailcrmProxy(
|
|
||||||
$settings['retailcrm_url'],
|
|
||||||
$settings['retailcrm_apikey'],
|
|
||||||
DIR_SYSTEM . 'storage/logs/retailcrm.log'
|
|
||||||
);
|
|
||||||
|
|
||||||
$customersToCrm = array();
|
$customersToCrm = array();
|
||||||
|
|
||||||
@ -32,22 +22,12 @@ class ModelExtensionRetailcrmCustomer extends Model {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function changeInCrm($customer) {
|
public function changeInCrm($customer)
|
||||||
$this->load->model('setting/setting');
|
{
|
||||||
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
$this->initApi();
|
||||||
|
|
||||||
if(empty($customer))
|
if(empty($customer))
|
||||||
return false;
|
return false;
|
||||||
if(empty($settings['retailcrm_url']) || empty($settings['retailcrm_apikey']))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
|
|
||||||
|
|
||||||
$this->retailcrmApi = new RetailcrmProxy(
|
|
||||||
$settings['retailcrm_url'],
|
|
||||||
$settings['retailcrm_apikey'],
|
|
||||||
DIR_SYSTEM . 'storage/logs/retailcrm.log'
|
|
||||||
);
|
|
||||||
|
|
||||||
$customerToCrm = $this->process($customer);
|
$customerToCrm = $this->process($customer);
|
||||||
|
|
||||||
@ -80,4 +60,34 @@ class ModelExtensionRetailcrmCustomer extends Model {
|
|||||||
|
|
||||||
return $customerToCrm;
|
return $customerToCrm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function initApi()
|
||||||
|
{
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
|
$this->load->model('setting/setting');
|
||||||
|
$settings = $this->model_setting_setting->getSetting($moduleTitle);
|
||||||
|
|
||||||
|
if(empty($settings[$moduleTitle . '_url']) || empty($settings[$moduleTitle . '_apikey']))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
|
||||||
|
|
||||||
|
$this->retailcrmApi = new RetailcrmProxy(
|
||||||
|
$settings[$moduleTitle . '_url'],
|
||||||
|
$settings[$moduleTitle . '_apikey'],
|
||||||
|
DIR_SYSTEM . 'storage/logs/retailcrm.log',
|
||||||
|
$settings[$moduleTitle . '_apiversion']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getModuleTitle()
|
||||||
|
{
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$title = 'retailcrm';
|
||||||
|
} else {
|
||||||
|
$title = 'module_retailcrm';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
475
admin/model/extension/retailcrm/history/v3.php
Normal file
475
admin/model/extension/retailcrm/history/v3.php
Normal file
@ -0,0 +1,475 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ModelExtensionRetailcrmHistoryV3 extends Model
|
||||||
|
{
|
||||||
|
protected $createResult;
|
||||||
|
|
||||||
|
private $opencartApiClient;
|
||||||
|
|
||||||
|
public function request()
|
||||||
|
{
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
|
$this->load->model('setting/setting');
|
||||||
|
$this->load->model('setting/store');
|
||||||
|
$this->load->model('user/api');
|
||||||
|
$this->load->model('sale/order');
|
||||||
|
$this->load->model('customer/customer');
|
||||||
|
$this->load->model('extension/retailcrm/references');
|
||||||
|
$this->load->model('catalog/product');
|
||||||
|
$this->load->model('catalog/option');
|
||||||
|
$this->load->model('localisation/zone');
|
||||||
|
|
||||||
|
$this->load->language('extension/module/retailcrm');
|
||||||
|
|
||||||
|
$settings = $this->model_setting_setting->getSetting($moduleTitle);
|
||||||
|
$history = $this->model_setting_setting->getSetting('retailcrm_history');
|
||||||
|
$settings['domain'] = parse_url(HTTP_SERVER, PHP_URL_HOST);
|
||||||
|
|
||||||
|
$url = isset($settings[$moduleTitle . '_url']) ? $settings[$moduleTitle . '_url'] : null;
|
||||||
|
$key = isset($settings[$moduleTitle . '_apikey']) ? $settings[$moduleTitle . '_apikey'] : null;
|
||||||
|
|
||||||
|
if (empty($url) || empty($key)) {
|
||||||
|
$this->log->addNotice('You need to configure retailcrm module first.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->opencartApiClient = new OpencartApiClient($this->registry);
|
||||||
|
|
||||||
|
$crm = new RetailcrmProxy(
|
||||||
|
$settings[$moduleTitle . '_url'],
|
||||||
|
$settings[$moduleTitle . '_apikey'],
|
||||||
|
DIR_SYSTEM . 'storage/logs/retailcrm.log',
|
||||||
|
$settings[$moduleTitle . '_apiversion']
|
||||||
|
);
|
||||||
|
|
||||||
|
$lastRun = !empty($history['retailcrm_history'])
|
||||||
|
? new DateTime($history['retailcrm_history'])
|
||||||
|
: new DateTime(date('Y-m-d H:i:s', strtotime('-1 days', strtotime(date('Y-m-d H:i:s')))));
|
||||||
|
|
||||||
|
$packsOrders = $crm->ordersHistory($lastRun);
|
||||||
|
|
||||||
|
if(!$packsOrders->isSuccessful() && count($packsOrders['orders']) <= 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$generatedAt = $packsOrders['generatedAt'];
|
||||||
|
|
||||||
|
$this->subtotalSettings = $this->model_setting_setting->getSetting('sub_total');
|
||||||
|
$this->totalSettings = $this->model_setting_setting->getSetting('total');
|
||||||
|
$this->shippingSettings = $this->model_setting_setting->getSetting('shipping');
|
||||||
|
|
||||||
|
$this->delivery = array_flip($settings[$moduleTitle . '_delivery']);
|
||||||
|
$this->payment = array_flip($settings[$moduleTitle . '_payment']);
|
||||||
|
$this->status = array_flip($settings[$moduleTitle . '_status']);
|
||||||
|
|
||||||
|
$this->ocPayment = $this->model_extension_retailcrm_references
|
||||||
|
->getOpercartPaymentTypes();
|
||||||
|
|
||||||
|
$this->ocDelivery = $settings[$moduleTitle . '_delivery'];
|
||||||
|
|
||||||
|
$this->zones = $this->model_localisation_zone->getZones();
|
||||||
|
|
||||||
|
$updatedOrders = array();
|
||||||
|
$newOrders = array();
|
||||||
|
$orders = $packsOrders['orders'];
|
||||||
|
|
||||||
|
foreach ($orders as $order) {
|
||||||
|
|
||||||
|
if (isset($order['deleted'])) continue;
|
||||||
|
|
||||||
|
if (isset($order['externalId'])) {
|
||||||
|
$updatedOrders[] = $order['id'];
|
||||||
|
} else {
|
||||||
|
$newOrders[] = $order['id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($orders);
|
||||||
|
|
||||||
|
if (!empty($newOrders)) {
|
||||||
|
$orders = $crm->ordersList($filter = array('ids' => $newOrders));
|
||||||
|
if ($orders) {
|
||||||
|
$this->createResult = $this->createOrders($orders['orders']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($updatedOrders)) {
|
||||||
|
$orders = $crm->ordersList($filter = array('ids' => $updatedOrders));
|
||||||
|
if ($orders) {
|
||||||
|
$this->updateOrders($orders['orders']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->model_setting_setting->editSetting('retailcrm_history', array('retailcrm_history' => $generatedAt));
|
||||||
|
|
||||||
|
if (!empty($this->createResult['customers'])) {
|
||||||
|
$crm->customersFixExternalIds($this->createResult['customers']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($this->createResult['orders'])) {
|
||||||
|
$crm->ordersFixExternalIds($this->createResult['orders']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function updateOrders($orders)
|
||||||
|
{
|
||||||
|
foreach ($orders as $order) {
|
||||||
|
$store = $this->config->get('config_store_id');
|
||||||
|
|
||||||
|
$data = array();
|
||||||
|
|
||||||
|
$data['store_id'] = $store == null ? 0 : $store;
|
||||||
|
$data['customer'] = $order['firstName'];
|
||||||
|
$data['customer_id'] = (!empty($order['customer']['externalId'])) ? $order['customer']['externalId'] : 0;
|
||||||
|
$data['customer_group_id'] = 1;
|
||||||
|
$data['firstname'] = $order['firstName'];
|
||||||
|
$data['lastname'] = (!empty($order['lastName'])) ? $order['lastName'] : ' ';
|
||||||
|
$data['email'] = $order['email'];
|
||||||
|
$data['telephone'] = (!empty($order['phone'])) ? $order['phone'] : '';
|
||||||
|
$data['comment'] = !empty($order['customerComment']) ? $order['customerComment'] : '';
|
||||||
|
$data['fax'] = '';
|
||||||
|
|
||||||
|
$data['payment_address'] = '0';
|
||||||
|
$data['payment_firstname'] = $order['firstName'];
|
||||||
|
$data['payment_lastname'] = (!empty($order['lastName'])) ? $order['lastName'] : ' ';
|
||||||
|
$data['payment_address_1'] = isset($order['customer']['address']) ? $order['customer']['address']['text'] : '';
|
||||||
|
$data['payment_address_2'] = '';
|
||||||
|
$data['payment_company'] = '';
|
||||||
|
$data['payment_company_id'] = '';
|
||||||
|
$data['payment_city'] = !empty($order['customer']['address']['city']) ? $order['customer']['address']['city'] : $order['delivery']['address']['city'];
|
||||||
|
$data['payment_postcode'] = !empty( $order['customer']['address']['index'] ) ? $order['customer']['address']['index'] : $order['delivery']['address']['index'];
|
||||||
|
|
||||||
|
$region = '';
|
||||||
|
|
||||||
|
if (is_int($order['delivery']['address']['region'])) {
|
||||||
|
$region = $order['delivery']['address']['region'];
|
||||||
|
} else {
|
||||||
|
foreach ($this->zones as $zone) {
|
||||||
|
if ($order['delivery']['address']['region'] == $zone['name']) {
|
||||||
|
$region = $zone['zone_id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['payment_country_id'] = !empty($order['delivery']['address']['country']) ? $order['delivery']['address']['country'] : 0;
|
||||||
|
$data['payment_zone_id'] = !empty($order['delivery']['address']['region']) ? $order['delivery']['address']['region'] : $region;
|
||||||
|
|
||||||
|
$data['shipping_country_id'] = !empty($order['delivery']['address']['country']) ? $order['delivery']['address']['country'] : 0;
|
||||||
|
$data['shipping_zone_id'] = $region;
|
||||||
|
|
||||||
|
$data['shipping_address'] = '0';
|
||||||
|
$data['shipping_firstname'] = $order['firstName'];
|
||||||
|
$data['shipping_lastname'] = (!empty($order['lastName'])) ? $order['lastName'] : ' ';
|
||||||
|
$data['shipping_address_1'] = $order['delivery']['address']['text'];
|
||||||
|
$data['shipping_address_2'] = '';
|
||||||
|
$data['shipping_company'] = '';
|
||||||
|
$data['shipping_company_id'] = '';
|
||||||
|
$data['shipping_city'] = $order['delivery']['address']['city'];
|
||||||
|
$data['shipping_postcode'] = $order['delivery']['address']['index'];
|
||||||
|
|
||||||
|
$data['shipping'] = $this->delivery[$order['delivery']['code']];
|
||||||
|
$data['shipping_method'] = $this->ocDelivery[$data['shipping']];
|
||||||
|
$data['shipping_code'] = $this->delivery[$order['delivery']['code']];
|
||||||
|
|
||||||
|
$data['payment'] = $this->payment[$order['paymentType']];
|
||||||
|
$data['payment_method'] = $this->ocPayment[$data['payment']];
|
||||||
|
$data['payment_code'] = $this->payment[$order['paymentType']];
|
||||||
|
|
||||||
|
// this data will not retrive from crm for now
|
||||||
|
$data['tax'] = '';
|
||||||
|
$data['tax_id'] = '';
|
||||||
|
$data['product'] = '';
|
||||||
|
$data['product_id'] = '';
|
||||||
|
$data['reward'] = '';
|
||||||
|
$data['affiliate'] = '';
|
||||||
|
$data['affiliate_id'] = '';
|
||||||
|
$data['payment_tax_id'] = '';
|
||||||
|
$data['order_product_id'] = '';
|
||||||
|
$data['payment_company'] = '';
|
||||||
|
$data['payment_company_id'] = '';
|
||||||
|
$data['company'] = '';
|
||||||
|
$data['company_id'] = '';
|
||||||
|
|
||||||
|
$data['order_product'] = array();
|
||||||
|
|
||||||
|
foreach ($order['items'] as $item) {
|
||||||
|
//$product = $this->model_catalog_product->getProduct($item['offer']['externalId']);
|
||||||
|
$productId = $item['offer']['externalId'];
|
||||||
|
$options = array();
|
||||||
|
if(mb_strpos($item['offer']['externalId'], '#') > 1) {
|
||||||
|
$offer = explode('#', $item['offer']['externalId']);
|
||||||
|
$productId = $offer[0];
|
||||||
|
$optionsFromCRM = explode('_', $offer[1]);
|
||||||
|
|
||||||
|
foreach($optionsFromCRM as $optionFromCRM) {
|
||||||
|
$optionData = explode('-', $optionFromCRM);
|
||||||
|
$productOptionId = $optionData[0];
|
||||||
|
$optionValueId = $optionData[1];
|
||||||
|
|
||||||
|
$productOptions = $this->model_catalog_product->getProductOptions($productId);
|
||||||
|
|
||||||
|
foreach($productOptions as $productOption) {
|
||||||
|
if($productOptionId == $productOption['product_option_id']) {
|
||||||
|
foreach($productOption['product_option_value'] as $productOptionValue) {
|
||||||
|
if($productOptionValue['option_value_id'] == $optionValueId) {
|
||||||
|
$options[$productOptionId] = $productOptionValue['product_option_value_id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$data['order_product'][] = array(
|
||||||
|
'product_id' => $productId,
|
||||||
|
'quantity' => $item['quantity'],
|
||||||
|
'option' => $options
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0;
|
||||||
|
|
||||||
|
if(isset($order['discount']) && $order['discount'] > 0) {
|
||||||
|
$orderTotals = $this->model_sale_order->getOrderTotals($order['externalId']);
|
||||||
|
foreach($orderTotals as $orderTotal) {
|
||||||
|
if($orderTotal['code'] == 'coupon') {
|
||||||
|
$data['order_total'][] = $orderTotal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['order_total'] = array(
|
||||||
|
array(
|
||||||
|
'order_total_id' => '',
|
||||||
|
'code' => 'sub_total',
|
||||||
|
'title' => $this->language->get('product_summ'),
|
||||||
|
'value' => $order['summ'],
|
||||||
|
'text' => $order['summ'],
|
||||||
|
'sort_order' => $this->subtotalSettings['sub_total_sort_order']
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'order_total_id' => '',
|
||||||
|
'code' => 'shipping',
|
||||||
|
'title' => $this->ocDelivery[$data['shipping_code']],
|
||||||
|
'value' => $deliveryCost,
|
||||||
|
'text' => $deliveryCost,
|
||||||
|
'sort_order' => $this->shippingSettings['shipping_sort_order']
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'order_total_id' => '',
|
||||||
|
'code' => 'total',
|
||||||
|
'title' => $this->language->get('column_total'),
|
||||||
|
'value' => isset($order['totalSumm']) ? $order['totalSumm'] : $order['summ'] + $deliveryCost,
|
||||||
|
'text' => isset($order['totalSumm']) ? $order['totalSumm'] : $order['summ'] + $deliveryCost,
|
||||||
|
'sort_order' => $this->totalSettings['total_sort_order']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$data['fromApi'] = true;
|
||||||
|
|
||||||
|
if (array_key_exists($order['status'], $this->status)) {
|
||||||
|
$data['order_status_id'] = $this->status[$order['status']];
|
||||||
|
} else {
|
||||||
|
$tmpOrder = $this->model_sale_order->getOrder($order['externalId']);
|
||||||
|
$data['order_status_id'] = $tmpOrder['order_status_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->opencartApiClient->editOrder($order['externalId'], $data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createOrders($orders)
|
||||||
|
{
|
||||||
|
$customersIdsFix = array();
|
||||||
|
$ordersIdsFix = array();
|
||||||
|
|
||||||
|
foreach ($orders as $order) {
|
||||||
|
$store = $this->config->get('config_store_id');
|
||||||
|
|
||||||
|
$customer_id = (!empty($order['customer']['externalId']))
|
||||||
|
? $order['customer']['externalId']
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
$data = array();
|
||||||
|
|
||||||
|
if ($customer_id == 0) {
|
||||||
|
$cData = array(
|
||||||
|
'store_id' => 0,
|
||||||
|
'customer_group_id' => '1',
|
||||||
|
'firstname' => $order['firstName'],
|
||||||
|
'lastname' => (!empty($order['lastName'])) ? $order['lastName'] : ' ',
|
||||||
|
'email' => $order['email'],
|
||||||
|
'telephone' => (!empty($order['customer']['phones'][0]['number']) ) ? $order['customer']['phones'][0]['number'] : ' ',
|
||||||
|
'fax' => '',
|
||||||
|
'newsletter' => 0,
|
||||||
|
'password' => 'tmppass',
|
||||||
|
'status' => 1,
|
||||||
|
'address' => array(
|
||||||
|
array(
|
||||||
|
'firstname' => $order['firstName'],
|
||||||
|
'lastname' => (!empty($order['lastName'])) ? $order['lastName'] : ' ',
|
||||||
|
'address_1' => $order['customer']['address']['text'],
|
||||||
|
'address_2' => ' ',
|
||||||
|
'city' => !empty($order['customer']['address']['city']) ? $order['customer']['address']['city'] : $order['delivery']['address']['city'],
|
||||||
|
'postcode' => isset($order['customer']['address']['index']) ? $order['customer']['address']['index'] : $order['delivery']['address']['index'],
|
||||||
|
'tax_id' => '1',
|
||||||
|
'company' => '',
|
||||||
|
'company_id' => '',
|
||||||
|
'zone_id' => '0',
|
||||||
|
'country_id' => 0
|
||||||
|
)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
$this->model_customer_customer->addCustomer($cData);
|
||||||
|
|
||||||
|
if (!empty($order['email'])) {
|
||||||
|
$tryToFind = $this->model_customer_customer->getCustomerByEmail($order['email']);
|
||||||
|
$customer_id = $tryToFind['customer_id'];
|
||||||
|
} else {
|
||||||
|
$last = $this->model_customer_customer->getCustomers($data = array('order' => 'DESC', 'limit' => 1));
|
||||||
|
$customer_id = $last[0]['customer_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$customersIdsFix[] = array('id' => $order['customer']['id'], 'externalId' => (int)$customer_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['store_id'] = $store == null ? 0 : $store;
|
||||||
|
$data['customer'] = $order['firstName'];
|
||||||
|
$data['customer_id'] = $customer_id;
|
||||||
|
$data['customer_group_id'] = 1;
|
||||||
|
$data['firstname'] = $order['firstName'];
|
||||||
|
$data['lastname'] = (!empty($order['lastName'])) ? $order['lastName'] : ' ';
|
||||||
|
$data['email'] = $order['email'];
|
||||||
|
$data['telephone'] = (!empty($order['customer']['phones'][0]['number'])) ? $order['customer']['phones'][0]['number'] : ' ';
|
||||||
|
$data['comment'] = !empty($order['customerComment']) ? $order['customerComment'] : '';
|
||||||
|
$data['fax'] = '';
|
||||||
|
$data['payment_address'] = '0';
|
||||||
|
$data['payment_firstname'] = $order['firstName'];
|
||||||
|
$data['payment_lastname'] = (!empty($order['lastName'])) ? $order['lastName'] : ' ';
|
||||||
|
$data['payment_address_1'] = $order['customer']['address']['text'];
|
||||||
|
$data['payment_address_2'] = '';
|
||||||
|
$data['payment_company'] = '';
|
||||||
|
$data['payment_company_id'] = '';
|
||||||
|
$data['payment_city'] = !empty($order['customer']['address']['city']) ? $order['customer']['address']['city'] : $order['delivery']['address']['city'];
|
||||||
|
$data['payment_postcode'] = !empty($order['customer']['address']['index']) ? $order['customer']['address']['index'] : $order['delivery']['address']['index'];
|
||||||
|
|
||||||
|
$region = '';
|
||||||
|
|
||||||
|
if (!empty($order['delivery']['address']['region']) && is_int($order['delivery']['address']['region'])) {
|
||||||
|
$region = $order['delivery']['address']['region'];
|
||||||
|
} else {
|
||||||
|
foreach ($this->zones as $zone) {
|
||||||
|
if ($order['delivery']['address']['region'] == $zone['name']) {
|
||||||
|
$region = $zone['zone_id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['payment_country_id'] = !empty($order['delivery']['address']['country']) ? $order['delivery']['address']['country'] : 0;
|
||||||
|
$data['payment_zone_id'] = !empty($order['delivery']['address']['region']) ? $order['delivery']['address']['region'] : $region;
|
||||||
|
$data['shipping_country_id'] = !empty($order['delivery']['address']['country']) ? $order['delivery']['address']['country'] : 0;
|
||||||
|
$data['shipping_zone_id'] = $region;
|
||||||
|
$data['shipping_address'] = '0';
|
||||||
|
$data['shipping_firstname'] = $order['firstName'];
|
||||||
|
$data['shipping_lastname'] = (!empty($order['lastName'])) ? $order['lastName'] : ' ';
|
||||||
|
$data['shipping_address_1'] = $order['delivery']['address']['text'];
|
||||||
|
$data['shipping_address_2'] = '';
|
||||||
|
$data['shipping_company'] = '';
|
||||||
|
$data['shipping_company_id'] = '';
|
||||||
|
$data['shipping_city'] = $order['delivery']['address']['city'];
|
||||||
|
$data['shipping_postcode'] = $order['delivery']['address']['index'];
|
||||||
|
|
||||||
|
$data['shipping'] = $this->delivery[$order['delivery']['code']];
|
||||||
|
$data['shipping_method'] = $this->ocDelivery[$data['shipping']];
|
||||||
|
$data['shipping_code'] = $this->delivery[$order['delivery']['code']];
|
||||||
|
$data['payment'] = $this->payment[$order['paymentType']];
|
||||||
|
$data['payment_method'] = $this->ocPayment[$data['payment']];
|
||||||
|
$data['payment_code'] = $this->payment[$order['paymentType']];
|
||||||
|
|
||||||
|
// this data will not retrive from crm for now
|
||||||
|
$data['tax'] = '';
|
||||||
|
$data['tax_id'] = '';
|
||||||
|
$data['product'] = '';
|
||||||
|
$data['product_id'] = '';
|
||||||
|
$data['reward'] = '';
|
||||||
|
$data['affiliate'] = '';
|
||||||
|
$data['affiliate_id'] = '';
|
||||||
|
$data['payment_tax_id'] = '';
|
||||||
|
$data['order_product_id'] = '';
|
||||||
|
$data['payment_company'] = '';
|
||||||
|
$data['payment_company_id'] = '';
|
||||||
|
$data['company'] = '';
|
||||||
|
$data['company_id'] = '';
|
||||||
|
|
||||||
|
$data['order_product'] = array();
|
||||||
|
|
||||||
|
foreach ($order['items'] as $item) {
|
||||||
|
$product = $this->model_catalog_product->getProduct($item['offer']['externalId']);
|
||||||
|
$data['order_product'][] = array(
|
||||||
|
'product_id' => $item['offer']['externalId'],
|
||||||
|
'name' => $item['offer']['name'],
|
||||||
|
'quantity' => $item['quantity'],
|
||||||
|
'price' => $item['initialPrice'],
|
||||||
|
'total' => $item['initialPrice'] * $item['quantity'],
|
||||||
|
'model' => $product['model'],
|
||||||
|
|
||||||
|
// this data will not retrive from crm
|
||||||
|
'order_product_id' => '',
|
||||||
|
'tax' => 0,
|
||||||
|
'reward' => 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0;
|
||||||
|
|
||||||
|
$data['order_total'] = array(
|
||||||
|
array(
|
||||||
|
'order_total_id' => '',
|
||||||
|
'code' => 'sub_total',
|
||||||
|
'title' => $this->language->get('product_summ'),
|
||||||
|
'value' => $order['summ'],
|
||||||
|
'text' => $order['summ'],
|
||||||
|
'sort_order' => $this->subtotalSettings['sub_total_sort_order']
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'order_total_id' => '',
|
||||||
|
'code' => 'shipping',
|
||||||
|
'title' => $this->ocDelivery[$data['shipping_code']],
|
||||||
|
'value' => $deliveryCost,
|
||||||
|
'text' => $deliveryCost,
|
||||||
|
'sort_order' => $this->shippingSettings['shipping_sort_order']
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'order_total_id' => '',
|
||||||
|
'code' => 'total',
|
||||||
|
'title' => $this->language->get('column_total'),
|
||||||
|
'value' => !empty($order['totalSumm']) ? $order['totalSumm'] : $order['summ'] + $deliveryCost,
|
||||||
|
'text' => isset($order['totalSumm']) ? $order['totalSumm'] : $order['summ'] + $deliveryCost,
|
||||||
|
'sort_order' => $this->totalSettings['total_sort_order']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$data['fromApi'] = true;
|
||||||
|
$data['order_status_id'] = 1;
|
||||||
|
|
||||||
|
$this->opencartApiClient->addOrder($data);
|
||||||
|
|
||||||
|
$last = $this->model_sale_order->getOrders($data = array('order' => 'DESC', 'limit' => 1, 'start' => 0));
|
||||||
|
|
||||||
|
$ordersIdsFix[] = array('id' => $order['id'], 'externalId' => (int) $last[0]['order_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('customers' => $customersIdsFix, 'orders' => $ordersIdsFix);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getModuleTitle()
|
||||||
|
{
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$title = 'retailcrm';
|
||||||
|
} else {
|
||||||
|
$title = 'module_retailcrm';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class ModelExtensionRetailcrmHistory extends Model
|
class ModelExtensionRetailcrmHistoryV45 extends Model
|
||||||
{
|
{
|
||||||
protected $createResult;
|
protected $createResult;
|
||||||
|
|
||||||
@ -8,6 +8,7 @@ class ModelExtensionRetailcrmHistory extends Model
|
|||||||
|
|
||||||
public function request()
|
public function request()
|
||||||
{
|
{
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
$this->load->model('setting/setting');
|
$this->load->model('setting/setting');
|
||||||
$this->load->model('setting/store');
|
$this->load->model('setting/store');
|
||||||
$this->load->model('user/api');
|
$this->load->model('user/api');
|
||||||
@ -20,12 +21,12 @@ class ModelExtensionRetailcrmHistory extends Model
|
|||||||
|
|
||||||
$this->load->language('extension/module/retailcrm');
|
$this->load->language('extension/module/retailcrm');
|
||||||
|
|
||||||
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
$settings = $this->model_setting_setting->getSetting($moduleTitle);
|
||||||
$history = $this->model_setting_setting->getSetting('retailcrm_history');
|
$history = $this->model_setting_setting->getSetting('retailcrm_history');
|
||||||
$settings['domain'] = parse_url(HTTP_SERVER, PHP_URL_HOST);
|
$settings['domain'] = parse_url(HTTP_SERVER, PHP_URL_HOST);
|
||||||
|
|
||||||
$url = isset($settings['retailcrm_url']) ? $settings['retailcrm_url'] : null;
|
$url = isset($settings[$moduleTitle . '_url']) ? $settings[$moduleTitle . '_url'] : null;
|
||||||
$key = isset($settings['retailcrm_apikey']) ? $settings['retailcrm_apikey'] : null;
|
$key = isset($settings[$moduleTitle . '_apikey']) ? $settings[$moduleTitle . '_apikey'] : null;
|
||||||
|
|
||||||
if (empty($url) || empty($key)) {
|
if (empty($url) || empty($key)) {
|
||||||
$this->log->addNotice('You need to configure retailcrm module first.');
|
$this->log->addNotice('You need to configure retailcrm module first.');
|
||||||
@ -35,9 +36,10 @@ class ModelExtensionRetailcrmHistory extends Model
|
|||||||
$this->opencartApiClient = new OpencartApiClient($this->registry);
|
$this->opencartApiClient = new OpencartApiClient($this->registry);
|
||||||
|
|
||||||
$crm = new RetailcrmProxy(
|
$crm = new RetailcrmProxy(
|
||||||
$settings['retailcrm_url'],
|
$settings[$moduleTitle . '_url'],
|
||||||
$settings['retailcrm_apikey'],
|
$settings[$moduleTitle . '_apikey'],
|
||||||
DIR_SYSTEM . 'storage/logs/retailcrm.log'
|
DIR_SYSTEM . 'storage/logs/retailcrm.log',
|
||||||
|
$settings[$moduleTitle . '_apiversion']
|
||||||
);
|
);
|
||||||
|
|
||||||
$lastRun = !empty($history['retailcrm_history'])
|
$lastRun = !empty($history['retailcrm_history'])
|
||||||
@ -62,14 +64,14 @@ class ModelExtensionRetailcrmHistory extends Model
|
|||||||
$this->totalSettings = $this->model_setting_setting->getSetting('total');
|
$this->totalSettings = $this->model_setting_setting->getSetting('total');
|
||||||
$this->shippingSettings = $this->model_setting_setting->getSetting('shipping');
|
$this->shippingSettings = $this->model_setting_setting->getSetting('shipping');
|
||||||
|
|
||||||
$this->delivery = array_flip($settings['retailcrm_delivery']);
|
$this->delivery = array_flip($settings[$moduleTitle . '_delivery']);
|
||||||
$this->payment = array_flip($settings['retailcrm_payment']);
|
$this->payment = array_flip($settings[$moduleTitle . '_payment']);
|
||||||
$this->status = array_flip($settings['retailcrm_status']);
|
$this->status = array_flip($settings[$moduleTitle . '_status']);
|
||||||
|
|
||||||
$this->ocPayment = $this->model_extension_retailcrm_references
|
$this->ocPayment = $this->model_extension_retailcrm_references
|
||||||
->getOpercartPaymentTypes();
|
->getOpercartPaymentTypes();
|
||||||
|
|
||||||
$this->ocDelivery = $settings['retailcrm_delivery'];
|
$this->ocDelivery = $settings[$moduleTitle . '_delivery'];
|
||||||
|
|
||||||
$this->zones = $this->model_localisation_zone->getZones();
|
$this->zones = $this->model_localisation_zone->getZones();
|
||||||
|
|
||||||
@ -139,6 +141,18 @@ class ModelExtensionRetailcrmHistory extends Model
|
|||||||
foreach ($orders as $order) {
|
foreach ($orders as $order) {
|
||||||
$store = $this->config->get('config_store_id');
|
$store = $this->config->get('config_store_id');
|
||||||
|
|
||||||
|
if ($order['payments']) {
|
||||||
|
foreach ($order['payments'] as $orderPayment) {
|
||||||
|
if (isset($orderPayment['externalId'])) {
|
||||||
|
$payment = $orderPayment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($payment) && count($order['payments']) == 1) {
|
||||||
|
$payment = end($order['payments']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$data = array();
|
$data = array();
|
||||||
|
|
||||||
$data['store_id'] = $store == null ? 0 : $store;
|
$data['store_id'] = $store == null ? 0 : $store;
|
||||||
@ -194,9 +208,16 @@ class ModelExtensionRetailcrmHistory extends Model
|
|||||||
$data['shipping_method'] = $this->ocDelivery[$data['shipping']];
|
$data['shipping_method'] = $this->ocDelivery[$data['shipping']];
|
||||||
$data['shipping_code'] = $this->delivery[$order['delivery']['code']];
|
$data['shipping_code'] = $this->delivery[$order['delivery']['code']];
|
||||||
|
|
||||||
$data['payment'] = $this->payment[$order['paymentType']];
|
if (isset($payment)) {
|
||||||
$data['payment_method'] = $this->ocPayment[$data['payment']];
|
$data['payment'] = $this->payment[$payment['type']];
|
||||||
$data['payment_code'] = $this->payment[$order['paymentType']];
|
$data['payment_method'] = $this->ocPayment[$data['payment']];
|
||||||
|
$data['payment_code'] = $this->payment[$payment['type']];
|
||||||
|
} else {
|
||||||
|
$this->load->model('sale/order');
|
||||||
|
$order_data = $this->model_sale_order->getOrder($order['externalId']);
|
||||||
|
$data['payment_method'] = $order_data['payment_method'];
|
||||||
|
$data['payment_code'] = $order_data['payment_code'];
|
||||||
|
}
|
||||||
|
|
||||||
// this data will not retrive from crm for now
|
// this data will not retrive from crm for now
|
||||||
$data['tax'] = '';
|
$data['tax'] = '';
|
||||||
@ -308,6 +329,10 @@ class ModelExtensionRetailcrmHistory extends Model
|
|||||||
foreach ($orders as $order) {
|
foreach ($orders as $order) {
|
||||||
$store = $this->config->get('config_store_id');
|
$store = $this->config->get('config_store_id');
|
||||||
|
|
||||||
|
if ($order['payments']) {
|
||||||
|
$payment = end($order['payments']);
|
||||||
|
}
|
||||||
|
|
||||||
$customer_id = (!empty($order['customer']['externalId']))
|
$customer_id = (!empty($order['customer']['externalId']))
|
||||||
? $order['customer']['externalId']
|
? $order['customer']['externalId']
|
||||||
: 0;
|
: 0;
|
||||||
@ -406,9 +431,12 @@ class ModelExtensionRetailcrmHistory extends Model
|
|||||||
$data['shipping'] = $this->delivery[$order['delivery']['code']];
|
$data['shipping'] = $this->delivery[$order['delivery']['code']];
|
||||||
$data['shipping_method'] = $this->ocDelivery[$data['shipping']];
|
$data['shipping_method'] = $this->ocDelivery[$data['shipping']];
|
||||||
$data['shipping_code'] = $this->delivery[$order['delivery']['code']];
|
$data['shipping_code'] = $this->delivery[$order['delivery']['code']];
|
||||||
$data['payment'] = $this->payment[$order['paymentType']];
|
|
||||||
$data['payment_method'] = $this->ocPayment[$data['payment']];
|
if (isset($payment)) {
|
||||||
$data['payment_code'] = $this->payment[$order['paymentType']];
|
$data['payment'] = $this->payment[$payment['type']];
|
||||||
|
$data['payment_method'] = $this->ocPayment[$data['payment']];
|
||||||
|
$data['payment_code'] = $this->payment[$payment['type']];
|
||||||
|
}
|
||||||
|
|
||||||
// this data will not retrive from crm for now
|
// this data will not retrive from crm for now
|
||||||
$data['tax'] = '';
|
$data['tax'] = '';
|
||||||
@ -510,4 +538,15 @@ class ModelExtensionRetailcrmHistory extends Model
|
|||||||
$this->model_customer_customer->editCustomer($customer_id, $customerData);
|
$this->model_customer_customer->editCustomer($customer_id, $customerData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getModuleTitle()
|
||||||
|
{
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$title = 'retailcrm';
|
||||||
|
} else {
|
||||||
|
$title = 'module_retailcrm';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
}
|
}
|
@ -3,10 +3,8 @@
|
|||||||
class ModelExtensionRetailcrmOrder extends Model {
|
class ModelExtensionRetailcrmOrder extends Model {
|
||||||
|
|
||||||
public function uploadToCrm($orders) {
|
public function uploadToCrm($orders) {
|
||||||
$this->load->model('catalog/product');
|
|
||||||
|
|
||||||
$this->load->model('setting/setting');
|
$this->initApi();
|
||||||
$this->settings = $this->model_setting_setting->getSetting('retailcrm');
|
|
||||||
|
|
||||||
$ordersToCrm = array();
|
$ordersToCrm = array();
|
||||||
|
|
||||||
@ -17,48 +15,40 @@ class ModelExtensionRetailcrmOrder extends Model {
|
|||||||
$chunkedOrders = array_chunk($ordersToCrm, 50);
|
$chunkedOrders = array_chunk($ordersToCrm, 50);
|
||||||
|
|
||||||
foreach($chunkedOrders as $ordersPart) {
|
foreach($chunkedOrders as $ordersPart) {
|
||||||
$this->retailcrmApi->ordersUpload($ordersPart);
|
$this->retailcrm->ordersUpload($ordersPart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function uploadOrder($order)
|
public function uploadOrder($order_data)
|
||||||
{
|
{
|
||||||
if(isset($this->request->post['fromApi'])) return;
|
if(isset($this->request->post['fromApi'])) return;
|
||||||
|
|
||||||
$this->load->model('setting/setting');
|
$moduleTitle = $this->getModuleTitle();
|
||||||
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
$this->initApi();
|
||||||
|
|
||||||
if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) {
|
$customers = $this->retailcrm->customersList(
|
||||||
$this->load->model('catalog/product');
|
array(
|
||||||
|
'name' => $order_data['telephone'],
|
||||||
|
'email' => $order_data['email']
|
||||||
|
),
|
||||||
|
1,
|
||||||
|
100
|
||||||
|
);
|
||||||
|
|
||||||
require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
|
$order = $this->process($order_data);
|
||||||
|
|
||||||
$this->retailcrm = new RetailcrmProxy(
|
if($customers) {
|
||||||
$settings['retailcrm_url'],
|
foreach ($customers['customers'] as $customer) {
|
||||||
$settings['retailcrm_apikey'],
|
$order['customer']['id'] = $customer['id'];
|
||||||
DIR_SYSTEM . 'storage/logs/retailcrm.log'
|
|
||||||
);
|
|
||||||
|
|
||||||
$customers = $this->retailcrm->customersList(
|
|
||||||
array(
|
|
||||||
'name' => $order['telephone'],
|
|
||||||
'email' => $order['email']
|
|
||||||
),
|
|
||||||
1,
|
|
||||||
100
|
|
||||||
);
|
|
||||||
|
|
||||||
$order = $this->process($order);
|
|
||||||
|
|
||||||
if($customers) {
|
|
||||||
foreach ($customers['customers'] as $customer) {
|
|
||||||
$order['customer']['id'] = $customer['id'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unset($customers);
|
unset($customers);
|
||||||
|
|
||||||
$result = $this->retailcrm->ordersCreate($order);
|
$result = $this->retailcrm->ordersCreate($order);
|
||||||
|
|
||||||
|
if ($this->settings[$moduleTitle . '_apiversion'] == 'v5' && $result->isSuccessful()) {
|
||||||
|
$this->createPayment($order_data, $order_data['order_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@ -67,6 +57,7 @@ class ModelExtensionRetailcrmOrder extends Model {
|
|||||||
private function process($order_data) {
|
private function process($order_data) {
|
||||||
$order = array();
|
$order = array();
|
||||||
|
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
$payment_code = $order_data['payment_code'];
|
$payment_code = $order_data['payment_code'];
|
||||||
$delivery_code = $order_data['shipping_code'];
|
$delivery_code = $order_data['shipping_code'];
|
||||||
|
|
||||||
@ -92,12 +83,15 @@ class ModelExtensionRetailcrmOrder extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$order['createdAt'] = $order_data['date_added'];
|
$order['createdAt'] = $order_data['date_added'];
|
||||||
$order['paymentType'] = $this->settings['retailcrm_payment'][$payment_code];
|
|
||||||
|
if ($this->settings[$moduleTitle . '_apiversion'] != 'v5') {
|
||||||
|
$order['paymentType'] = $this->settings[$moduleTitle . '_payment'][$payment_code];
|
||||||
|
}
|
||||||
|
|
||||||
$country = (isset($order_data['shipping_country'])) ? $order_data['shipping_country'] : '' ;
|
$country = (isset($order_data['shipping_country'])) ? $order_data['shipping_country'] : '' ;
|
||||||
|
|
||||||
$order['delivery'] = array(
|
$order['delivery'] = array(
|
||||||
'code' => !empty($delivery_code) ? $this->settings['retailcrm_delivery'][$delivery_code] : '',
|
'code' => !empty($delivery_code) ? $this->settings[$moduleTitle . '_delivery'][$delivery_code] : '',
|
||||||
'cost' => $deliveryCost,
|
'cost' => $deliveryCost,
|
||||||
'address' => array(
|
'address' => array(
|
||||||
'index' => $order_data['shipping_postcode'],
|
'index' => $order_data['shipping_postcode'],
|
||||||
@ -126,6 +120,14 @@ class ModelExtensionRetailcrmOrder extends Model {
|
|||||||
$productOptions = $this->model_catalog_product->getProductOptions($product['product_id']);
|
$productOptions = $this->model_catalog_product->getProductOptions($product['product_id']);
|
||||||
|
|
||||||
foreach($product['option'] as $option) {
|
foreach($product['option'] as $option) {
|
||||||
|
if ($option['type'] == 'checkbox') {
|
||||||
|
$properties[] = array(
|
||||||
|
'code' => $option['product_option_value_id'],
|
||||||
|
'name' => $option['name'],
|
||||||
|
'value' => $option['value']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if(!in_array($option['type'], $offerOptions)) continue;
|
if(!in_array($option['type'], $offerOptions)) continue;
|
||||||
foreach($productOptions as $productOption) {
|
foreach($productOptions as $productOption) {
|
||||||
if($productOption['product_option_id'] = $option['product_option_id']) {
|
if($productOption['product_option_id'] = $option['product_option_id']) {
|
||||||
@ -147,16 +149,98 @@ class ModelExtensionRetailcrmOrder extends Model {
|
|||||||
$offerId = implode('_', $offerId);
|
$offerId = implode('_', $offerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$order['items'][] = array(
|
if ($this->settings[$moduleTitle . '_apiversion'] != 'v3') {
|
||||||
'offer' => array(
|
$item = array(
|
||||||
'externalId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id']
|
'offer' => array(
|
||||||
),
|
'externalId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id']
|
||||||
'productName' => $product['name'],
|
),
|
||||||
'initialPrice' => $product['price'],
|
'productName' => $product['name'],
|
||||||
'quantity' => $product['quantity'],
|
'initialPrice' => $product['price'],
|
||||||
);
|
'quantity' => $product['quantity'],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$item = array(
|
||||||
|
'productName' => $product['name'],
|
||||||
|
'initialPrice' => $product['price'],
|
||||||
|
'quantity' => $product['quantity'],
|
||||||
|
'productId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($properties)) $item['properties'] = $properties;
|
||||||
|
$order['items'][] = $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $order;
|
return $order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function createPayment($order, $order_id)
|
||||||
|
{
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
|
$settings = $this->model_setting_setting->getSetting($moduleTitle);
|
||||||
|
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$settingPaid = $this->model_setting_setting->getSetting($order['payment_code']);
|
||||||
|
} else {
|
||||||
|
$settingPaid = $this->model_setting_setting->getSetting('payment_' . $order['payment_code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$payment_code = $order['payment_code'];
|
||||||
|
|
||||||
|
foreach ($order['totals'] as $total) {
|
||||||
|
if ($total['code'] == 'total') $amount = $total['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$payment = array(
|
||||||
|
'externalId' => $order_id,
|
||||||
|
'type' => $settings[$moduleTitle . '_payment'][$payment_code],
|
||||||
|
'amount' => $amount
|
||||||
|
);
|
||||||
|
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
if ($order['order_status_id'] == $settingPaid[$order['payment_code'] . '_order_status_id']) {
|
||||||
|
$payment['status'] = 'paid';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($order['order_status_id'] == $settingPaid['payment_' . $order['payment_code'] . '_order_status_id']) {
|
||||||
|
$payment['status'] = 'paid';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$payment['order'] = array(
|
||||||
|
'externalId' => $order_id
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->retailcrm->ordersPaymentCreate($payment);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function initApi()
|
||||||
|
{
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
|
$this->load->model('setting/setting');
|
||||||
|
$this->settings = $this->model_setting_setting->getSetting($moduleTitle);
|
||||||
|
|
||||||
|
if(!empty($this->settings[$moduleTitle . '_url']) && !empty($this->settings[$moduleTitle . '_apikey'])) {
|
||||||
|
|
||||||
|
require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
|
||||||
|
|
||||||
|
$this->retailcrm = new RetailcrmProxy(
|
||||||
|
$this->settings[$moduleTitle . '_url'],
|
||||||
|
$this->settings[$moduleTitle . '_apikey'],
|
||||||
|
DIR_SYSTEM . 'storage/logs/retailcrm.log',
|
||||||
|
$this->settings[$moduleTitle . '_apiversion']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getModuleTitle()
|
||||||
|
{
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$title = 'retailcrm';
|
||||||
|
} else {
|
||||||
|
$title = 'module_retailcrm';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,13 @@ class ModelExtensionRetailcrmReferences extends Model
|
|||||||
|
|
||||||
$this->load->language('extension/payment/' . $extension);
|
$this->load->language('extension/payment/' . $extension);
|
||||||
|
|
||||||
if ($this->config->get($extension . '_status')) {
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$configStatus = $extension . '_status';
|
||||||
|
} else {
|
||||||
|
$configStatus = 'payment_' . $extension . '_status';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->config->get($configStatus)) {
|
||||||
$paymentTypes[$extension] = strip_tags(
|
$paymentTypes[$extension] = strip_tags(
|
||||||
$this->language->get('heading_title')
|
$this->language->get('heading_title')
|
||||||
);
|
);
|
||||||
@ -73,55 +79,55 @@ class ModelExtensionRetailcrmReferences extends Model
|
|||||||
|
|
||||||
public function getApiDeliveryTypes()
|
public function getApiDeliveryTypes()
|
||||||
{
|
{
|
||||||
$this->load->model('setting/setting');
|
$this->initApi();
|
||||||
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
|
||||||
|
|
||||||
if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) {
|
$response = $this->retailcrm->deliveryTypesList();
|
||||||
$this->retailcrm = new RetailcrmProxy(
|
|
||||||
$settings['retailcrm_url'],
|
|
||||||
$settings['retailcrm_apikey'],
|
|
||||||
DIR_SYSTEM . 'storage/logs/retailcrm.log'
|
|
||||||
);
|
|
||||||
|
|
||||||
$response = $this->retailcrm->deliveryTypesList();
|
return ($response === false) ? array() : $response->deliveryTypes;
|
||||||
|
|
||||||
return ($response === false) ? array() : $response->deliveryTypes;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getApiOrderStatuses()
|
public function getApiOrderStatuses()
|
||||||
{
|
{
|
||||||
$this->load->model('setting/setting');
|
$this->initApi();
|
||||||
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
|
||||||
|
|
||||||
if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) {
|
$response = $this->retailcrm->statusesList();
|
||||||
$this->retailcrm = new RetailcrmProxy(
|
|
||||||
$settings['retailcrm_url'],
|
|
||||||
$settings['retailcrm_apikey'],
|
|
||||||
DIR_SYSTEM . 'storage/logs/retailcrm.log'
|
|
||||||
);
|
|
||||||
|
|
||||||
$response = $this->retailcrm->statusesList();
|
return ($response === false) ? array() : $response->statuses;
|
||||||
|
|
||||||
return ($response === false) ? array() : $response->statuses;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getApiPaymentTypes()
|
public function getApiPaymentTypes()
|
||||||
{
|
{
|
||||||
|
$this->initApi();
|
||||||
|
|
||||||
|
$response = $this->retailcrm->paymentTypesList();
|
||||||
|
|
||||||
|
return ($response === false) ? array() : $response->paymentTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function initApi()
|
||||||
|
{
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
$this->load->model('setting/setting');
|
$this->load->model('setting/setting');
|
||||||
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
$settings = $this->model_setting_setting->getSetting($moduleTitle);
|
||||||
|
|
||||||
if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) {
|
if(!empty($settings[$moduleTitle . '_url']) && !empty($settings[$moduleTitle . '_apikey'])) {
|
||||||
$this->retailcrm = new RetailcrmProxy(
|
$this->retailcrm = new RetailcrmProxy(
|
||||||
$settings['retailcrm_url'],
|
$settings[$moduleTitle . '_url'],
|
||||||
$settings['retailcrm_apikey'],
|
$settings[$moduleTitle . '_apikey'],
|
||||||
DIR_SYSTEM . 'storage/logs/retailcrm.log'
|
DIR_SYSTEM . 'storage/logs/retailcrm.log',
|
||||||
|
$settings[$moduleTitle . '_apiversion']
|
||||||
);
|
);
|
||||||
|
|
||||||
$response = $this->retailcrm->paymentTypesList();
|
|
||||||
|
|
||||||
return ($response === false) ? array() : $response->paymentTypes;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getModuleTitle()
|
||||||
|
{
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$title = 'retailcrm';
|
||||||
|
} else {
|
||||||
|
$title = 'module_retailcrm';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,14 @@
|
|||||||
<input type="hidden" name="retailcrm_status" value="1">
|
<input type="hidden" name="retailcrm_status" value="1">
|
||||||
|
|
||||||
<h3><?php echo $retailcrm_base_settings; ?></h3>
|
<h3><?php echo $retailcrm_base_settings; ?></h3>
|
||||||
|
<div class="retailcrm_unit">
|
||||||
|
<label for="retailcrm_url"><?php echo $retailcrm_apiversion; ?></label><br>
|
||||||
|
<select name="retailcrm_apiversion">
|
||||||
|
<?php foreach($api_versions as $version) : ?>
|
||||||
|
<option value="<?php echo $version; ?>" <?php if (isset($saved_settings['retailcrm_apiversion']) && $saved_settings['retailcrm_apiversion'] == $version) echo "selected='selected'"; elseif (!isset($saved_settings['retailcrm_apiversion']) && $default_apiversion == $version) echo "selected='selected'"; ?>><?php echo $version; ?></option>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="retailcrm_unit">
|
<div class="retailcrm_unit">
|
||||||
<label for="retailcrm_url"><?php echo $retailcrm_url; ?></label><br>
|
<label for="retailcrm_url"><?php echo $retailcrm_url; ?></label><br>
|
||||||
<input id="retailcrm_url" type="text" name="retailcrm_url" value="<?php if (isset($saved_settings['retailcrm_url'])): echo $saved_settings['retailcrm_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; ?>">
|
||||||
@ -106,8 +114,8 @@
|
|||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
<label for="retailcrm_pm_<?php echo $val['code']; ?>"><?php echo $val['title']; ?></label>
|
<label for="retailcrm_pm_<?php echo $val['code']; ?>"><?php echo $val['title']; ?></label>
|
||||||
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</div>
|
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
<h4><?php echo $retailcrm_dict_status; ?></h4>
|
<h4><?php echo $retailcrm_dict_status; ?></h4>
|
||||||
|
314
admin/view/template/extension/module/retailcrm.twig
Normal file
314
admin/view/template/extension/module/retailcrm.twig
Normal file
@ -0,0 +1,314 @@
|
|||||||
|
{{ header }}{{ column_left }}
|
||||||
|
|
||||||
|
<div id="content">
|
||||||
|
<div class="page-header">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="pull-right">
|
||||||
|
{% if export_file %}
|
||||||
|
<button type="button" id="export" data-toggle="tooltip" title="{{ text_button_export }}" class="btn btn-success"><i class="fa fa-download"></i></button>
|
||||||
|
{% endif %}
|
||||||
|
<button type="button" id="icml" data-toggle="tooltip" title="{{ text_button_catalog }}" class="btn btn-success"><i class="fa fa-file-text-o"></i></button>
|
||||||
|
<button type="submit" form="form-module" data-toggle="tooltip" title="{{ button_save }}" class="btn btn-primary"><i class="fa fa-save"></i></button>
|
||||||
|
<a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}" class="btn btn-default"><i class="fa fa-reply"></i></a></div>
|
||||||
|
<h1>{{ heading_title }}</h1>
|
||||||
|
<ul class="breadcrumb">
|
||||||
|
{% for breadcrumb in breadcrumbs %}
|
||||||
|
<li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="container-fluid">
|
||||||
|
{% if error_warning %}
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||||
|
<i class="fa fa-exclamation-circle"></i> {{ error_warning }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% if saved_settings.module_retailcrm_url is defined %}
|
||||||
|
<div class="alert alert-info"><i class="fa fa-exclamation-circle"></i>
|
||||||
|
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||||
|
{{ text_notice }}
|
||||||
|
<a href="{{ saved_settings.module_retailcrm_url }}/admin/settings#t-main">{{ saved_settings.module_retailcrm_url }}/admin/settings#t-main</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-body">
|
||||||
|
<form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-module">
|
||||||
|
<ul class="nav nav-tabs">
|
||||||
|
<li class="active"><a href="#tab-general" data-toggle="tab">{{ general_tab_text }}</a></li>
|
||||||
|
{% if saved_settings.module_retailcrm_apikey is defined and saved_settings.module_retailcrm_apikey and saved_settings.module_retailcrm_url is defined and saved_settings.module_retailcrm_url %}
|
||||||
|
<li><a href="#tab-references" data-toggle="tab">{{ references_tab_text }}</a></li>
|
||||||
|
<li><a href="#tab-collector" data-toggle="tab">{{ collector_tab_text }}</a></li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="tab-content">
|
||||||
|
<div class="tab-pane active" id="tab-general">
|
||||||
|
<input type="hidden" name="module_retailcrm_status" value="1">
|
||||||
|
|
||||||
|
<h3>{{ retailcrm_base_settings }}</h3>
|
||||||
|
<div class="retailcrm_unit">
|
||||||
|
<label for="retailcrm_url">{{ retailcrm_apiversion }}</label><br>
|
||||||
|
<select name="module_retailcrm_apiversion">
|
||||||
|
{% for version in api_versions %}
|
||||||
|
<option value="{{ version }}" {% if saved_settings.module_retailcrm_apiversion is defined and saved_settings.module_retailcrm_apiversion == version %} selected="selected" {% elseif saved_settings.module_retailcrm_apiversion is not defined and default_apiversion == version %} selected="selected" {% endif %}>{{ version }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="retailcrm_unit">
|
||||||
|
<label for="retailcrm_url">{{ retailcrm_url }}</label><br>
|
||||||
|
<input id="retailcrm_url" type="text" name="module_retailcrm_url" value="{% if saved_settings.module_retailcrm_url is defined %}{{ saved_settings.module_retailcrm_url }}{% endif %}">
|
||||||
|
</div>
|
||||||
|
<div class="retailcrm_unit">
|
||||||
|
<label for="retailcrm_apikey">{{ retailcrm_apikey }}</label><br>
|
||||||
|
<input id="retailcrm_apikey" type="text" name="module_retailcrm_apikey" value="{% if saved_settings.module_retailcrm_apikey is defined %}{{ saved_settings.module_retailcrm_apikey }}{% endif %}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>{{ retailcrm_countries_settings }}</h3>
|
||||||
|
<div class="retailcrm_unit">
|
||||||
|
<div class="well well-sm" style="height: 150px; overflow: auto; width: 30%;">
|
||||||
|
{% for country in countries %}
|
||||||
|
<div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="module_retailcrm_country[]" value="{{ country.country_id }}" {% if saved_settings.module_retailcrm_country is defined and country.country_id in saved_settings.module_retailcrm_country %} {{ 'checked' }} {% endif %}">
|
||||||
|
{{ country.name }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% if saved_settings.module_retailcrm_apikey is defined and saved_settings.module_retailcrm_apikey and saved_settings.module_retailcrm_url is defined and saved_settings.module_retailcrm_url %}
|
||||||
|
|
||||||
|
{% if retailcrm_errors|length %}
|
||||||
|
{% for retailcrm_error in retailcrm_errors %}
|
||||||
|
<div class="warning">{{ retailcrm_error }}</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
<h3>{{ retailcrm_upload_order }}</h3>
|
||||||
|
<div class="retailcrm_unit">
|
||||||
|
<label>{{ text_button_export_order }} № </label><input type="text" name="order_id">
|
||||||
|
<button type="button" id="export_order" data-toggle="tooltip" title="{{ text_button_export_order }}" class="btn btn-success"><i class="fa fa-download"></i></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tab-pane" id="tab-references">
|
||||||
|
<h3>{{ retailcrm_dict_settings }}</h3>
|
||||||
|
|
||||||
|
<h4>{{ retailcrm_dict_delivery }}</h4>
|
||||||
|
{% for value in delivery.opencart %}
|
||||||
|
|
||||||
|
<div class="pm">{{ value.title ~ ':' }}</div>
|
||||||
|
|
||||||
|
{% for key, val in value %}
|
||||||
|
{% if key != 'title' %}
|
||||||
|
<div class="retailcrm_unit">
|
||||||
|
<select id="retailcrm_delivery_{{ val.code }}" name="module_retailcrm_delivery[{{ val.code }}]" >
|
||||||
|
{% for k, v in delivery.retailcrm %}
|
||||||
|
<option value="{{ v.code }}" {% if saved_settings.module_retailcrm_delivery[key] is defined and v.code == saved_settings.module_retailcrm_delivery[key] %} selected="selected" {% endif %}>
|
||||||
|
{{ v.name }}
|
||||||
|
</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<label for="retailcrm_pm_{{ val.code }}">{{ val.title }}</label>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<h4>{{ retailcrm_dict_status }}</h4>
|
||||||
|
{% for status in statuses.opencart %}
|
||||||
|
{% set uid = status.order_status_id %}
|
||||||
|
<div class="retailcrm_unit">
|
||||||
|
<select id="retailcrm_status_{{ uid }}" name="module_retailcrm_status[{{ status.order_status_id }}]" >
|
||||||
|
{% for k, v in statuses.retailcrm %}
|
||||||
|
<option value="{{ v.code }}" {% if saved_settings.module_retailcrm_status[uid] is defined and v.code == saved_settings.module_retailcrm_status[uid] %} selected="selected" {% endif %}>
|
||||||
|
{{ v.name }}
|
||||||
|
</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<label for="retailcrm_status_{{ status.order_status_id }} ">{{ status.name }}</label>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<h4>{{ retailcrm_dict_payment }}</h4>
|
||||||
|
{% for key, value in payments.opencart %}
|
||||||
|
<div class="retailcrm_unit">
|
||||||
|
<select id="retailcrm_payment_{{ key }}" name="module_retailcrm_payment[{{ key }}]" >
|
||||||
|
{% for k, v in payments.retailcrm %}
|
||||||
|
<option value="{{ v.code }}" {% if saved_settings.module_retailcrm_payment[key] is defined and v.code == saved_settings.module_retailcrm_payment[key] %} selected="selected" {% endif %}>
|
||||||
|
{{ v.name }}
|
||||||
|
</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<label for="retailcrm_payment_{{ key }}">{{ value }}</label>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tab-pane" id="tab-collector">
|
||||||
|
<h3>{{ daemon_collector }}</h3>
|
||||||
|
<div class="retailcrm_unit">
|
||||||
|
<label for="retailcrm_collector_active" class="col-md-4">{{ text_collector_activity }}</label>
|
||||||
|
<label class="radio-inline">
|
||||||
|
<input type="radio" name="module_retailcrm_collector_active" value="1" {% if saved_settings.module_retailcrm_collector_active is defined and
|
||||||
|
saved_settings.module_retailcrm_collector_active == 1 %} {{ 'checked' }}
|
||||||
|
{% endif %}>
|
||||||
|
{{ text_yes }}
|
||||||
|
</label>
|
||||||
|
<label class="radio-inline">
|
||||||
|
<input type="radio" name="module_retailcrm_collector_active" value="0" {% if not saved_settings.module_retailcrm_collector_active or
|
||||||
|
saved_settings.module_retailcrm_collector_active == 0 %} {{ 'checked' }}
|
||||||
|
{% endif %}>
|
||||||
|
{{ text_no }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="retailcrm_unit">
|
||||||
|
<label for="retailcrm_collector" class="col-md-4">{{ collector_site_key }}</label>
|
||||||
|
<input id="retailcrm_collector_site_key" type="text" name="module_retailcrm_collector[site_key]" value="{% if saved_settings.module_retailcrm_collector.site_key is defined %}{{ saved_settings.module_retailcrm_collector.site_key }}{% endif %}">
|
||||||
|
</div>
|
||||||
|
{% if saved_settings.module_retailcrm_collector.site_key is not empty and
|
||||||
|
saved_settings.module_retailcrm_collector_active == 1 %}
|
||||||
|
<div class="retailcrm_unit">
|
||||||
|
<label for="retailcrm_collector" class="col-md-4">{{ text_collector_form_capture }}</label>
|
||||||
|
<label class="radio-inline">
|
||||||
|
<input type="radio" name="module_retailcrm_collector[form_capture]" value="1" {% if saved_settings.module_retailcrm_collector.form_capture is defined and
|
||||||
|
saved_settings.module_retailcrm_collector.form_capture == 1 %} {{ 'checked' }}
|
||||||
|
{% endif %}>
|
||||||
|
{{ text_yes }}
|
||||||
|
</label>
|
||||||
|
<label class="radio-inline">
|
||||||
|
<input type="radio" name="module_retailcrm_collector[form_capture]" value="0" {% if saved_settings.module_retailcrm_collector.form_capture is not defined or
|
||||||
|
saved_settings.module_retailcrm_collector.form_capture == 0 %} {{ 'checked' }}
|
||||||
|
{% endif %}>
|
||||||
|
{{ text_no }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{% if saved_settings.module_retailcrm_collector.form_capture is defined and
|
||||||
|
saved_settings.module_retailcrm_collector.form_capture == 1 %}
|
||||||
|
<div class="retailcrm_unit">
|
||||||
|
<label for="retailcrm_collector" class="col-md-4">{{ text_collector_period }}</label>
|
||||||
|
<input id="retailcrm_collector_period" type="text" name="module_retailcrm_collector[period]" value="{% if saved_settings.module_retailcrm_collector.period is defined %}{{ saved_settings.module_retailcrm_collector.period }}{% endif %}">
|
||||||
|
</div>
|
||||||
|
<div class="retailcrm_unit">
|
||||||
|
<label for="retailcrm_collector" class="col-md-4">{{ text_label_promo }}</label>
|
||||||
|
<input id="retailcrm_collector[]" type="text" name="module_retailcrm_collector[label_promo]" value="{% if saved_settings.module_retailcrm_collector.label_promo is defined %}{{ saved_settings.module_retailcrm_collector.label_promo }}{% endif %}">
|
||||||
|
</div>
|
||||||
|
<div class="retailcrm_unit">
|
||||||
|
<label for="retailcrm_collector" class="col-md-4">{{ text_label_send }}</label>
|
||||||
|
<input id="retailcrm_collector_label_send" type="text" name="module_retailcrm_collector[label_send]" value="{% if saved_settings.module_retailcrm_collector.label_send is defined %} {{ saved_settings.module_retailcrm_collector.label_send }} {% endif %}">
|
||||||
|
</div>
|
||||||
|
<div class="retailcrm_unit">
|
||||||
|
<label for="retailcrm_collector" class="col-md-4">{{ collector_custom_text }}</label>
|
||||||
|
<label class="radio-inline">
|
||||||
|
<input type="radio" name="module_retailcrm_collector[custom_form]" value="1" {% if saved_settings.module_retailcrm_collector.custom_form is defined and
|
||||||
|
saved_settings.module_retailcrm_collector.custom_form == 1 %} {{ 'checked' }}
|
||||||
|
{% endif %}>
|
||||||
|
{{ text_yes }}
|
||||||
|
</label>
|
||||||
|
<label class="radio-inline">
|
||||||
|
<input type="radio" name="module_retailcrm_collector[custom_form]" value="0" {% if saved_settings.module_retailcrm_collector.custom_form is defined or
|
||||||
|
saved_settings.module_retailcrm_collector.custom_form == 0 %} {{ 'checked' }}
|
||||||
|
{% endif %}>
|
||||||
|
{{ text_no }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{% if saved_settings.module_retailcrm_collector.custom_form is defined and
|
||||||
|
saved_settings.module_retailcrm_collector.custom_form == 1 %}
|
||||||
|
{% for field, label in collectorFields %}
|
||||||
|
<div class="retailcrm_unit">
|
||||||
|
<label for="retailcrm_collector" class="col-md-4">{{ label }}</label>
|
||||||
|
<div class="col-md-8">
|
||||||
|
{# <input id="retailcrm_collector" type="text" name="module_retailcrm_collector[custom][{{ field }}]" value="{% if saved_settings.module_retailcrm_collector.custom.{{ field }} is defined %} {{ saved_settings.module_retailcrm_collector.custom.{{ field }} {% endif %}"> #}
|
||||||
|
<input type="checkbox" name="module_retailcrm_collector[require][{{ field }}_require]" value="1" {% if saved_settings.module_retailcrm_collector.require.field ~'_require' %} {{ 'checked' }} {% endif %}>
|
||||||
|
<label for="retailcrm_collector">{{ text_require }}</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{ footer }}
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
var token = '{{ user_token }}';
|
||||||
|
$('#icml').on('click', function() {
|
||||||
|
$.ajax({
|
||||||
|
url: '{{ catalog }}' + 'admin/index.php?route=extension/module/retailcrm/icml&user_token=' + token,
|
||||||
|
beforeSend: function() {
|
||||||
|
$('#icml').button('loading');
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
$('.alert-success').remove();
|
||||||
|
$('#content > .container-fluid').prepend('<div class="alert alert-success"><i class="fa fa-exclamation-circle"></i> {{ text_success_catalog }}</div>');
|
||||||
|
$('#icml').button('reset');
|
||||||
|
},
|
||||||
|
error: function(){
|
||||||
|
alert('error');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#export').on('click', function() {
|
||||||
|
$.ajax({
|
||||||
|
url: '{{ catalog }}' + 'admin/index.php?route=extension/module/retailcrm/export&user_token=' + token,
|
||||||
|
beforeSend: function() {
|
||||||
|
$('#export').button('loading');
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
$('.alert-success').remove();
|
||||||
|
$('#content > .container-fluid').prepend('<div class="alert alert-success"><i class="fa fa-exclamation-circle"></i> {{ text_success_export }}</div>');
|
||||||
|
$('#export').button('reset');
|
||||||
|
},
|
||||||
|
error: function(){
|
||||||
|
alert('error');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#export_order').on('click', function() {
|
||||||
|
var order_id = $('input[name=\'order_id\']').val();
|
||||||
|
if (order_id && order_id > 0) {
|
||||||
|
$.ajax({
|
||||||
|
url: '{{ catalog }}' + 'admin/index.php?route=extension/module/retailcrm/exportOrder&user_token=' + token + '&order_id=' + order_id,
|
||||||
|
beforeSend: function() {
|
||||||
|
$('#export_order').button('loading');
|
||||||
|
},
|
||||||
|
error: function(xhr, ajaxOptions, thrownError) {
|
||||||
|
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
|
||||||
|
},
|
||||||
|
success: function(data, textStatus, jqXHR) {
|
||||||
|
if (jqXHR['responseText'] == 'false') {
|
||||||
|
$('.alert-danger').remove();
|
||||||
|
$('#content > .container-fluid').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i>{{ text_error_order }}</div>');
|
||||||
|
$('#export_order').button('reset');
|
||||||
|
} else {
|
||||||
|
$('.alert-success').remove();
|
||||||
|
$('#content > .container-fluid').prepend('<div class="alert alert-success"><i class="fa fa-exclamation-circle"></i>{{ text_success_export_order }}</div>');
|
||||||
|
$('#export_order').button('reset');
|
||||||
|
$('input[name=\'order_id\']').val('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$('.alert-danger').remove();
|
||||||
|
$('#content > .container-fluid').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> {{ text_error_order_id }}</div>');
|
||||||
|
$('#export_order').button('reset');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
@ -26,11 +26,11 @@ class ControllerApiRetailcrm extends Controller
|
|||||||
|
|
||||||
protected function getDeliveryTypesByZones($country_id)
|
protected function getDeliveryTypesByZones($country_id)
|
||||||
{
|
{
|
||||||
|
$this->loadModels();
|
||||||
$this->load->model('localisation/zone');
|
$this->load->model('localisation/zone');
|
||||||
$this->load->model('localisation/country');
|
$this->load->model('localisation/country');
|
||||||
$this->load->model('extension/extension');
|
|
||||||
|
|
||||||
$shippingModules = $this->model_extension_extension->getExtensions('shipping');
|
$shippingModules = $this->{'model_' . $this->modelExtension}->getExtensions('shipping');
|
||||||
$zones = $this->model_localisation_zone->getZonesByCountryId($country_id);
|
$zones = $this->model_localisation_zone->getZonesByCountryId($country_id);
|
||||||
$country = $this->model_localisation_country->getCountry($country_id);
|
$country = $this->model_localisation_country->getCountry($country_id);
|
||||||
$quote_data = array();
|
$quote_data = array();
|
||||||
@ -48,8 +48,13 @@ class ControllerApiRetailcrm extends Controller
|
|||||||
|
|
||||||
foreach ($shippingModules as $shippingModule) {
|
foreach ($shippingModules as $shippingModule) {
|
||||||
$this->load->model('extension/shipping/' . $shippingModule['code']);
|
$this->load->model('extension/shipping/' . $shippingModule['code']);
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$shippingCode = $shippingModule['code'];
|
||||||
|
} else {
|
||||||
|
$shippingCode = 'shipping_' . $shippingModule['code'];
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->config->get($shippingModule['code'] . '_status')) {
|
if ($this->config->get($shippingCode . '_status')) {
|
||||||
if($this->{'model_extension_shipping_' . $shippingModule['code']}->getQuote($address)) {
|
if($this->{'model_extension_shipping_' . $shippingModule['code']}->getQuote($address)) {
|
||||||
$quote_data[] = $this->{'model_extension_shipping_' . $shippingModule['code']}->getQuote($address);
|
$quote_data[] = $this->{'model_extension_shipping_' . $shippingModule['code']}->getQuote($address);
|
||||||
}
|
}
|
||||||
@ -70,4 +75,28 @@ class ControllerApiRetailcrm extends Controller
|
|||||||
|
|
||||||
return $deliveryTypes;
|
return $deliveryTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function loadModels()
|
||||||
|
{
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$this->load->model('extension/extension');
|
||||||
|
|
||||||
|
$this->modelExtension = 'extension_extension';
|
||||||
|
} else {
|
||||||
|
$this->load->model('setting/extension');
|
||||||
|
|
||||||
|
$this->modelExtension = 'setting_extension';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getModuleTitle()
|
||||||
|
{
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$title = 'retailcrm';
|
||||||
|
} else {
|
||||||
|
$title = 'module_retailcrm';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
class ControllerExtensionAnalyticsDaemonCollector extends Controller {
|
class ControllerExtensionAnalyticsDaemonCollector extends Controller {
|
||||||
public function index() {
|
public function index() {
|
||||||
$this->load->model('setting/setting');
|
$this->load->model('setting/setting');
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
|
|
||||||
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
$settings = $this->model_setting_setting->getSetting($moduleTitle);
|
||||||
$setting = $settings['retailcrm_collector'];
|
$setting = $settings[$moduleTitle . '_collector'];
|
||||||
$siteCode = isset($setting['site_key']) ? $setting['site_key'] : '';
|
$siteCode = isset($setting['site_key']) ? $setting['site_key'] : '';
|
||||||
|
|
||||||
if ($this->customer->isLogged()) $customerId = $this->customer->getID();
|
if ($this->customer->isLogged()) $customerId = $this->customer->getID();
|
||||||
@ -78,4 +79,15 @@ class ControllerExtensionAnalyticsDaemonCollector extends Controller {
|
|||||||
|
|
||||||
return html_entity_decode($js, ENT_QUOTES, 'UTF-8');
|
return html_entity_decode($js, ENT_QUOTES, 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getModuleTitle()
|
||||||
|
{
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$title = 'retailcrm';
|
||||||
|
} else {
|
||||||
|
$title = 'module_retailcrm';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
*/
|
*/
|
||||||
public function order_create($parameter1, $parameter2 = null, $parameter3 = null)
|
public function order_create($parameter1, $parameter2 = null, $parameter3 = null)
|
||||||
{
|
{
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
$this->load->model('checkout/order');
|
$this->load->model('checkout/order');
|
||||||
$this->load->model('account/order');
|
$this->load->model('account/order');
|
||||||
|
|
||||||
@ -38,9 +39,9 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
|
|
||||||
if (!isset($data['fromApi'])) {
|
if (!isset($data['fromApi'])) {
|
||||||
$this->load->model('setting/setting');
|
$this->load->model('setting/setting');
|
||||||
$status = $this->model_setting_setting->getSetting('retailcrm');
|
$status = $this->model_setting_setting->getSetting($moduleTitle);
|
||||||
if ($data['order_status_id'] > 0) {
|
if ($data['order_status_id'] > 0) {
|
||||||
$data['order_status'] = $status['retailcrm_status'][$data['order_status_id']];
|
$data['order_status'] = $status[$moduleTitle . '_status'][$data['order_status_id']];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->load->model('extension/retailcrm/order');
|
$this->load->model('extension/retailcrm/order');
|
||||||
@ -56,6 +57,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function order_edit($parameter1, $parameter2 = null) {
|
public function order_edit($parameter1, $parameter2 = null) {
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
$order_id = $parameter2[0];
|
$order_id = $parameter2[0];
|
||||||
|
|
||||||
$this->load->model('checkout/order');
|
$this->load->model('checkout/order');
|
||||||
@ -77,10 +79,10 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
|
|
||||||
if (!isset($data['fromApi'])) {
|
if (!isset($data['fromApi'])) {
|
||||||
$this->load->model('setting/setting');
|
$this->load->model('setting/setting');
|
||||||
$status = $this->model_setting_setting->getSetting('retailcrm');
|
$status = $this->model_setting_setting->getSetting($moduleTitle);
|
||||||
|
|
||||||
if ($data['order_status_id'] > 0) {
|
if ($data['order_status_id'] > 0) {
|
||||||
$data['order_status'] = $status['retailcrm_status'][$data['order_status_id']];
|
$data['order_status'] = $status[$moduleTitle . '_status'][$data['order_status_id']];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->load->model('extension/retailcrm/order');
|
$this->load->model('extension/retailcrm/order');
|
||||||
@ -140,4 +142,15 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
|||||||
$this->load->model('extension/retailcrm/customer');
|
$this->load->model('extension/retailcrm/customer');
|
||||||
$this->model_extension_retailcrm_customer->changeInCrm($customer);
|
$this->model_extension_retailcrm_customer->changeInCrm($customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getModuleTitle()
|
||||||
|
{
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$title = 'retailcrm';
|
||||||
|
} else {
|
||||||
|
$title = 'module_retailcrm';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,44 +1,24 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class ModelExtensionRetailcrmCustomer extends Model {
|
class ModelExtensionRetailcrmCustomer extends Model {
|
||||||
public function sendToCrm($customer) {
|
public function sendToCrm($customer)
|
||||||
$this->load->model('setting/setting');
|
{
|
||||||
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
$this->initApi();
|
||||||
|
|
||||||
if(empty($customer))
|
if(empty($customer))
|
||||||
return false;
|
return false;
|
||||||
if(empty($settings['retailcrm_url']) || empty($settings['retailcrm_apikey']))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
|
|
||||||
|
|
||||||
$this->retailcrmApi = new RetailcrmProxy(
|
|
||||||
$settings['retailcrm_url'],
|
|
||||||
$settings['retailcrm_apikey'],
|
|
||||||
DIR_SYSTEM . 'storage/logs/retailcrm.log'
|
|
||||||
);
|
|
||||||
|
|
||||||
$customerToCrm = $this->process($customer);
|
$customerToCrm = $this->process($customer);
|
||||||
|
|
||||||
$this->retailcrmApi->customersCreate($customerToCrm);
|
$this->retailcrmApi->customersCreate($customerToCrm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function changeInCrm($customer) {
|
public function changeInCrm($customer)
|
||||||
$this->load->model('setting/setting');
|
{
|
||||||
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
$this->initApi();
|
||||||
|
|
||||||
if(empty($customer))
|
if(empty($customer))
|
||||||
return false;
|
return false;
|
||||||
if(empty($settings['retailcrm_url']) || empty($settings['retailcrm_apikey']))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
|
|
||||||
|
|
||||||
$this->retailcrmApi = new RetailcrmProxy(
|
|
||||||
$settings['retailcrm_url'],
|
|
||||||
$settings['retailcrm_apikey'],
|
|
||||||
DIR_SYSTEM . 'storage/logs/retailcrm.log'
|
|
||||||
);
|
|
||||||
|
|
||||||
$customerToCrm = $this->process($customer);
|
$customerToCrm = $this->process($customer);
|
||||||
|
|
||||||
@ -59,6 +39,46 @@ class ModelExtensionRetailcrmCustomer extends Model {
|
|||||||
'createdAt' => $customer['date_added']
|
'createdAt' => $customer['date_added']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (isset($customer['address'])) {
|
||||||
|
$customerToCrm['address'] = array(
|
||||||
|
'index' => $customer['address']['postcode'],
|
||||||
|
'countryIso' => $customer['address']['iso_code_2'],
|
||||||
|
'region' => $customer['address']['zone'],
|
||||||
|
'city' => $customer['address']['city'],
|
||||||
|
'text' => $customer['address']['address_1'] . ' ' . $customer['address']['address_2']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return $customerToCrm;
|
return $customerToCrm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function initApi()
|
||||||
|
{
|
||||||
|
$this->load->model('setting/setting');
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
|
$settings = $this->model_setting_setting->getSetting($moduleTitle);
|
||||||
|
|
||||||
|
if(empty($settings[$moduleTitle . '_url']) || empty($settings[$moduleTitle . '_apikey']))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
|
||||||
|
|
||||||
|
$this->retailcrmApi = new RetailcrmProxy(
|
||||||
|
$settings[$moduleTitle . '_url'],
|
||||||
|
$settings[$moduleTitle . '_apikey'],
|
||||||
|
DIR_SYSTEM . 'storage/logs/retailcrm.log',
|
||||||
|
$settings[$moduleTitle . '_apiversion']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getModuleTitle()
|
||||||
|
{
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$title = 'retailcrm';
|
||||||
|
} else {
|
||||||
|
$title = 'module_retailcrm';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,162 +6,32 @@ class ModelExtensionRetailcrmOrder extends Model {
|
|||||||
{
|
{
|
||||||
if(isset($this->request->post['fromApi'])) return;
|
if(isset($this->request->post['fromApi'])) return;
|
||||||
|
|
||||||
$this->load->model('setting/setting');
|
$this->initApi();
|
||||||
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
|
||||||
|
|
||||||
if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) {
|
$order = array();
|
||||||
$this->load->model('catalog/product');
|
|
||||||
|
|
||||||
require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
|
$customers = $this->retailcrm->customersList(
|
||||||
|
array(
|
||||||
|
'name' => $order_data['telephone'],
|
||||||
|
'email' => $order_data['email']
|
||||||
|
),
|
||||||
|
1,
|
||||||
|
100
|
||||||
|
);
|
||||||
|
|
||||||
$this->retailcrm = new RetailcrmProxy(
|
if($customers) {
|
||||||
$settings['retailcrm_url'],
|
foreach ($customers['customers'] as $customer) {
|
||||||
$settings['retailcrm_apikey'],
|
$order['customer']['id'] = $customer['id'];
|
||||||
DIR_SYSTEM . 'storage/logs/retailcrm.log'
|
|
||||||
);
|
|
||||||
|
|
||||||
$order = array();
|
|
||||||
|
|
||||||
$customers = $this->retailcrm->customersList(
|
|
||||||
array(
|
|
||||||
'name' => $order_data['telephone'],
|
|
||||||
'email' => $order_data['email']
|
|
||||||
),
|
|
||||||
1,
|
|
||||||
100
|
|
||||||
);
|
|
||||||
|
|
||||||
if($customers) {
|
|
||||||
foreach ($customers['customers'] as $customer) {
|
|
||||||
$order['customer']['id'] = $customer['id'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unset($customers);
|
unset($customers);
|
||||||
|
|
||||||
$order['externalId'] = $order_id;
|
$order = $this->processOrder($order_data, $order_id);
|
||||||
$order['firstName'] = $order_data['firstname'];
|
$response = $this->retailcrm->ordersCreate($order);
|
||||||
$order['lastName'] = $order_data['lastname'];
|
|
||||||
$order['phone'] = $order_data['telephone'];
|
|
||||||
$order['customerComment'] = $order_data['comment'];
|
|
||||||
|
|
||||||
if(!empty($order_data['email'])) {
|
if ($settings[$moduleTitle . '_apiversion'] == 'v5' && $response->isSuccessful()) {
|
||||||
$order['email'] = $order_data['email'];
|
$this->createPayment($order_data, $order_id);
|
||||||
}
|
|
||||||
|
|
||||||
$deliveryCost = 0;
|
|
||||||
$altTotals = isset($order_data['order_total']) ? $order_data['order_total'] : "";
|
|
||||||
$orderTotals = isset($order_data['totals']) ? $order_data['totals'] : $altTotals ;
|
|
||||||
$couponTotal = 0;
|
|
||||||
|
|
||||||
if (!empty($orderTotals)) {
|
|
||||||
foreach ($orderTotals as $totals) {
|
|
||||||
if ($totals['code'] == 'shipping') {
|
|
||||||
$deliveryCost = $totals['value'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($totals['code'] == 'coupon') {
|
|
||||||
$couponTotal = abs($totals['value']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($couponTotal)) $order['discount'] = $couponTotal;
|
|
||||||
$order['createdAt'] = $order_data['date_added'];
|
|
||||||
|
|
||||||
$payment_code = $order_data['payment_code'];
|
|
||||||
$order['paymentType'] = $settings['retailcrm_payment'][$payment_code];
|
|
||||||
|
|
||||||
if(!isset($order_data['shipping_iso_code_2']) && isset($order_data['shipping_country_id'])) {
|
|
||||||
$this->load->model('localisation/country');
|
|
||||||
$shipping_country = $this->model_localisation_country->getCountry($order_data['shipping_country_id']);
|
|
||||||
$order_data['shipping_iso_code_2'] = $shipping_country['iso_code_2'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($settings['retailcrm_delivery'][$order_data['shipping_code']])) {
|
|
||||||
$delivery_code = $order_data['shipping_code'];
|
|
||||||
} else {
|
|
||||||
$delivery_code = stristr($order_data['shipping_code'], '.', TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
$order['delivery'] = array(
|
|
||||||
'code' => !empty($delivery_code) ? $settings['retailcrm_delivery'][$delivery_code] : '',
|
|
||||||
'cost' => $deliveryCost,
|
|
||||||
'address' => array(
|
|
||||||
'index' => $order_data['shipping_postcode'],
|
|
||||||
'city' => $order_data['shipping_city'],
|
|
||||||
'countryIso' => $order_data['shipping_iso_code_2'],
|
|
||||||
'region' => $order_data['shipping_zone'],
|
|
||||||
'text' => implode(', ', array(
|
|
||||||
$order_data['shipping_postcode'],
|
|
||||||
(isset($order_data['shipping_country'])) ? $order_data['shipping_country'] : '',
|
|
||||||
$order_data['shipping_city'],
|
|
||||||
$order_data['shipping_address_1'],
|
|
||||||
$order_data['shipping_address_2']
|
|
||||||
))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$orderProducts = isset($order_data['products']) ? $order_data['products'] : $order_data['order_product'];
|
|
||||||
$offerOptions = array('select', 'radio');
|
|
||||||
|
|
||||||
foreach ($orderProducts as $product) {
|
|
||||||
$offerId = '';
|
|
||||||
|
|
||||||
if(!empty($product['option'])) {
|
|
||||||
$options = array();
|
|
||||||
|
|
||||||
$productOptions = $this->model_catalog_product->getProductOptions($product['product_id']);
|
|
||||||
|
|
||||||
foreach($product['option'] as $option) {
|
|
||||||
if ($option['type'] == 'checkbox') {
|
|
||||||
$properties[] = array(
|
|
||||||
'code' => $option['product_option_value_id'],
|
|
||||||
'name' => $option['name'],
|
|
||||||
'value' => $option['value']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!in_array($option['type'], $offerOptions)) continue;
|
|
||||||
foreach($productOptions as $productOption) {
|
|
||||||
if($productOption['product_option_id'] = $option['product_option_id']) {
|
|
||||||
foreach($productOption['product_option_value'] as $productOptionValue) {
|
|
||||||
if($productOptionValue['product_option_value_id'] == $option['product_option_value_id']) {
|
|
||||||
$options[$option['product_option_id']] = $productOptionValue['option_value_id'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ksort($options);
|
|
||||||
|
|
||||||
$offerId = array();
|
|
||||||
foreach($options as $optionKey => $optionValue) {
|
|
||||||
$offerId[] = $optionKey.'-'.$optionValue;
|
|
||||||
}
|
|
||||||
$offerId = implode('_', $offerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
$item = array(
|
|
||||||
'offer' => array(
|
|
||||||
'externalId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id']
|
|
||||||
),
|
|
||||||
'productName' => $product['name'],
|
|
||||||
'initialPrice' => $product['price'],
|
|
||||||
'quantity' => $product['quantity'],
|
|
||||||
);
|
|
||||||
|
|
||||||
if (isset($properties)) $item['properties'] = $properties;
|
|
||||||
|
|
||||||
$order['items'][] = $item;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($order_data['order_status_id']) && $order_data['order_status_id'] > 0) {
|
|
||||||
$order['status'] = $settings['retailcrm_status'][$order_data['order_status_id']];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->retailcrm->ordersCreate($order);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,121 +39,134 @@ class ModelExtensionRetailcrmOrder extends Model {
|
|||||||
{
|
{
|
||||||
if(isset($this->request->post['fromApi'])) return;
|
if(isset($this->request->post['fromApi'])) return;
|
||||||
|
|
||||||
|
$this->initApi();
|
||||||
|
|
||||||
|
$order = array();
|
||||||
|
|
||||||
|
$order = $this->processOrder($order_data, $order_id);
|
||||||
|
|
||||||
|
$response = $this->retailcrm->ordersEdit($order);
|
||||||
|
|
||||||
|
if ($settings[$moduleTitle . '_apiversion'] == 'v5' && $response->isSuccessful()) {
|
||||||
|
$this->editPayment($order_data, $order_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function processOrder($order_data, $order_id)
|
||||||
|
{
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
$this->load->model('setting/setting');
|
$this->load->model('setting/setting');
|
||||||
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
$this->load->model('catalog/product');
|
||||||
$settingPaid = $this->model_setting_setting->getSetting($order_data['payment_code']);
|
$settings = $this->model_setting_setting->getSetting($moduleTitle);
|
||||||
|
|
||||||
if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) {
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
$this->load->model('catalog/product');
|
$settingPaid = $this->model_setting_setting->getSetting($order_data['payment_code']);
|
||||||
|
} else {
|
||||||
|
$settingPaid = $this->model_setting_setting->getSetting('payment_' . $order_data['payment_code']);
|
||||||
|
}
|
||||||
|
|
||||||
require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
|
$payment_code = $order_data['payment_code'];
|
||||||
|
$order['externalId'] = $order_id;
|
||||||
|
$order['firstName'] = $order_data['firstname'];
|
||||||
|
$order['lastName'] = $order_data['lastname'];
|
||||||
|
$order['phone'] = $order_data['telephone'];
|
||||||
|
$order['customerComment'] = $order_data['comment'];
|
||||||
|
|
||||||
$this->retailcrm = new RetailcrmProxy(
|
if(!empty($order_data['email'])) {
|
||||||
$settings['retailcrm_url'],
|
$order['email'] = $order_data['email'];
|
||||||
$settings['retailcrm_apikey'],
|
}
|
||||||
DIR_SYSTEM . 'storage/logs/retailcrm.log'
|
|
||||||
);
|
|
||||||
|
|
||||||
$order = array();
|
$deliveryCost = 0;
|
||||||
|
$orderTotals = isset($order_data['totals']) ? $order_data['totals'] : $order_data['order_total'] ;
|
||||||
|
|
||||||
$payment_code = $order_data['payment_code'];
|
foreach ($orderTotals as $totals) {
|
||||||
$order['externalId'] = $order_id;
|
if ($totals['code'] == 'shipping') {
|
||||||
$order['firstName'] = $order_data['firstname'];
|
$deliveryCost = $totals['value'];
|
||||||
$order['lastName'] = $order_data['lastname'];
|
|
||||||
$order['phone'] = $order_data['telephone'];
|
|
||||||
$order['customerComment'] = $order_data['comment'];
|
|
||||||
|
|
||||||
if(!empty($order_data['email'])) {
|
|
||||||
$order['email'] = $order_data['email'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$deliveryCost = 0;
|
if ($totals['code'] == 'coupon') {
|
||||||
$orderTotals = isset($order_data['totals']) ? $order_data['totals'] : $order_data['order_total'] ;
|
$couponTotal = abs($totals['value']);
|
||||||
|
|
||||||
foreach ($orderTotals as $totals) {
|
|
||||||
if ($totals['code'] == 'shipping') {
|
|
||||||
$deliveryCost = $totals['value'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($totals['code'] == 'coupon') {
|
|
||||||
$couponTotal = abs($totals['value']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(isset($couponTotal)) $order['discount'] = $couponTotal;
|
if (isset($couponTotal)) $order['discount'] = $couponTotal;
|
||||||
$order['createdAt'] = $order_data['date_added'];
|
$order['createdAt'] = $order_data['date_added'];
|
||||||
$order['paymentType'] = $settings['retailcrm_payment'][$payment_code];
|
|
||||||
|
|
||||||
$country = (isset($order_data['shipping_country'])) ? $order_data['shipping_country'] : '' ;
|
if ($settings[$moduleTitle . '_apiversion'] != 'v5') {
|
||||||
|
$order['paymentType'] = $settings[$moduleTitle . '_payment'][$payment_code];
|
||||||
|
}
|
||||||
|
|
||||||
if(isset($settings['retailcrm_delivery'][$order_data['shipping_code']])) {
|
$country = (isset($order_data['shipping_country'])) ? $order_data['shipping_country'] : '' ;
|
||||||
$delivery_code = $order_data['shipping_code'];
|
|
||||||
} else {
|
|
||||||
$delivery_code = stristr($order_data['shipping_code'], '.', TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
$order['delivery'] = array(
|
if(isset($settings[$moduleTitle . '_delivery'][$order_data['shipping_code']])) {
|
||||||
'code' => !empty($delivery_code) ? $settings['retailcrm_delivery'][$delivery_code] : '',
|
$delivery_code = $order_data['shipping_code'];
|
||||||
'address' => array(
|
} else {
|
||||||
'index' => $order_data['shipping_postcode'],
|
$delivery_code = stristr($order_data['shipping_code'], '.', TRUE);
|
||||||
'city' => $order_data['shipping_city'],
|
}
|
||||||
'countryIso' => $order_data['shipping_iso_code_2'],
|
|
||||||
'region' => $order_data['shipping_zone'],
|
|
||||||
'text' => implode(', ', array(
|
|
||||||
$order_data['shipping_postcode'],
|
|
||||||
$country,
|
|
||||||
$order_data['shipping_city'],
|
|
||||||
$order_data['shipping_address_1'],
|
|
||||||
$order_data['shipping_address_2']
|
|
||||||
))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if(!empty($deliveryCost)){
|
$order['delivery'] = array(
|
||||||
$order['delivery']['cost'] = $deliveryCost;
|
'code' => !empty($delivery_code) ? $settings[$moduleTitle . '_delivery'][$delivery_code] : '',
|
||||||
}
|
'address' => array(
|
||||||
|
'index' => $order_data['shipping_postcode'],
|
||||||
|
'city' => $order_data['shipping_city'],
|
||||||
|
'countryIso' => $order_data['shipping_iso_code_2'],
|
||||||
|
'region' => $order_data['shipping_zone'],
|
||||||
|
'text' => implode(', ', array(
|
||||||
|
$order_data['shipping_postcode'],
|
||||||
|
$country,
|
||||||
|
$order_data['shipping_city'],
|
||||||
|
$order_data['shipping_address_1'],
|
||||||
|
$order_data['shipping_address_2']
|
||||||
|
))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$orderProducts = isset($order_data['products']) ? $order_data['products'] : $order_data['order_product'];
|
if(!empty($deliveryCost)){
|
||||||
$offerOptions = array('select', 'radio');
|
$order['delivery']['cost'] = $deliveryCost;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($orderProducts as $product) {
|
$orderProducts = isset($order_data['products']) ? $order_data['products'] : $order_data['order_product'];
|
||||||
$offerId = '';
|
$offerOptions = array('select', 'radio');
|
||||||
|
|
||||||
if (!empty($product['option'])) {
|
foreach ($orderProducts as $product) {
|
||||||
$options = array();
|
$offerId = '';
|
||||||
|
|
||||||
$productOptions = $this->model_catalog_product->getProductOptions($product['product_id']);
|
if (!empty($product['option'])) {
|
||||||
|
$options = array();
|
||||||
|
|
||||||
foreach($product['option'] as $option) {
|
$productOptions = $this->model_catalog_product->getProductOptions($product['product_id']);
|
||||||
if ($option['type'] == 'checkbox') {
|
|
||||||
$properties[] = array(
|
|
||||||
'code' => $option['product_option_value_id'],
|
|
||||||
'name' => $option['name'],
|
|
||||||
'value' => $option['value']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!in_array($option['type'], $offerOptions)) continue;
|
foreach($product['option'] as $option) {
|
||||||
foreach($productOptions as $productOption) {
|
if ($option['type'] == 'checkbox') {
|
||||||
if($productOption['product_option_id'] = $option['product_option_id']) {
|
$properties[] = array(
|
||||||
foreach($productOption['product_option_value'] as $productOptionValue) {
|
'code' => $option['product_option_value_id'],
|
||||||
if($productOptionValue['product_option_value_id'] == $option['product_option_value_id']) {
|
'name' => $option['name'],
|
||||||
$options[$option['product_option_id']] = $productOptionValue['option_value_id'];
|
'value' => $option['value']
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!in_array($option['type'], $offerOptions)) continue;
|
||||||
|
foreach($productOptions as $productOption) {
|
||||||
|
if($productOption['product_option_id'] = $option['product_option_id']) {
|
||||||
|
foreach($productOption['product_option_value'] as $productOptionValue) {
|
||||||
|
if($productOptionValue['product_option_value_id'] == $option['product_option_value_id']) {
|
||||||
|
$options[$option['product_option_id']] = $productOptionValue['option_value_id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ksort($options);
|
|
||||||
|
|
||||||
$offerId = array();
|
|
||||||
foreach($options as $optionKey => $optionValue) {
|
|
||||||
$offerId[] = $optionKey.'-'.$optionValue;
|
|
||||||
}
|
|
||||||
$offerId = implode('_', $offerId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ksort($options);
|
||||||
|
|
||||||
|
$offerId = array();
|
||||||
|
foreach($options as $optionKey => $optionValue) {
|
||||||
|
$offerId[] = $optionKey.'-'.$optionValue;
|
||||||
|
}
|
||||||
|
$offerId = implode('_', $offerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($settings[$moduleTitle . '_apiversion'] != 'v3') {
|
||||||
$item = array(
|
$item = array(
|
||||||
'offer' => array(
|
'offer' => array(
|
||||||
'externalId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id']
|
'externalId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id']
|
||||||
@ -292,21 +175,143 @@ class ModelExtensionRetailcrmOrder extends Model {
|
|||||||
'initialPrice' => $product['price'],
|
'initialPrice' => $product['price'],
|
||||||
'quantity' => $product['quantity'],
|
'quantity' => $product['quantity'],
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
if (isset($properties)) $item['properties'] = $properties;
|
$item = array(
|
||||||
|
'productName' => $product['name'],
|
||||||
$order['items'][] = $item;
|
'initialPrice' => $product['price'],
|
||||||
|
'quantity' => $product['quantity'],
|
||||||
|
'productId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($properties)) $item['properties'] = $properties;
|
||||||
|
|
||||||
|
$order['items'][] = $item;
|
||||||
|
|
||||||
if (isset($order_data['order_status_id']) && $order_data['order_status_id'] > 0) {
|
if (isset($order_data['order_status_id']) && $order_data['order_status_id'] > 0) {
|
||||||
$order['status'] = $settings['retailcrm_status'][$order_data['order_status_id']];
|
$order['status'] = $settings[$moduleTitle . '_status'][$order_data['order_status_id']];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($order_data['order_status_id'] == $settingPaid[$order_data['payment_code'] . '_order_status_id']) {
|
if ($settings[$moduleTitle . '_apiversion'] != 'v5') {
|
||||||
$order['paymentStatus'] = 'paid';
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
if ($order_data['order_status_id'] == $settingPaid[$order_data['payment_code'] . '_order_status_id']) {
|
||||||
|
$order['paymentStatus'] = 'paid';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($order_data['order_status_id'] == $settingPaid['payment_' . $order_data['payment_code'] . '_order_status_id']) {
|
||||||
|
$order['paymentStatus'] = 'paid';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->retailcrm->ordersEdit($order);
|
return $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createPayment($order, $order_id)
|
||||||
|
{
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
|
$settings = $this->model_setting_setting->getSetting($moduleTitle);
|
||||||
|
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$settingPaid = $this->model_setting_setting->getSetting($order['payment_code']);
|
||||||
|
} else {
|
||||||
|
$settingPaid = $this->model_setting_setting->getSetting('payment_' . $order['payment_code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$payment_code = $order['payment_code'];
|
||||||
|
|
||||||
|
foreach ($order['totals'] as $total) {
|
||||||
|
if ($total['code'] == 'total') $amount = $total['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$payment = array(
|
||||||
|
'externalId' => $order_id,
|
||||||
|
'type' => $settings[$moduleTitle . '_payment'][$payment_code],
|
||||||
|
'amount' => $amount
|
||||||
|
);
|
||||||
|
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
if ($order['order_status_id'] == $settingPaid[$order['payment_code'] . '_order_status_id']) {
|
||||||
|
$payment['status'] = 'paid';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($order['order_status_id'] == $settingPaid['payment_' . $order['payment_code'] . '_order_status_id']) {
|
||||||
|
$payment['status'] = 'paid';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$payment['order'] = array(
|
||||||
|
'externalId' => $order_id
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->retailcrm->ordersPaymentCreate($payment);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function editPayment($order, $order_id)
|
||||||
|
{
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
|
$settings = $this->model_setting_setting->getSetting($moduleTitle);
|
||||||
|
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$settingPaid = $this->model_setting_setting->getSetting($order['payment_code']);
|
||||||
|
} else {
|
||||||
|
$settingPaid = $this->model_setting_setting->getSetting('payment_' . $order['payment_code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$payment_code = $order['payment_code'];
|
||||||
|
|
||||||
|
foreach ($order['totals'] as $total) {
|
||||||
|
if ($total['code'] == 'total') $amount = $total['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$payment = array(
|
||||||
|
'externalId' => $order_id,
|
||||||
|
'type' => $settings[$moduleTitle . '_payment'][$payment_code],
|
||||||
|
'amount' => $amount
|
||||||
|
);
|
||||||
|
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
if ($order['order_status_id'] == $settingPaid[$order['payment_code'] . '_order_status_id']) {
|
||||||
|
$payment['status'] = 'paid';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($order['order_status_id'] == $settingPaid['payment_' . $order['payment_code'] . '_order_status_id']) {
|
||||||
|
$payment['status'] = 'paid';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->retailcrm->ordersPaymentEdit($payment);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function initApi()
|
||||||
|
{
|
||||||
|
$moduleTitle = $this->getModuleTitle();
|
||||||
|
$this->load->model('setting/setting');
|
||||||
|
$settings = $this->model_setting_setting->getSetting($moduleTitle);
|
||||||
|
|
||||||
|
if(!empty($settings[$moduleTitle . '_url']) && !empty($settings[$moduleTitle . '_apikey'])) {
|
||||||
|
|
||||||
|
require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
|
||||||
|
|
||||||
|
$this->retailcrm = new RetailcrmProxy(
|
||||||
|
$settings[$moduleTitle . '_url'],
|
||||||
|
$settings[$moduleTitle . '_apikey'],
|
||||||
|
DIR_SYSTEM . 'storage/logs/retailcrm.log',
|
||||||
|
$settings[$moduleTitle . '_apiversion']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getModuleTitle()
|
||||||
|
{
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$title = 'retailcrm';
|
||||||
|
} else {
|
||||||
|
$title = 'module_retailcrm';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,12 @@ $registry->set('load', $loader);
|
|||||||
|
|
||||||
// Config
|
// Config
|
||||||
$config = new Config();
|
$config = new Config();
|
||||||
|
|
||||||
|
if (version_compare(VERSION, '3.0', '>=')) {
|
||||||
|
$config->load('default');
|
||||||
|
$config->load('catalog');
|
||||||
|
}
|
||||||
|
|
||||||
$registry->set('config', $config);
|
$registry->set('config', $config);
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
@ -122,7 +128,13 @@ $cache = new Cache('file');
|
|||||||
$registry->set('cache', $cache);
|
$registry->set('cache', $cache);
|
||||||
|
|
||||||
$registry->set('response', $response);
|
$registry->set('response', $response);
|
||||||
$session = new Session();
|
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$session = new Session();
|
||||||
|
} else {
|
||||||
|
$session = new Session($config->get('session_engine'), $registry);
|
||||||
|
}
|
||||||
|
|
||||||
$registry->set('session', $session);
|
$registry->set('session', $session);
|
||||||
|
|
||||||
$languages = array();
|
$languages = array();
|
||||||
@ -150,8 +162,12 @@ $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));
|
||||||
|
|
||||||
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$controller = new Front($registry);
|
||||||
|
} else {
|
||||||
|
$controller = new Router($registry);
|
||||||
|
}
|
||||||
|
|
||||||
$controller = new Front($registry);
|
|
||||||
$action = new Action($cli_action);
|
$action = new Action($cli_action);
|
||||||
$controller->dispatch($action, new Action('error/not_found'));
|
$controller->dispatch($action, new Action('error/not_found'));
|
||||||
|
|
||||||
|
@ -44,7 +44,12 @@ class OpencartApiClient {
|
|||||||
$opencartStoreInfo = $this->model_setting_store->getStore($this->opencartStoreId);
|
$opencartStoreInfo = $this->model_setting_store->getStore($this->opencartStoreId);
|
||||||
|
|
||||||
if(!empty($this->apiToken)) {
|
if(!empty($this->apiToken)) {
|
||||||
$getParams['token'] = $this->apiToken;
|
if (version_compare(VERSION, '3.0', '<')) {
|
||||||
|
$getParams['token'] = $this->apiToken;
|
||||||
|
} else {
|
||||||
|
$getParams['api_token'] = $this->apiToken;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$postParams['fromApi'] = true;
|
$postParams['fromApi'] = true;
|
||||||
@ -89,10 +94,7 @@ class OpencartApiClient {
|
|||||||
$api = array();
|
$api = array();
|
||||||
foreach ($apiUsers as $apiUser) {
|
foreach ($apiUsers as $apiUser) {
|
||||||
if($apiUser['status'] == 1) {
|
if($apiUser['status'] == 1) {
|
||||||
$api = array(
|
$api = $apiUser;
|
||||||
'api_id' => $apiUser['api_id'],
|
|
||||||
'key' => $apiUser['key']
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,10 +116,14 @@ class OpencartApiClient {
|
|||||||
$this->model_user_api->addApiIp($api['api_id'], $innerIp);
|
$this->model_user_api->addApiIp($api['api_id'], $innerIp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (version_compare(VERSION, '3.0', '<')){
|
||||||
|
$apiAnswer = $this->request('login', array(), $api);
|
||||||
|
$this->apiToken = $apiAnswer['token'];
|
||||||
|
} else {
|
||||||
|
$this->apiToken = $this->session->getID();
|
||||||
|
$apiAnswer = $this->request('login', array(), $api);
|
||||||
|
}
|
||||||
|
|
||||||
$apiAnswer = $this->request('login', array(), $apiUser);
|
|
||||||
|
|
||||||
$this->apiToken = $apiAnswer['token'];
|
|
||||||
|
|
||||||
return $apiAnswer;
|
return $apiAnswer;
|
||||||
}
|
}
|
||||||
|
811
system/library/retailcrm/RetailcrmApiClient3.php
Normal file
811
system/library/retailcrm/RetailcrmApiClient3.php
Normal file
@ -0,0 +1,811 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* retailCRM API client class
|
||||||
|
*/
|
||||||
|
class RetailcrmApiClient3
|
||||||
|
{
|
||||||
|
const VERSION = 'v3';
|
||||||
|
|
||||||
|
protected $client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Site code
|
||||||
|
*/
|
||||||
|
protected $siteCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client creating
|
||||||
|
*
|
||||||
|
* @param string $url
|
||||||
|
* @param string $apiKey
|
||||||
|
* @param string $site
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function __construct($url, $apiKey, $site = null)
|
||||||
|
{
|
||||||
|
if ('/' != substr($url, strlen($url) - 1, 1)) {
|
||||||
|
$url .= '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = $url . 'api/' . self::VERSION;
|
||||||
|
|
||||||
|
$this->client = new RetailcrmHttpClient($url, array('apiKey' => $apiKey));
|
||||||
|
$this->siteCode = $site;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a order
|
||||||
|
*
|
||||||
|
* @param array $order
|
||||||
|
* @param string $site (default: null)
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function ordersCreate(array $order, $site = null)
|
||||||
|
{
|
||||||
|
if (!sizeof($order)) {
|
||||||
|
throw new InvalidArgumentException('Parameter `order` must contains a data');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest("/orders/create", RetailcrmHttpClient::METHOD_POST, $this->fillSite($site, array(
|
||||||
|
'order' => json_encode($order)
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit a order
|
||||||
|
*
|
||||||
|
* @param array $order
|
||||||
|
* @param string $by
|
||||||
|
* @param string $site (default: null)
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function ordersEdit(array $order, $by = 'externalId', $site = null)
|
||||||
|
{
|
||||||
|
if (!sizeof($order)) {
|
||||||
|
throw new InvalidArgumentException('Parameter `order` must contains a data');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->checkIdParameter($by);
|
||||||
|
|
||||||
|
if (!isset($order[$by])) {
|
||||||
|
throw new InvalidArgumentException(sprintf('Order array must contain the "%s" parameter.', $by));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
"/orders/" . $order[$by] . "/edit",
|
||||||
|
RetailcrmHttpClient::METHOD_POST,
|
||||||
|
$this->fillSite($site, array(
|
||||||
|
'order' => json_encode($order),
|
||||||
|
'by' => $by,
|
||||||
|
))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload array of the orders
|
||||||
|
*
|
||||||
|
* @param array $orders
|
||||||
|
* @param string $site (default: null)
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function ordersUpload(array $orders, $site = null)
|
||||||
|
{
|
||||||
|
if (!sizeof($orders)) {
|
||||||
|
throw new InvalidArgumentException('Parameter `orders` must contains array of the orders');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest("/orders/upload", RetailcrmHttpClient::METHOD_POST, $this->fillSite($site, array(
|
||||||
|
'orders' => json_encode($orders),
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get order by id or externalId
|
||||||
|
*
|
||||||
|
* @param string $id
|
||||||
|
* @param string $by (default: 'externalId')
|
||||||
|
* @param string $site (default: null)
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function ordersGet($id, $by = 'externalId', $site = null)
|
||||||
|
{
|
||||||
|
$this->checkIdParameter($by);
|
||||||
|
|
||||||
|
return $this->client->makeRequest("/orders/$id", RetailcrmHttpClient::METHOD_GET, $this->fillSite($site, array(
|
||||||
|
'by' => $by
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a orders history
|
||||||
|
*
|
||||||
|
* @param DateTime $startDate (default: null)
|
||||||
|
* @param DateTime $endDate (default: null)
|
||||||
|
* @param int $limit (default: 100)
|
||||||
|
* @param int $offset (default: 0)
|
||||||
|
* @param bool $skipMyChanges (default: true)
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function ordersHistory(
|
||||||
|
DateTime $startDate = null,
|
||||||
|
DateTime $endDate = null,
|
||||||
|
$limit = 100,
|
||||||
|
$offset = 0,
|
||||||
|
$skipMyChanges = true
|
||||||
|
) {
|
||||||
|
$parameters = array();
|
||||||
|
|
||||||
|
if ($startDate) {
|
||||||
|
$parameters['startDate'] = $startDate->format('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
if ($endDate) {
|
||||||
|
$parameters['endDate'] = $endDate->format('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
if ($limit) {
|
||||||
|
$parameters['limit'] = (int) $limit;
|
||||||
|
}
|
||||||
|
if ($offset) {
|
||||||
|
$parameters['offset'] = (int) $offset;
|
||||||
|
}
|
||||||
|
if ($skipMyChanges) {
|
||||||
|
$parameters['skipMyChanges'] = (bool) $skipMyChanges;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest('/orders/history', RetailcrmHttpClient::METHOD_GET, $parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns filtered orders list
|
||||||
|
*
|
||||||
|
* @param array $filter (default: array())
|
||||||
|
* @param int $page (default: null)
|
||||||
|
* @param int $limit (default: null)
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function ordersList(array $filter = array(), $page = null, $limit = null)
|
||||||
|
{
|
||||||
|
$parameters = array();
|
||||||
|
|
||||||
|
if (sizeof($filter)) {
|
||||||
|
$parameters['filter'] = $filter;
|
||||||
|
}
|
||||||
|
if (null !== $page) {
|
||||||
|
$parameters['page'] = (int) $page;
|
||||||
|
}
|
||||||
|
if (null !== $limit) {
|
||||||
|
$parameters['limit'] = (int) $limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest('/orders', RetailcrmHttpClient::METHOD_GET, $parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns statuses of the orders
|
||||||
|
*
|
||||||
|
* @param array $ids (default: array())
|
||||||
|
* @param array $externalIds (default: array())
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function ordersStatuses(array $ids = array(), array $externalIds = array())
|
||||||
|
{
|
||||||
|
$parameters = array();
|
||||||
|
|
||||||
|
if (sizeof($ids)) {
|
||||||
|
$parameters['ids'] = $ids;
|
||||||
|
}
|
||||||
|
if (sizeof($externalIds)) {
|
||||||
|
$parameters['externalIds'] = $externalIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest('/orders/statuses', RetailcrmHttpClient::METHOD_GET, $parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save order IDs' (id and externalId) association in the CRM
|
||||||
|
*
|
||||||
|
* @param array $ids
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function ordersFixExternalIds(array $ids)
|
||||||
|
{
|
||||||
|
if (!sizeof($ids)) {
|
||||||
|
throw new InvalidArgumentException('Method parameter must contains at least one IDs pair');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest("/orders/fix-external-ids", RetailcrmHttpClient::METHOD_POST, array(
|
||||||
|
'orders' => json_encode($ids),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get orders assembly history
|
||||||
|
*
|
||||||
|
* @param array $filter (default: array())
|
||||||
|
* @param int $page (default: null)
|
||||||
|
* @param int $limit (default: null)
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function ordersPacksHistory(array $filter = array(), $page = null, $limit = null)
|
||||||
|
{
|
||||||
|
$parameters = array();
|
||||||
|
|
||||||
|
if (sizeof($filter)) {
|
||||||
|
$parameters['filter'] = $filter;
|
||||||
|
}
|
||||||
|
if (null !== $page) {
|
||||||
|
$parameters['page'] = (int) $page;
|
||||||
|
}
|
||||||
|
if (null !== $limit) {
|
||||||
|
$parameters['limit'] = (int) $limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest('/orders/packs/history', RetailcrmHttpClient::METHOD_GET, $parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a customer
|
||||||
|
*
|
||||||
|
* @param array $customer
|
||||||
|
* @param string $site (default: null)
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function customersCreate(array $customer, $site = null)
|
||||||
|
{
|
||||||
|
if (!sizeof($customer)) {
|
||||||
|
throw new InvalidArgumentException('Parameter `customer` must contains a data');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest("/customers/create", RetailcrmHttpClient::METHOD_POST, $this->fillSite($site, array(
|
||||||
|
'customer' => json_encode($customer)
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit a customer
|
||||||
|
*
|
||||||
|
* @param array $customer
|
||||||
|
* @param string $by (default: 'externalId')
|
||||||
|
* @param string $site (default: null)
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function customersEdit(array $customer, $by = 'externalId', $site = null)
|
||||||
|
{
|
||||||
|
if (!sizeof($customer)) {
|
||||||
|
throw new InvalidArgumentException('Parameter `customer` must contains a data');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->checkIdParameter($by);
|
||||||
|
|
||||||
|
if (!isset($customer[$by])) {
|
||||||
|
throw new InvalidArgumentException(sprintf('Customer array must contain the "%s" parameter.', $by));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
"/customers/" . $customer[$by] . "/edit",
|
||||||
|
RetailcrmHttpClient::METHOD_POST,
|
||||||
|
$this->fillSite(
|
||||||
|
$site,
|
||||||
|
array(
|
||||||
|
'customer' => json_encode($customer),
|
||||||
|
'by' => $by
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload array of the customers
|
||||||
|
*
|
||||||
|
* @param array $customers
|
||||||
|
* @param string $site (default: null)
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function customersUpload(array $customers, $site = null)
|
||||||
|
{
|
||||||
|
if (!sizeof($customers)) {
|
||||||
|
throw new InvalidArgumentException('Parameter `customers` must contains array of the customers');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest("/customers/upload", RetailcrmHttpClient::METHOD_POST, $this->fillSite($site, array(
|
||||||
|
'customers' => json_encode($customers),
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get customer by id or externalId
|
||||||
|
*
|
||||||
|
* @param string $id
|
||||||
|
* @param string $by (default: 'externalId')
|
||||||
|
* @param string $site (default: null)
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function customersGet($id, $by = 'externalId', $site = null)
|
||||||
|
{
|
||||||
|
$this->checkIdParameter($by);
|
||||||
|
|
||||||
|
return $this->client->makeRequest("/customers/$id", RetailcrmHttpClient::METHOD_GET, $this->fillSite($site, array(
|
||||||
|
'by' => $by
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns filtered customers list
|
||||||
|
*
|
||||||
|
* @param array $filter (default: array())
|
||||||
|
* @param int $page (default: null)
|
||||||
|
* @param int $limit (default: null)
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function customersList(array $filter = array(), $page = null, $limit = null)
|
||||||
|
{
|
||||||
|
$parameters = array();
|
||||||
|
|
||||||
|
if (sizeof($filter)) {
|
||||||
|
$parameters['filter'] = $filter;
|
||||||
|
}
|
||||||
|
if (null !== $page) {
|
||||||
|
$parameters['page'] = (int) $page;
|
||||||
|
}
|
||||||
|
if (null !== $limit) {
|
||||||
|
$parameters['limit'] = (int) $limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest('/customers', RetailcrmHttpClient::METHOD_GET, $parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save customer IDs' (id and externalId) association in the CRM
|
||||||
|
*
|
||||||
|
* @param array $ids
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function customersFixExternalIds(array $ids)
|
||||||
|
{
|
||||||
|
if (!sizeof($ids)) {
|
||||||
|
throw new InvalidArgumentException('Method parameter must contains at least one IDs pair');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest("/customers/fix-external-ids", RetailcrmHttpClient::METHOD_POST, array(
|
||||||
|
'customers' => json_encode($ids),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get purchace prices & stock balance
|
||||||
|
*
|
||||||
|
* @param array $filter (default: array())
|
||||||
|
* @param int $page (default: null)
|
||||||
|
* @param int $limit (default: null)
|
||||||
|
* @param string $site (default: null)
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function storeInventories(array $filter = array(), $page = null, $limit = null, $site = null)
|
||||||
|
{
|
||||||
|
$parameters = array();
|
||||||
|
|
||||||
|
if (sizeof($filter)) {
|
||||||
|
$parameters['filter'] = $filter;
|
||||||
|
}
|
||||||
|
if (null !== $page) {
|
||||||
|
$parameters['page'] = (int) $page;
|
||||||
|
}
|
||||||
|
if (null !== $limit) {
|
||||||
|
$parameters['limit'] = (int) $limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest('/store/inventories', RetailcrmHttpClient::METHOD_GET, $this->fillSite($site, $parameters));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload store inventories
|
||||||
|
*
|
||||||
|
* @param array $offers
|
||||||
|
* @param string $site (default: null)
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function storeInventoriesUpload(array $offers, $site = null)
|
||||||
|
{
|
||||||
|
if (!sizeof($offers)) {
|
||||||
|
throw new InvalidArgumentException('Parameter `offers` must contains array of the customers');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
"/store/inventories/upload",
|
||||||
|
RetailcrmHttpClient::METHOD_POST,
|
||||||
|
$this->fillSite($site, array('offers' => json_encode($offers)))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns deliveryServices list
|
||||||
|
*
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function deliveryServicesList()
|
||||||
|
{
|
||||||
|
return $this->client->makeRequest('/reference/delivery-services', RetailcrmHttpClient::METHOD_GET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns deliveryTypes list
|
||||||
|
*
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function deliveryTypesList()
|
||||||
|
{
|
||||||
|
return $this->client->makeRequest('/reference/delivery-types', RetailcrmHttpClient::METHOD_GET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns orderMethods list
|
||||||
|
*
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function orderMethodsList()
|
||||||
|
{
|
||||||
|
return $this->client->makeRequest('/reference/order-methods', RetailcrmHttpClient::METHOD_GET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns orderTypes list
|
||||||
|
*
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function orderTypesList()
|
||||||
|
{
|
||||||
|
return $this->client->makeRequest('/reference/order-types', RetailcrmHttpClient::METHOD_GET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns paymentStatuses list
|
||||||
|
*
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function paymentStatusesList()
|
||||||
|
{
|
||||||
|
return $this->client->makeRequest('/reference/payment-statuses', RetailcrmHttpClient::METHOD_GET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns paymentTypes list
|
||||||
|
*
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function paymentTypesList()
|
||||||
|
{
|
||||||
|
return $this->client->makeRequest('/reference/payment-types', RetailcrmHttpClient::METHOD_GET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns productStatuses list
|
||||||
|
*
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function productStatusesList()
|
||||||
|
{
|
||||||
|
return $this->client->makeRequest('/reference/product-statuses', RetailcrmHttpClient::METHOD_GET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns statusGroups list
|
||||||
|
*
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function statusGroupsList()
|
||||||
|
{
|
||||||
|
return $this->client->makeRequest('/reference/status-groups', RetailcrmHttpClient::METHOD_GET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns statuses list
|
||||||
|
*
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function statusesList()
|
||||||
|
{
|
||||||
|
return $this->client->makeRequest('/reference/statuses', RetailcrmHttpClient::METHOD_GET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns sites list
|
||||||
|
*
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function sitesList()
|
||||||
|
{
|
||||||
|
return $this->client->makeRequest('/reference/sites', RetailcrmHttpClient::METHOD_GET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns stores list
|
||||||
|
*
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function storesList()
|
||||||
|
{
|
||||||
|
return $this->client->makeRequest('/reference/stores', RetailcrmHttpClient::METHOD_GET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit deliveryService
|
||||||
|
*
|
||||||
|
* @param array $data delivery service data
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function deliveryServicesEdit(array $data)
|
||||||
|
{
|
||||||
|
if (!isset($data['code'])) {
|
||||||
|
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
'/reference/delivery-services/' . $data['code'] . '/edit',
|
||||||
|
RetailcrmHttpClient::METHOD_POST,
|
||||||
|
array(
|
||||||
|
'deliveryService' => json_encode($data)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit deliveryType
|
||||||
|
*
|
||||||
|
* @param array $data delivery type data
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function deliveryTypesEdit(array $data)
|
||||||
|
{
|
||||||
|
if (!isset($data['code'])) {
|
||||||
|
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
'/reference/delivery-types/' . $data['code'] . '/edit',
|
||||||
|
RetailcrmHttpClient::METHOD_POST,
|
||||||
|
array(
|
||||||
|
'deliveryType' => json_encode($data)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit orderMethod
|
||||||
|
*
|
||||||
|
* @param array $data order method data
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function orderMethodsEdit(array $data)
|
||||||
|
{
|
||||||
|
if (!isset($data['code'])) {
|
||||||
|
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
'/reference/order-methods/' . $data['code'] . '/edit',
|
||||||
|
RetailcrmHttpClient::METHOD_POST,
|
||||||
|
array(
|
||||||
|
'orderMethod' => json_encode($data)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit orderType
|
||||||
|
*
|
||||||
|
* @param array $data order type data
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function orderTypesEdit(array $data)
|
||||||
|
{
|
||||||
|
if (!isset($data['code'])) {
|
||||||
|
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
'/reference/order-types/' . $data['code'] . '/edit',
|
||||||
|
RetailcrmHttpClient::METHOD_POST,
|
||||||
|
array(
|
||||||
|
'orderType' => json_encode($data)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit paymentStatus
|
||||||
|
*
|
||||||
|
* @param array $data payment status data
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function paymentStatusesEdit(array $data)
|
||||||
|
{
|
||||||
|
if (!isset($data['code'])) {
|
||||||
|
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
'/reference/payment-statuses/' . $data['code'] . '/edit',
|
||||||
|
RetailcrmHttpClient::METHOD_POST,
|
||||||
|
array(
|
||||||
|
'paymentStatus' => json_encode($data)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit paymentType
|
||||||
|
*
|
||||||
|
* @param array $data payment type data
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function paymentTypesEdit(array $data)
|
||||||
|
{
|
||||||
|
if (!isset($data['code'])) {
|
||||||
|
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
'/reference/payment-types/' . $data['code'] . '/edit',
|
||||||
|
RetailcrmHttpClient::METHOD_POST,
|
||||||
|
array(
|
||||||
|
'paymentType' => json_encode($data)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit productStatus
|
||||||
|
*
|
||||||
|
* @param array $data product status data
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function productStatusesEdit(array $data)
|
||||||
|
{
|
||||||
|
if (!isset($data['code'])) {
|
||||||
|
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
'/reference/product-statuses/' . $data['code'] . '/edit',
|
||||||
|
RetailcrmHttpClient::METHOD_POST,
|
||||||
|
array(
|
||||||
|
'productStatus' => json_encode($data)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit order status
|
||||||
|
*
|
||||||
|
* @param array $data status data
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function statusesEdit(array $data)
|
||||||
|
{
|
||||||
|
if (!isset($data['code'])) {
|
||||||
|
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
'/reference/statuses/' . $data['code'] . '/edit',
|
||||||
|
RetailcrmHttpClient::METHOD_POST,
|
||||||
|
array(
|
||||||
|
'status' => json_encode($data)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit site
|
||||||
|
*
|
||||||
|
* @param array $data site data
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function sitesEdit(array $data)
|
||||||
|
{
|
||||||
|
if (!isset($data['code'])) {
|
||||||
|
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
'/reference/sites/' . $data['code'] . '/edit',
|
||||||
|
RetailcrmHttpClient::METHOD_POST,
|
||||||
|
array(
|
||||||
|
'site' => json_encode($data)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit store
|
||||||
|
*
|
||||||
|
* @param array $data site data
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function storesEdit(array $data)
|
||||||
|
{
|
||||||
|
if (!isset($data['code'])) {
|
||||||
|
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($data['name'])) {
|
||||||
|
throw new InvalidArgumentException('Data must contain "name" parameter.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
'/reference/stores/' . $data['code'] . '/edit',
|
||||||
|
RetailcrmHttpClient::METHOD_POST,
|
||||||
|
array(
|
||||||
|
'store' => json_encode($data)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update CRM basic statistic
|
||||||
|
*
|
||||||
|
* @return RetailcrmApiResponse
|
||||||
|
*/
|
||||||
|
public function statisticUpdate()
|
||||||
|
{
|
||||||
|
return $this->client->makeRequest('/statistic/update', RetailcrmHttpClient::METHOD_GET);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return current site
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getSite()
|
||||||
|
{
|
||||||
|
return $this->siteCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set site
|
||||||
|
*
|
||||||
|
* @param string $site
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setSite($site)
|
||||||
|
{
|
||||||
|
$this->siteCode = $site;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check ID parameter
|
||||||
|
*
|
||||||
|
* @param string $by
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function checkIdParameter($by)
|
||||||
|
{
|
||||||
|
$allowedForBy = array('externalId', 'id');
|
||||||
|
if (!in_array($by, $allowedForBy)) {
|
||||||
|
throw new InvalidArgumentException(sprintf(
|
||||||
|
'Value "%s" for parameter "by" is not valid. Allowed values are %s.',
|
||||||
|
$by,
|
||||||
|
implode(', ', $allowedForBy)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill params by site value
|
||||||
|
*
|
||||||
|
* @param string $site
|
||||||
|
* @param array $params
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function fillSite($site, array $params)
|
||||||
|
{
|
||||||
|
if ($site) {
|
||||||
|
$params['site'] = $site;
|
||||||
|
} elseif ($this->siteCode) {
|
||||||
|
$params['site'] = $this->siteCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $params;
|
||||||
|
}
|
||||||
|
}
|
1723
system/library/retailcrm/RetailcrmApiClient4.php
Normal file
1723
system/library/retailcrm/RetailcrmApiClient4.php
Normal file
File diff suppressed because it is too large
Load Diff
2098
system/library/retailcrm/RetailcrmApiClient5.php
Normal file
2098
system/library/retailcrm/RetailcrmApiClient5.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -10,17 +10,31 @@ class RetailcrmProxy
|
|||||||
private $api;
|
private $api;
|
||||||
private $log;
|
private $log;
|
||||||
|
|
||||||
public function __construct($url, $key, $log)
|
public function __construct($url, $key, $log, $version = 'v4')
|
||||||
{
|
{
|
||||||
$this->api = new RetailcrmApiClient($url, $key);
|
switch ($version) {
|
||||||
|
case 'v5':
|
||||||
|
$this->api = new RetailcrmApiClient5($url, $key);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'v4':
|
||||||
|
$this->api = new RetailcrmApiClient4($url, $key);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'v3':
|
||||||
|
$this->api = new RetailcrmApiClient3($url, $key);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
$this->log = $log;
|
$this->log = $log;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __call($method, $arguments)
|
public function __call($method, $arguments)
|
||||||
{
|
{
|
||||||
|
$date = date('[Y-m-d H:i:s]');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = call_user_func_array(array($this->api, $method), $arguments);
|
$response = call_user_func_array(array($this->api, $method), $arguments);
|
||||||
$date = date('[Y-m-d H:i:s]');
|
|
||||||
|
|
||||||
if (!$response->isSuccessful()) {
|
if (!$response->isSuccessful()) {
|
||||||
error_log($date . " [$method] " . $response->getErrorMsg() . "\n", 3, $this->log);
|
error_log($date . " [$method] " . $response->getErrorMsg() . "\n", 3, $this->log);
|
||||||
|
Loading…
Reference in New Issue
Block a user