mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-22 05:06:07 +03:00
commit
dbb353be03
@ -3,8 +3,8 @@ language: php
|
||||
sudo: false
|
||||
|
||||
php:
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
|
||||
env:
|
||||
global:
|
||||
@ -39,4 +39,4 @@ deploy:
|
||||
on:
|
||||
php: 7.1
|
||||
branch: master
|
||||
condition: "$DEPLOY = true"
|
||||
condition: "$DEPLOY = false"
|
11
RoboFile.php
11
RoboFile.php
@ -73,9 +73,12 @@ class RoboFile extends \Robo\Tasks
|
||||
$this->taskDeleteDir('www')->run();
|
||||
$this->taskFileSystemStack()
|
||||
->mirror('vendor/opencart/opencart/upload', 'www')
|
||||
->copy('vendor/beyondit/opencart-test-suite/src/upload/system/config/test-config.php','www/system/config/test-config.php')
|
||||
->copy('vendor/beyondit/opencart-test-suite/src/upload/catalog/controller/startup/test_startup.php','www/catalog/controller/startup/test_startup.php')
|
||||
->copy('tests/test-config.php', 'www/system/config/test-config.php')
|
||||
->copy('vendor/beyondit/opencart-test-suite/src/upload/system/library/session/test.php', 'www/system/library/session/test.php')
|
||||
->copy('vendor/beyondit/opencart-test-suite/src/upload/admin/controller/startup/test_startup.php','www/admin/controller/startup/test_startup.php')
|
||||
->chmod('www', 0777, 0000, true)
|
||||
->rename('www/config-dist.php', 'www/config.php')
|
||||
->rename('www/admin/config-dist.php', 'www/admin/config.php')
|
||||
->run();
|
||||
|
||||
// Create new database, drop if exists already
|
||||
@ -97,7 +100,9 @@ class RoboFile extends \Robo\Tasks
|
||||
$install->run();
|
||||
$this->taskDeleteDir('www/install')->run();
|
||||
|
||||
$this->restoreSampleData($conn);
|
||||
if (isset($conn)) {
|
||||
$this->restoreSampleData($conn);
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
}
|
||||
|
@ -9,11 +9,12 @@
|
||||
"email": "integration@retailcrm.ru"
|
||||
}
|
||||
],
|
||||
"version": "3.1.0-alpha1",
|
||||
"require-dev": {
|
||||
"opencart/opencart" : "2.3.0.2",
|
||||
"opencart/opencart" : "3.1.0.0_a1",
|
||||
"vlucas/phpdotenv": "~1.1.0",
|
||||
"phpunit/phpunit" : "~4.0",
|
||||
"beyondit/opencart-test-suite": "~2.3.0",
|
||||
"phpunit/phpunit" : "^6",
|
||||
"beyondit/opencart-test-suite": "~3.0",
|
||||
"consolidation/robo": "~1",
|
||||
"henrikbjorn/lurker": "^1.2"
|
||||
},
|
||||
@ -25,9 +26,11 @@
|
||||
"opencart-dir" : "www"
|
||||
},
|
||||
"scripts" : {
|
||||
"test-library": "bin/phpunit --testsuite library-tests --colors=always",
|
||||
"test-admin": "bin/phpunit --testsuite admin-tests --colors=always",
|
||||
"test-catalog": "bin/phpunit --testsuite catalog-tests --colors=always",
|
||||
"test": [
|
||||
"@test-library",
|
||||
"@test-admin",
|
||||
"@test-catalog"
|
||||
],
|
||||
|
1215
composer.lock
generated
1215
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,7 @@
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
processIsolation="true"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false">
|
||||
<testsuites>
|
||||
@ -16,8 +16,13 @@
|
||||
<testsuite name="admin-tests">
|
||||
<directory suffix="AdminTest.php">./tests/admin/</directory>
|
||||
</testsuite>
|
||||
<testsuite name="library-tests">
|
||||
<directory suffix="LibraryTest.php">./tests/library/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<php>
|
||||
<env name="OC_ROOT" value="./www/" />
|
||||
<env name="HTTP_SERVER" value="http://localhost:8000/" />
|
||||
<env name="TEST_CONFIG" value="test-config" />
|
||||
</php>
|
||||
</phpunit>
|
7
src/upload/admin/controller/cron/icml.php
Normal file
7
src/upload/admin/controller/cron/icml.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
class ControllerCronIcml extends Controller {
|
||||
public function index($cron_id, $code, $cycle, $date_added, $date_modified) {
|
||||
$this->load->controller('extension/module/retailcrm/icml');
|
||||
}
|
||||
}
|
@ -9,19 +9,7 @@
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
|
||||
*/
|
||||
class ControllerExtensionModuleRetailcrm extends Controller
|
||||
{
|
||||
private $_error = array();
|
||||
protected $log, $statuses, $payments, $deliveryTypes, $retailcrmApiClient, $moduleTitle, $tokenTitle;
|
||||
public $children, $template;
|
||||
|
||||
public function __construct($registry)
|
||||
{
|
||||
parent::__construct($registry);
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
$this->moduleTitle = $this->retailcrm->getModuleTitle();
|
||||
$this->tokenTitle = $this->retailcrm->getTokenTitle();
|
||||
}
|
||||
class ControllerExtensionModuleRetailcrm extends Controller {
|
||||
|
||||
/**
|
||||
* Install method
|
||||
@ -33,13 +21,14 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$this->model_setting_setting->editSetting(
|
||||
$this->moduleTitle,
|
||||
\Retailcrm\Retailcrm::MODULE,
|
||||
array(
|
||||
$this->moduleTitle . '_status' => 1,
|
||||
$this->moduleTitle . '_country' => array($this->config->get('config_country_id'))
|
||||
\Retailcrm\Retailcrm::MODULE . '_status' => 1,
|
||||
\Retailcrm\Retailcrm::MODULE . '_country' => array($this->config->get('config_country_id'))
|
||||
)
|
||||
);
|
||||
|
||||
$this->addCronJobs();
|
||||
$this->addEvents();
|
||||
}
|
||||
|
||||
@ -53,10 +42,11 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
$this->uninstall_collector();
|
||||
$this->load->model('setting/setting');
|
||||
$this->model_setting_setting->editSetting(
|
||||
$this->moduleTitle,
|
||||
array($this->moduleTitle . '_status' => 0)
|
||||
\Retailcrm\Retailcrm::MODULE,
|
||||
array(\Retailcrm\Retailcrm::MODULE . '_status' => 0)
|
||||
);
|
||||
$this->model_setting_setting->deleteSetting('retailcrm_history');
|
||||
$this->deleteCronJobs();
|
||||
$this->deleteEvents();
|
||||
}
|
||||
|
||||
@ -66,12 +56,14 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
* @return void
|
||||
*/
|
||||
public function install_collector()
|
||||
{
|
||||
$collector = $this->getCollectorTitle();
|
||||
$this->loadModels();
|
||||
{
|
||||
$this->load->model('setting/setting');
|
||||
$this->{'model_' . $this->modelExtension}->install('analytics', 'daemon_collector');
|
||||
$this->model_setting_setting->editSetting($collector, array($collector . '_status' => 1));
|
||||
$this->load->model('setting/extension');
|
||||
$this->model_setting_extension->install('analytics', 'daemon_collector');
|
||||
$this->model_setting_setting->editSetting(
|
||||
'analytics_daemon_collector',
|
||||
array('analytics_daemon_collector_status' => 1)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,12 +72,14 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall_collector()
|
||||
{
|
||||
$collector = $this->getCollectorTitle();
|
||||
$this->loadModels();
|
||||
{
|
||||
$this->load->model('setting/setting');
|
||||
$this->model_setting_setting->editSetting($collector, array($collector . '_status' => 0));
|
||||
$this->{'model_' . $this->modelExtension}->uninstall('analytics', 'daemon_collector');
|
||||
$this->load->model('setting/extension');
|
||||
$this->model_setting_setting->editSetting(
|
||||
'analytics_daemon_collector',
|
||||
array('analytics_daemon_collector_status' => 0)
|
||||
);
|
||||
$this->model_setting_extension->uninstall('analytics', 'daemon_collector');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,7 +89,9 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->loadModels();
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
$this->load->model('setting/extension');
|
||||
$this->load->model('setting/event');
|
||||
$this->load->model('localisation/country');
|
||||
$this->load->model('setting/setting');
|
||||
$this->load->model('extension/retailcrm/references');
|
||||
@ -103,8 +99,9 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
$this->document->addStyle('/admin/view/stylesheet/retailcrm.css');
|
||||
|
||||
$collector = $this->getCollectorTitle();
|
||||
$history_setting = $this->model_setting_setting->getSetting('retailcrm_history');
|
||||
$retailcrm_api_client = $this->retailcrm->getApiClient();
|
||||
$opencart_api_client = $this->retailcrm->getOcApiClient($this->registry);
|
||||
|
||||
if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
|
||||
if ($this->checkEvents() === false) {
|
||||
@ -112,81 +109,49 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
$this->addEvents();
|
||||
}
|
||||
|
||||
$analytics = $this->{'model_' . $this->modelExtension}->getInstalled('analytics');
|
||||
$analytics = $this->model_setting_extension->getInstalled('analytics');
|
||||
|
||||
if ($this->request->post[$this->moduleTitle . '_collector_active'] == 1
|
||||
&& !in_array($collector, $analytics)
|
||||
if ($this->request->post[\Retailcrm\Retailcrm::MODULE . '_collector_active'] == 1
|
||||
&& !in_array('analytics_daemon_collector', $analytics)
|
||||
) {
|
||||
$this->install_collector();
|
||||
} elseif ($this->request->post[$this->moduleTitle . '_collector_active'] == 0
|
||||
&& in_array($collector, $analytics)
|
||||
} elseif ($this->request->post[\Retailcrm\Retailcrm::MODULE . '_collector_active'] == 0
|
||||
&& in_array('analytics_daemon_collector', $analytics)
|
||||
) {
|
||||
$this->uninstall_collector();
|
||||
}
|
||||
|
||||
if (parse_url($this->request->post[$this->moduleTitle . '_url'])) {
|
||||
$crm_url = parse_url($this->request->post[$this->moduleTitle . '_url'], PHP_URL_HOST);
|
||||
$this->request->post[$this->moduleTitle . '_url'] = 'https://' . $crm_url;
|
||||
if (parse_url($this->request->post[\Retailcrm\Retailcrm::MODULE . '_url'])) {
|
||||
$crm_url = parse_url($this->request->post[\Retailcrm\Retailcrm::MODULE . '_url'], PHP_URL_HOST);
|
||||
$this->request->post[\Retailcrm\Retailcrm::MODULE . '_url'] = 'https://' . $crm_url;
|
||||
}
|
||||
|
||||
if (isset($this->request->post[$this->moduleTitle . '_custom_field_active'])
|
||||
&& $this->request->post[$this->moduleTitle . '_custom_field_active'] == 0
|
||||
if (isset($this->request->post[\Retailcrm\Retailcrm::MODULE . '_custom_field_active'])
|
||||
&& $this->request->post[\Retailcrm\Retailcrm::MODULE . '_custom_field_active'] == 0
|
||||
) {
|
||||
unset($this->request->post[$this->moduleTitle . '_custom_field']);
|
||||
unset($this->request->post[\Retailcrm\Retailcrm::MODULE . '_custom_field']);
|
||||
}
|
||||
|
||||
$this->model_setting_setting->editSetting(
|
||||
$this->moduleTitle,
|
||||
\Retailcrm\Retailcrm::MODULE,
|
||||
$this->request->post
|
||||
);
|
||||
|
||||
if ($this->request->post[$this->moduleTitle . '_apiversion'] != 'v3') {
|
||||
if (!isset($history_setting['retailcrm_history_orders']) && !isset($history_setting['retailcrm_history_customers'])) {
|
||||
$api = $this->retailcrm->getApiClient(
|
||||
$this->request->post[$this->moduleTitle . '_url'],
|
||||
$this->request->post[$this->moduleTitle . '_apikey'],
|
||||
$this->request->post[$this->moduleTitle . '_apiversion']
|
||||
);
|
||||
if (!isset($history_setting['retailcrm_history_orders'])
|
||||
&& !isset($history_setting['retailcrm_history_customers'])
|
||||
) {
|
||||
$api = $this->retailcrm->getApiClient(
|
||||
$this->request->post[\Retailcrm\Retailcrm::MODULE . '_url'],
|
||||
$this->request->post[\Retailcrm\Retailcrm::MODULE . '_apikey'],
|
||||
$this->request->post[\Retailcrm\Retailcrm::MODULE . '_apiversion']
|
||||
);
|
||||
|
||||
$ordersHistory = $api->ordersHistory();
|
||||
|
||||
if ($ordersHistory->isSuccessful() && !empty($ordersHistory['history'])) {
|
||||
$ordersHistory = $api->ordersHistory(array(), $ordersHistory['pagination']['totalPageCount']);
|
||||
|
||||
if ($ordersHistory->isSuccessful()) {
|
||||
$ordersHistoryArr = $ordersHistory['history'];
|
||||
$lastChangeOrders = end($ordersHistoryArr);
|
||||
$sinceIdOrders = $lastChangeOrders['id'];
|
||||
$generatedAt = $ordersHistory['generatedAt'];
|
||||
}
|
||||
}
|
||||
|
||||
$customersHistory = $api->customersHistory();
|
||||
|
||||
if ($customersHistory->isSuccessful() && !empty($customersHistory['history'])) {
|
||||
$customersHistory = $api->customersHistory(array(), $customersHistory['pagination']['totalPageCount']);
|
||||
|
||||
if ($customersHistory->isSuccessful()) {
|
||||
$customersHistoryArr = $customersHistory['history'];
|
||||
$lastChangeCustomers = end($customersHistoryArr);
|
||||
$sinceIdCustomers = $lastChangeCustomers['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->model_setting_setting->editSetting(
|
||||
'retailcrm_history',
|
||||
array(
|
||||
'retailcrm_history_orders' => isset($sinceIdOrders) ? $sinceIdOrders : 1,
|
||||
'retailcrm_history_customers' => isset($sinceIdCustomers) ? $sinceIdCustomers : 1,
|
||||
'retailcrm_history_datetime' => isset($generatedAt) ? $generatedAt : date('Y-m-d H:i:s')
|
||||
)
|
||||
);
|
||||
}
|
||||
$this->getHistory($api);
|
||||
}
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
$redirect = $this->url->link(
|
||||
'extension/module/retailcrm', $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle],
|
||||
'extension/module/retailcrm', 'user_token=' . $this->session->data['user_token'],
|
||||
'SSL'
|
||||
);
|
||||
|
||||
@ -251,51 +216,39 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
'special_price_settings',
|
||||
'special_price',
|
||||
'order_number',
|
||||
'text_order_number'
|
||||
'text_order_number',
|
||||
'debug',
|
||||
'text_debug'
|
||||
);
|
||||
|
||||
$_data = &$data;
|
||||
|
||||
foreach ($text_strings as $text) {
|
||||
$_data[$text] = $this->language->get($text);
|
||||
}
|
||||
|
||||
$_data['retailcrm_errors'] = array();
|
||||
$_data['saved_settings'] = $this->model_setting_setting
|
||||
->getSetting($this->moduleTitle);
|
||||
->getSetting(\Retailcrm\Retailcrm::MODULE);
|
||||
|
||||
$url = isset($_data['saved_settings'][$this->moduleTitle . '_url'])
|
||||
? $_data['saved_settings'][$this->moduleTitle . '_url']
|
||||
$url = isset($_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_url'])
|
||||
? $_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_url']
|
||||
: null;
|
||||
$key = isset($_data['saved_settings'][$this->moduleTitle . '_apikey'])
|
||||
? $_data['saved_settings'][$this->moduleTitle . '_apikey']
|
||||
: null;
|
||||
$apiVersion = isset($_data['saved_settings'][$this->moduleTitle . '_apiversion'])
|
||||
? $_data['saved_settings'][$this->moduleTitle . '_apiversion']
|
||||
$key = isset($_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_apikey'])
|
||||
? $_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_apikey']
|
||||
: null;
|
||||
|
||||
if (!empty($url) && !empty($key)) {
|
||||
|
||||
$_data['delivery'] = $this->model_extension_retailcrm_references
|
||||
->getDeliveryTypes();
|
||||
->getDeliveryTypes($opencart_api_client ,$retailcrm_api_client);
|
||||
$_data['statuses'] = $this->model_extension_retailcrm_references
|
||||
->getOrderStatuses();
|
||||
->getOrderStatuses($retailcrm_api_client);
|
||||
$_data['payments'] = $this->model_extension_retailcrm_references
|
||||
->getPaymentTypes();
|
||||
|
||||
if ($apiVersion == 'v5') {
|
||||
$_data['customFields'] = $this->model_extension_retailcrm_references
|
||||
->getCustomFields();
|
||||
}
|
||||
|
||||
if ($apiVersion != 'v3') {
|
||||
$_data['priceTypes'] = $this->model_extension_retailcrm_references
|
||||
->getPriceTypes();
|
||||
}
|
||||
->getPaymentTypes($retailcrm_api_client);
|
||||
$_data['customFields'] = $this->model_extension_retailcrm_references
|
||||
->getCustomFields($retailcrm_api_client);
|
||||
}
|
||||
|
||||
$config_data = array(
|
||||
$this->moduleTitle . '_status'
|
||||
\Retailcrm\Retailcrm::MODULE . '_status'
|
||||
);
|
||||
|
||||
foreach ($config_data as $conf) {
|
||||
@ -318,7 +271,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link(
|
||||
'common/dashboard',
|
||||
$this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], 'SSL'
|
||||
'user_token' . '=' . $this->session->data['user_token'], 'SSL'
|
||||
),
|
||||
'separator' => false
|
||||
);
|
||||
@ -327,7 +280,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
'text' => $this->language->get('text_module'),
|
||||
'href' => $this->url->link(
|
||||
'extension/extension',
|
||||
$this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], 'SSL'
|
||||
'user_token' . '=' . $this->session->data['user_token'], 'SSL'
|
||||
),
|
||||
'separator' => ' :: '
|
||||
);
|
||||
@ -336,19 +289,19 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
'text' => $this->language->get('retailcrm_title'),
|
||||
'href' => $this->url->link(
|
||||
'extension/module/retailcrm',
|
||||
$this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], 'SSL'
|
||||
'user_token' . '=' . $this->session->data['user_token'], 'SSL'
|
||||
),
|
||||
'separator' => ' :: '
|
||||
);
|
||||
|
||||
$_data['action'] = $this->url->link(
|
||||
'extension/module/retailcrm',
|
||||
$this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], 'SSL'
|
||||
'user_token' . '=' . $this->session->data['user_token'], 'SSL'
|
||||
);
|
||||
|
||||
$_data['cancel'] = $this->url->link(
|
||||
version_compare(VERSION, '3.0', '<') ? 'extension/extension' : 'marketplace/extension',
|
||||
$this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], 'SSL'
|
||||
'marketplace/extension',
|
||||
'user_token' . '=' . $this->session->data['user_token'], 'SSL'
|
||||
);
|
||||
|
||||
$_data['modules'] = array();
|
||||
@ -361,13 +314,12 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
|
||||
$this->load->model('design/layout');
|
||||
$_data['layouts'] = $this->model_design_layout->getLayouts();
|
||||
|
||||
$_data['header'] = $this->load->controller('common/header');
|
||||
$_data['column_left'] = $this->load->controller('common/column_left');
|
||||
$_data['footer'] = $this->load->controller('common/footer');
|
||||
$_data['countries'] = $this->model_localisation_country->getCountries();
|
||||
$_data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG;
|
||||
$_data[$this->tokenTitle] = $this->request->get[$this->tokenTitle];
|
||||
$_data['user_token'] = $this->request->get['user_token'];
|
||||
|
||||
if(file_exists(DIR_SYSTEM . '/cron/export_done')) {
|
||||
$_data['export_file'] = false;
|
||||
@ -382,11 +334,15 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
);
|
||||
|
||||
$_data['collectorFields'] = $collectorFields;
|
||||
$_data['api_versions'] = array('v3', 'v4', 'v5');
|
||||
$_data['default_apiversion'] = 'v4';
|
||||
$_data['api_versions'] = array('v5');
|
||||
$_data['default_apiversion'] = 'v5';
|
||||
|
||||
$retailcrmLog = file_exists(DIR_SYSTEM . 'storage/logs/retailcrm.log') ? DIR_SYSTEM . 'storage/logs/retailcrm.log' : false;
|
||||
$ocApiLog = file_exists(DIR_SYSTEM . 'storage/logs/opencartapi.log') ? DIR_SYSTEM . 'storage/logs/opencartapi.log' : false;
|
||||
$retailcrmLog = file_exists(DIR_SYSTEM . 'storage/logs/retailcrm.log')
|
||||
? DIR_SYSTEM . 'storage/logs/retailcrm.log'
|
||||
: false;
|
||||
$ocApiLog = file_exists(DIR_SYSTEM . 'storage/logs/opencartapi.log')
|
||||
? DIR_SYSTEM . 'storage/logs/opencartapi.log'
|
||||
: false;
|
||||
|
||||
if ($this->checkLogFile($retailcrmLog) !== false) {
|
||||
$_data['logs']['retailcrm_log'] = $this->checkLogFile($retailcrmLog);
|
||||
@ -400,8 +356,8 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
$_data['logs']['oc_error'] = $this->language->get('text_error_log');
|
||||
}
|
||||
|
||||
$_data['clear_retailcrm'] = $this->url->link('extension/module/retailcrm/clear_retailcrm', $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], true);
|
||||
$_data['clear_opencart'] = $this->url->link('extension/module/retailcrm/clear_opencart', $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], true);
|
||||
$_data['clear_retailcrm'] = $this->url->link('extension/module/retailcrm/clear_retailcrm', 'user_token' . '=' . $this->session->data['user_token'], true);
|
||||
$_data['clear_opencart'] = $this->url->link('extension/module/retailcrm/clear_opencart', 'user_token' . '=' . $this->session->data['user_token'], true);
|
||||
$_data['button_clear'] = $this->language->get('button_clear');
|
||||
|
||||
$this->response->setOutput(
|
||||
@ -417,25 +373,14 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
*/
|
||||
public function history()
|
||||
{
|
||||
$this->load->model('setting/setting');
|
||||
$settings = $this->model_setting_setting->getSetting($this->moduleTitle);
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
|
||||
if ($settings[$this->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($this->retailcrm->getApiClient());
|
||||
} else {
|
||||
$this->load->model('extension/retailcrm/history/v3');
|
||||
$this->model_extension_retailcrm_history_v3->request($this->retailcrm->getApiClient());
|
||||
}
|
||||
if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/history.php')) {
|
||||
$this->load->model('extension/retailcrm/custom/history');
|
||||
$this->model_extension_retailcrm_custom_history->request($this->retailcrm->getApiClient());
|
||||
} else {
|
||||
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($this->retailcrm->getApiClient());
|
||||
} else {
|
||||
$this->load->model('extension/retailcrm/history/v4_5');
|
||||
$this->model_extension_retailcrm_history_v4_5->request($this->retailcrm->getApiClient());
|
||||
}
|
||||
$this->load->model('extension/retailcrm/history');
|
||||
$this->model_extension_retailcrm_history->request($this->retailcrm->getApiClient());
|
||||
}
|
||||
}
|
||||
|
||||
@ -446,6 +391,8 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
*/
|
||||
public function icml()
|
||||
{
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
|
||||
if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/icml.php')) {
|
||||
$this->load->model('extension/retailcrm/custom/icml');
|
||||
$this->model_extension_retailcrm_custom_icml->generateICML();
|
||||
@ -463,8 +410,8 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function customer_edit($route, $customer)
|
||||
{
|
||||
public function customerEdit($route, $customer)
|
||||
{
|
||||
$this->load->model('localisation/country');
|
||||
$this->load->model('localisation/zone');
|
||||
$this->load->model('customer/customer');
|
||||
@ -487,7 +434,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
'postcode' => $address['postcode'],
|
||||
'iso_code_2' => $country['iso_code_2'],
|
||||
'zone' => $zone['name']
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
$this->load->model('extension/retailcrm/customer');
|
||||
@ -504,23 +451,18 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
$order_id = isset($this->request->get['order_id']) ? $this->request->get['order_id'] : '';
|
||||
$this->load->model('sale/order');
|
||||
|
||||
$data = $this->model_sale_order->getOrder($order_id);
|
||||
$data['products'] = $this->model_sale_order->getOrderProducts($order_id);
|
||||
$data['totals'] = $this->model_sale_order->getOrderTotals($order_id);
|
||||
$order = $this->model_sale_order->getOrder($order_id);
|
||||
$order['products'] = $this->model_sale_order->getOrderProducts($order_id);
|
||||
$order['totals'] = $this->model_sale_order->getOrderTotals($order_id);
|
||||
|
||||
foreach ($data['products'] as $key => $product) {
|
||||
$data['products'][$key]['option'] = $this->model_sale_order->getOrderOptions($product['order_id'], $product['order_product_id']);
|
||||
foreach ($order['products'] as $key => $product) {
|
||||
$order['products'][$key]['option'] = $this->model_sale_order->getOrderOptions($product['order_id'], $product['order_product_id']);
|
||||
}
|
||||
|
||||
if (!isset($data['fromApi'])) {
|
||||
$this->load->model('setting/setting');
|
||||
$status = $this->model_setting_setting->getSetting($this->moduleTitle);
|
||||
$data['order_status'] = $status[$this->moduleTitle . '_status'][$data['order_status_id']];
|
||||
|
||||
$this->load->model('extension/retailcrm/order');
|
||||
$this->model_extension_retailcrm_order->uploadOrder($data, $this->retailcrm->getApiClient());
|
||||
$response = ModelExtensionRetailcrmOrder::getLastResponse();
|
||||
}
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
$retailcrm_order = $this->retailcrm->createObject(\Retailcrm\Order::class);
|
||||
$retailcrm_order->prepare($order);
|
||||
$response = $retailcrm_order->create($this->retailcrm->getApiClient());
|
||||
|
||||
if (!$response->isSuccessful()) {
|
||||
if (isset($response['errors'])) {
|
||||
@ -556,14 +498,17 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
public function export()
|
||||
{
|
||||
$this->load->model('customer/customer');
|
||||
$this->load->model('extension/retailcrm/customer');
|
||||
$this->load->model('extension/retailcrm/order');
|
||||
$this->load->model('sale/order');
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
|
||||
$retailcrm_api_client = $this->retailcrm->getApiClient();
|
||||
$retailcrm_customer = $this->retailcrm->createObject(\Retailcrm\Customer::class);
|
||||
$retailcrm_order = $this->retailcrm->createObject(\Retailcrm\Order::class);
|
||||
|
||||
$customers = $this->model_customer_customer->getCustomers();
|
||||
$this->model_extension_retailcrm_customer->uploadToCrm($customers, $this->retailcrm->getApiClient());
|
||||
$orders = $this->model_sale_order->getOrders();
|
||||
$retailcrm_customer->upload($retailcrm_api_client, $customers, 'customers');
|
||||
|
||||
$orders = $this->model_sale_order->getOrders();
|
||||
$fullOrders = array();
|
||||
|
||||
foreach ($orders as $order) {
|
||||
@ -572,15 +517,14 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
$fullOrder['totals'] = $this->model_sale_order->getOrderTotals($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']);
|
||||
}
|
||||
|
||||
$fullOrders[] = $fullOrder;
|
||||
}
|
||||
|
||||
$this->model_extension_retailcrm_order->uploadToCrm($fullOrders, $this->retailcrm->getApiClient());
|
||||
fopen(DIR_SYSTEM . '/cron/export_done', "x");
|
||||
$retailcrm_order->upload($retailcrm_api_client, $fullOrders);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -591,14 +535,23 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
public function prices()
|
||||
{
|
||||
$this->load->model('catalog/product');
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
$products = $this->model_catalog_product->getProducts();
|
||||
|
||||
if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/prices.php')) {
|
||||
$this->load->model('extension/retailcrm/custom/prices');
|
||||
$this->model_extension_retailcrm_custom_prices->uploadPrices($products, $this->retailcrm->getApiClient());
|
||||
$this->model_extension_retailcrm_custom_prices->uploadPrices(
|
||||
$products,
|
||||
$this->retailcrm->getApiClient(),
|
||||
$this->retailcrm
|
||||
);
|
||||
} else {
|
||||
$this->load->model('extension/retailcrm/prices');
|
||||
$this->model_extension_retailcrm_prices->uploadPrices($products, $this->retailcrm->getApiClient());
|
||||
$this->model_extension_retailcrm_prices->uploadPrices(
|
||||
$products,
|
||||
$this->retailcrm->getApiClient(),
|
||||
$this->retailcrm
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -610,22 +563,20 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
private function validate()
|
||||
{
|
||||
$versionsMap = array(
|
||||
'v3' => '3.0',
|
||||
'v4' => '4.0',
|
||||
'v5' => '5.0'
|
||||
);
|
||||
|
||||
if (!empty($this->request->post[$this->moduleTitle . '_url']) && !empty($this->request->post[$this->moduleTitle . '_apikey'])) {
|
||||
if (!empty($this->request->post[\Retailcrm\Retailcrm::MODULE . '_url']) && !empty($this->request->post[\Retailcrm\Retailcrm::MODULE . '_apikey'])) {
|
||||
$apiClient = $this->retailcrm->getApiClient(
|
||||
$this->request->post[$this->moduleTitle . '_url'],
|
||||
$this->request->post[$this->moduleTitle . '_apikey']
|
||||
$this->request->post[\Retailcrm\Retailcrm::MODULE . '_url'],
|
||||
$this->request->post[\Retailcrm\Retailcrm::MODULE . '_apikey']
|
||||
);
|
||||
}
|
||||
|
||||
$response = $apiClient->apiVersions();
|
||||
$response = isset($apiClient) ? $apiClient->apiVersions() : false;
|
||||
|
||||
if ($response && $response->isSuccessful()) {
|
||||
if (!in_array($versionsMap[$this->request->post[$this->moduleTitle . '_apiversion']], $response['versions'])) {
|
||||
if (!in_array($versionsMap[$this->request->post[\Retailcrm\Retailcrm::MODULE . '_apiversion']], $response['versions'])) {
|
||||
$this->_error['warning'] = $this->language->get('text_error_api');
|
||||
}
|
||||
} else {
|
||||
@ -636,9 +587,9 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
$this->_error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (isset($this->request->post[$this->moduleTitle . '_collector']['custom']) &&
|
||||
$this->request->post[$this->moduleTitle . '_collector']['custom_form'] == 1) {
|
||||
$customField = $this->request->post[$this->moduleTitle . '_collector']['custom'];
|
||||
if (isset($this->request->post[\Retailcrm\Retailcrm::MODULE . '_collector']['custom']) &&
|
||||
$this->request->post[\Retailcrm\Retailcrm::MODULE . '_collector']['custom_form'] == 1) {
|
||||
$customField = $this->request->post[\Retailcrm\Retailcrm::MODULE . '_collector']['custom'];
|
||||
|
||||
if (empty($customField['name']) && empty($customField['email']) && empty($customField['phone'])) {
|
||||
$this->_error['fields'] = $this->language->get('text_error_collector_fields');
|
||||
@ -654,7 +605,7 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
|
||||
/**
|
||||
* Clear retailcrm log file
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear_retailcrm()
|
||||
@ -667,12 +618,18 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('extension/module/retailcrm', $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], true));
|
||||
$this->response->redirect(
|
||||
$this->url->link(
|
||||
'extension/module/retailcrm',
|
||||
'user_token' . '=' . $this->session->data['user_token'],
|
||||
true
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear opencart API log file
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear_opencart()
|
||||
@ -685,54 +642,18 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('extension/module/retailcrm', $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for load models
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get collector module name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getCollectorTitle()
|
||||
{
|
||||
if (version_compare(VERSION, '3.0', '<')) {
|
||||
$title = 'daemon_collector';
|
||||
} else {
|
||||
$title = 'analytics_daemon_collector';
|
||||
}
|
||||
|
||||
return $title;
|
||||
$this->response->redirect(
|
||||
$this->url->link(
|
||||
'extension/module/retailcrm',
|
||||
'user_token' . '=' . $this->session->data['user_token'],
|
||||
true
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check file size
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function checkLogFile($file)
|
||||
@ -754,67 +675,65 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
|
||||
/**
|
||||
* Add events to db
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addEvents()
|
||||
{
|
||||
$this->loadModels();
|
||||
|
||||
$this->{'model_' . $this->modelEvent}
|
||||
$this->model_setting_event
|
||||
->addEvent(
|
||||
$this->moduleTitle,
|
||||
\Retailcrm\Retailcrm::MODULE,
|
||||
'catalog/model/checkout/order/addOrder/after',
|
||||
'extension/module/retailcrm/order_create'
|
||||
'extension/module/retailcrm/orderCreate'
|
||||
);
|
||||
|
||||
$this->{'model_' . $this->modelEvent}
|
||||
$this->model_setting_event
|
||||
->addEvent(
|
||||
$this->moduleTitle,
|
||||
'catalog/model/checkout/order/addOrderHistory/after',
|
||||
'extension/module/retailcrm/order_edit'
|
||||
\Retailcrm\Retailcrm::MODULE,
|
||||
'catalog/model/checkout/order/editOrder/after',
|
||||
'extension/module/retailcrm/orderEdit'
|
||||
);
|
||||
|
||||
$this->{'model_' . $this->modelEvent}
|
||||
$this->model_setting_event
|
||||
->addEvent(
|
||||
$this->moduleTitle,
|
||||
\Retailcrm\Retailcrm::MODULE,
|
||||
'catalog/model/account/customer/addCustomer/after',
|
||||
'extension/module/retailcrm/customer_create'
|
||||
'extension/module/retailcrm/customerCreate'
|
||||
);
|
||||
|
||||
$this->{'model_' . $this->modelEvent}
|
||||
$this->model_setting_event
|
||||
->addEvent(
|
||||
$this->moduleTitle,
|
||||
\Retailcrm\Retailcrm::MODULE,
|
||||
'catalog/model/account/customer/editCustomer/after',
|
||||
'extension/module/retailcrm/customer_edit'
|
||||
'extension/module/retailcrm/customerEdit'
|
||||
);
|
||||
|
||||
$this->{'model_' . $this->modelEvent}
|
||||
$this->model_setting_event
|
||||
->addEvent(
|
||||
$this->moduleTitle,
|
||||
\Retailcrm\Retailcrm::MODULE,
|
||||
'catalog/model/account/address/editAddress/after',
|
||||
'extension/module/retailcrm/customer_edit'
|
||||
'extension/module/retailcrm/customerEdit'
|
||||
);
|
||||
|
||||
$this->{'model_' . $this->modelEvent}
|
||||
$this->model_setting_event
|
||||
->addEvent(
|
||||
$this->moduleTitle,
|
||||
\Retailcrm\Retailcrm::MODULE,
|
||||
'admin/model/customer/customer/editCustomer/after',
|
||||
'extension/module/retailcrm/customer_edit'
|
||||
'extension/module/retailcrm/customerEdit'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check events in db
|
||||
*
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function checkEvents()
|
||||
{
|
||||
$events = $this->{'model_' . $this->modelEvent}->getEvent(
|
||||
$this->moduleTitle,
|
||||
$events = $this->model_setting_event->getEvent(
|
||||
\Retailcrm\Retailcrm::MODULE,
|
||||
'catalog/model/checkout/order/addOrder/after',
|
||||
'extension/module/retailcrm/order_create'
|
||||
'extension/module/retailcrm/orderCreate'
|
||||
);
|
||||
|
||||
if (!empty($events)) {
|
||||
@ -826,17 +745,72 @@ class ControllerExtensionModuleRetailcrm extends Controller
|
||||
|
||||
/**
|
||||
* Delete events from db
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function deleteEvents()
|
||||
{
|
||||
$this->loadModels();
|
||||
$this->model_setting_event->deleteEventByCode(\Retailcrm\Retailcrm::MODULE);
|
||||
}
|
||||
|
||||
if (version_compare(VERSION, '3.0', '<')) {
|
||||
$this->{'model_' . $this->modelEvent}->deleteEvent($this->moduleTitle);
|
||||
} else {
|
||||
$this->{'model_' . $this->modelEvent}->deleteEventByCode($this->moduleTitle);
|
||||
/**
|
||||
* Getting history for first setting save
|
||||
*
|
||||
* @param $apiClient
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function getHistory($apiClient)
|
||||
{
|
||||
$ordersHistoryBegin = $apiClient->ordersHistory();
|
||||
|
||||
if ($ordersHistoryBegin->isSuccessful() && !empty($ordersHistoryBegin['history'])) {
|
||||
$ordersHistoryEnd = $apiClient->ordersHistory(array(),
|
||||
$ordersHistoryBegin['pagination']['totalPageCount']
|
||||
);
|
||||
|
||||
if ($ordersHistoryEnd->isSuccessful()) {
|
||||
$ordersHistoryArr = $ordersHistoryEnd['history'];
|
||||
$lastChangeOrders = end($ordersHistoryArr);
|
||||
$sinceIdOrders = $lastChangeOrders['id'];
|
||||
$generatedAt = $ordersHistoryEnd['generatedAt'];
|
||||
}
|
||||
}
|
||||
|
||||
$customersHistoryBegin = $apiClient->customersHistory();
|
||||
|
||||
if ($customersHistoryBegin->isSuccessful() && !empty($customersHistoryBegin['history'])) {
|
||||
$customersHistoryEnd = $apiClient->customersHistory(
|
||||
array(),
|
||||
$customersHistoryBegin['pagination']['totalPageCount']
|
||||
);
|
||||
|
||||
if ($customersHistoryEnd->isSuccessful()) {
|
||||
$customersHistoryArr = $customersHistoryEnd['history'];
|
||||
$lastChangeCustomers = end($customersHistoryArr);
|
||||
$sinceIdCustomers = $lastChangeCustomers['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->model_setting_setting->editSetting(
|
||||
'retailcrm_history',
|
||||
array(
|
||||
'retailcrm_history_orders' => isset($sinceIdOrders) ? $sinceIdOrders : 1,
|
||||
'retailcrm_history_customers' => isset($sinceIdCustomers) ? $sinceIdCustomers : 1,
|
||||
'retailcrm_history_datetime' => isset($generatedAt) ? $generatedAt : date('Y-m-d H:i:s')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function addCronJobs() {
|
||||
$this->load->model('setting/cron');
|
||||
$this->model_setting_cron->addCron('icml', 'day', 'cron/icml', 1);
|
||||
$this->model_setting_cron->addCron('prices', 'day', 'cron/icml', 0);
|
||||
}
|
||||
|
||||
private function deleteCronJobs() {
|
||||
$this->load->model('setting/cron');
|
||||
$this->model_setting_cron->deleteCronByCode('icml');
|
||||
$this->model_setting_cron->deleteCronByCode('prices');
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ $_['collector_site_key'] = 'Site key';
|
||||
$_['special_price_settings'] = 'Setting of uploading promotion price';
|
||||
$_['special_price'] = 'Price type to which the promotion price will be uploaded';
|
||||
|
||||
|
||||
$_['text_success_export'] = 'Orders and customers are uploaded successfully';
|
||||
$_['text_success_export_order'] = 'Order is uploaded successfully';
|
||||
$_['text_button_export'] = 'Upload all orders and customers';
|
||||
@ -69,6 +70,9 @@ $_['retailcrm_missing_status'] = 'Status of lost orders';
|
||||
$_['order_number'] = 'Order number';
|
||||
$_['text_order_number'] = 'Upload the order number to retailCRM';
|
||||
|
||||
$_['debug'] = 'Debug mode';
|
||||
$_['text_debug'] = 'Enable debug mode';
|
||||
|
||||
$_['column_total'] = 'Total';
|
||||
$_['product_summ'] = 'Sum';
|
||||
|
||||
|
@ -24,7 +24,7 @@ $_['retailcrm_url'] = 'Адрес RetailCRM';
|
||||
$_['retailcrm_apikey'] = 'Api ключ RetailCRM';
|
||||
$_['collector_site_key'] = 'Ключ сайта';
|
||||
$_['special_price_settings'] = 'Настройка выгрузки акционной цены';
|
||||
$_['special_price'] = 'Тип цены, в который будет выгружаться цена по акции';
|
||||
$_['special_price'] = 'Тип цены, в который будет выгружаться цена по акции';
|
||||
|
||||
$_['text_success_export'] = 'Заказы и клиенты успешно выгружены';
|
||||
$_['text_success_export_order'] = 'Заказ успешно выгружен';
|
||||
@ -56,7 +56,7 @@ $_['text_error_cf_opencart'] = 'Отсутствуют пользовате
|
||||
$_['text_error_cf_retailcrm'] = 'Отсутствуют пользовательские поля в RetailCRM';
|
||||
$_['text_error_save'] = 'Ошибка сохранения настроек';
|
||||
$_['text_error_log'] = 'Размер лога более 2MB';
|
||||
$_['text_error_delivery'] = 'Не найдены типы доставки';
|
||||
$_['text_error_delivery'] = 'Не найдены типы доставки';
|
||||
$_['text_confirm_log'] = 'Вы уверены, что хотите очистить лог?';
|
||||
|
||||
$_['retailcrm_dict_delivery'] = 'Способы доставки';
|
||||
@ -69,6 +69,9 @@ $_['retailcrm_missing_status'] = 'Статус пропавших заказо
|
||||
$_['order_number'] = 'Номер заказа';
|
||||
$_['text_order_number'] = 'Передавать номер заказа в retailCRM';
|
||||
|
||||
$_['debug'] = 'Debug режим';
|
||||
$_['text_debug'] = 'Включить подробное логирование';
|
||||
|
||||
$_['column_total'] = 'Итого';
|
||||
$_['product_summ'] = 'Сумма';
|
||||
|
||||
|
@ -1,137 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ModelExtensionRetailcrmCustomer extends Model {
|
||||
protected $settings;
|
||||
protected $moduleTitle;
|
||||
protected $retailcrmApiClient;
|
||||
|
||||
public function __construct($registry)
|
||||
{
|
||||
parent::__construct($registry);
|
||||
$this->load->model('setting/setting');
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
|
||||
$this->moduleTitle = $this->retailcrm->getModuleTitle();
|
||||
$this->settings = $this->model_setting_setting->getSetting($this->moduleTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload customers
|
||||
*
|
||||
* @param array $customers
|
||||
* @param \RetailcrmProxy $retailcrmApiClient
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function uploadToCrm($customers, $retailcrmApiClient)
|
||||
{
|
||||
if ($retailcrmApiClient === false || empty($customers)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$customersToCrm = array();
|
||||
|
||||
foreach($customers as $customer) {
|
||||
$customersToCrm[] = $this->process($customer);
|
||||
}
|
||||
|
||||
$chunkedCustomers = array_chunk($customersToCrm, 50);
|
||||
|
||||
foreach($chunkedCustomers as $customersPart) {
|
||||
$retailcrmApiClient->customersUpload($customersPart);
|
||||
}
|
||||
|
||||
return $chunkedCustomers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit customer
|
||||
*
|
||||
* @param array $customer
|
||||
* @param \RetailcrmProxy $retailcrmApiClient
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function changeInCrm($customer, $retailcrmApiClient)
|
||||
{
|
||||
if ($retailcrmApiClient === false || empty($customer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$customerToCrm = $this->process($customer);
|
||||
|
||||
$retailcrmApiClient->customersEdit($customerToCrm);
|
||||
|
||||
return $customerToCrm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create customer
|
||||
*
|
||||
* @param array $customer
|
||||
* @param \RetailcrmProxy $retailcrmApiClient
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendToCrm($customer, $retailcrmApiClient)
|
||||
{
|
||||
if ($retailcrmApiClient === false || empty($customer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$customerToCrm = $this->process($customer);
|
||||
|
||||
$retailcrmApiClient->customersCreate($customerToCrm);
|
||||
|
||||
return $customerToCrm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process customer
|
||||
*
|
||||
* @param array $customer
|
||||
*
|
||||
* @return array $customerToCrm
|
||||
*/
|
||||
private function process($customer)
|
||||
{
|
||||
$customerToCrm = array(
|
||||
'externalId' => $customer['customer_id'],
|
||||
'firstName' => $customer['firstname'],
|
||||
'lastName' => $customer['lastname'],
|
||||
'email' => $customer['email'],
|
||||
'phones' => array(
|
||||
array(
|
||||
'number' => $customer['telephone']
|
||||
)
|
||||
),
|
||||
'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']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->settings[$this->moduleTitle . '_custom_field']) && $customer['custom_field']) {
|
||||
$customFields = json_decode($customer['custom_field']);
|
||||
|
||||
foreach ($customFields as $key => $value) {
|
||||
if (isset($this->settings[$this->moduleTitle . '_custom_field']['c_' . $key])) {
|
||||
$customFieldsToCrm[$this->settings[$this->moduleTitle . '_custom_field']['c_' . $key]] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($customFieldsToCrm)) {
|
||||
$customerToCrm['customFields'] = $customFieldsToCrm;
|
||||
}
|
||||
}
|
||||
|
||||
return $customerToCrm;
|
||||
}
|
||||
}
|
@ -1,194 +1,825 @@
|
||||
<?php
|
||||
|
||||
class ModelExtensionRetailcrmHistory extends Model
|
||||
require_once 'order.php';
|
||||
|
||||
class ModelExtensionRetailcrmHistory extends ModelExtensionRetailcrmOrder
|
||||
{
|
||||
/**
|
||||
* Create order in OC
|
||||
*
|
||||
* @param array $order
|
||||
*
|
||||
* @return int $order_id
|
||||
*/
|
||||
public function addOrder($order)
|
||||
protected $createResult;
|
||||
protected $settings;
|
||||
protected $opencartApiClient;
|
||||
|
||||
private $customFieldSetting;
|
||||
|
||||
public function __construct($registry)
|
||||
{
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET store_id = '" . (int)$order['store_id'] . "', store_name = '" . $order['store_name'] . "', customer_id = '" . (int)$order['customer_id'] . "', customer_group_id = '" . (int)$order['customer_group_id'] . "', firstname = '" . $this->db->escape($order['firstname']) . "', lastname = '" . $this->db->escape($order['lastname']) . "', email = '" . $this->db->escape($order['email']) . "', telephone = '" . $this->db->escape($order['telephone']) . "', custom_field = '" . $this->db->escape(isset($order['custom_field']) ? json_encode($order['custom_field']) : '') . "', payment_firstname = '" . $this->db->escape($order['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($order['payment_lastname']) . "', payment_address_1 = '" . $this->db->escape($order['payment_address_1']) . "', payment_city = '" . $this->db->escape($order['payment_city']) . "', payment_postcode = '" . $this->db->escape($order['payment_postcode']) . "', payment_country = '" . $this->db->escape($order['payment_country']) . "', payment_country_id = '" . (int)$order['payment_country_id'] . "', payment_zone = '" . $this->db->escape($order['payment_zone']) . "', payment_zone_id = '" . (int)$order['payment_zone_id'] . "', payment_method = '" . $this->db->escape($order['payment_method']) . "', payment_code = '" . $this->db->escape($order['payment_code']) . "', shipping_firstname = '" . $this->db->escape($order['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($order['shipping_lastname']) . "', shipping_address_1 = '" . $this->db->escape($order['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($order['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($order['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($order['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($order['shipping_country']) . "', shipping_country_id = '" . (int)$order['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($order['shipping_zone']) . "', shipping_zone_id = '" . (int)$order['shipping_zone_id'] . "', shipping_method = '" . $this->db->escape($order['shipping_method']) . "', shipping_code = '" . $this->db->escape($order['shipping_code']) . "', comment = '" . $this->db->escape($order['comment']) . "', total = '" . (float)$order['total'] . "', affiliate_id = '" . (int)$order['affiliate_id'] . "', language_id = '" . (int)$order['language_id'] . "', currency_id = '" . (int)$order['currency_id'] . "', currency_code = '" . $this->db->escape($order['currency_code']) . "', currency_value = '" . (float)$order['currency_value'] . "', order_status_id = '" . (int)$order['order_status_id'] . "', date_added = NOW(), date_modified = NOW()");
|
||||
|
||||
$order_id = $this->db->getLastId();
|
||||
|
||||
// Products
|
||||
if (isset($order['order_product']) && $order['order_product']) {
|
||||
$this->addOrderProducts($order_id, $order['order_product']);
|
||||
}
|
||||
|
||||
// Totals
|
||||
if (isset($order['order_total'])) {
|
||||
$this->addOrderTotals($order_id, $order['order_total']);
|
||||
}
|
||||
|
||||
return $order_id;
|
||||
parent::__construct($registry);
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
$this->opencartApiClient = $this->retailcrm->getOcApiClient($registry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit order in OC
|
||||
*
|
||||
* @param int $order_id
|
||||
* @param array $order
|
||||
*
|
||||
* @return void
|
||||
* Getting changes from RetailCRM
|
||||
* @param \RetailcrmProxy $retailcrmApiClient
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function editOrder($order_id, $order)
|
||||
public function request($retailcrmApiClient)
|
||||
{
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "order` SET customer_id = '" . (int)$order['customer_id'] . "', customer_group_id = '" . (int)$order['customer_group_id'] . "', firstname = '" . $this->db->escape($order['firstname']) . "', lastname = '" . $this->db->escape($order['lastname']) . "', email = '" . $this->db->escape($order['email']) . "', telephone = '" . $this->db->escape($order['telephone']) . "', custom_field = '" . $this->db->escape(json_encode($order['custom_field'])) . "', payment_firstname = '" . $this->db->escape($order['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($order['payment_lastname']) . "', payment_address_1 = '" . $this->db->escape($order['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($order['payment_address_2']) . "', payment_city = '" . $this->db->escape($order['payment_city']) . "', payment_postcode = '" . $this->db->escape($order['payment_postcode']) . "', payment_country = '" . $this->db->escape($order['payment_country']) . "', payment_country_id = '" . (int)$order['payment_country_id'] . "', payment_zone = '" . $this->db->escape($order['payment_zone']) . "', payment_zone_id = '" . (int)$order['payment_zone_id'] . "', payment_method = '" . $this->db->escape($order['payment_method']) . "', payment_code = '" . $this->db->escape($order['payment_code']) . "', shipping_firstname = '" . $this->db->escape($order['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($order['shipping_lastname']) . "', shipping_address_1 = '" . $this->db->escape($order['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($order['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($order['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($order['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($order['shipping_country']) . "', shipping_country_id = '" . (int)$order['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($order['shipping_zone']) . "', shipping_zone_id = '" . (int)$order['shipping_zone_id'] . "', shipping_method = '" . $this->db->escape($order['shipping_method']) . "', shipping_code = '" . $this->db->escape($order['shipping_code']) . "', comment = '" . $this->db->escape($order['comment']) . "', total = '" . (float)$order['total'] . "', order_status_id = '" . (int)$order['order_status_id'] . "', date_modified = NOW() WHERE order_id = '" . (int)$order_id . "'");
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
$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->db->query("DELETE FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
|
||||
$this->load->language('extension/module/retailcrm');
|
||||
|
||||
// Products
|
||||
if (isset($order['order_product']) && $order['order_product']) {
|
||||
$this->addOrderProducts($order_id, $order['order_product']);
|
||||
$settings = $this->model_setting_setting->getSetting(\Retailcrm\Retailcrm::MODULE);
|
||||
$history = $this->model_setting_setting->getSetting('retailcrm_history');
|
||||
$settings['domain'] = parse_url(HTTP_SERVER, PHP_URL_HOST);
|
||||
|
||||
$url = isset($settings[\Retailcrm\Retailcrm::MODULE . '_url']) ? $settings[\Retailcrm\Retailcrm::MODULE . '_url'] : null;
|
||||
$key = isset($settings[\Retailcrm\Retailcrm::MODULE . '_apikey']) ? $settings[\Retailcrm\Retailcrm::MODULE . '_apikey'] : null;
|
||||
|
||||
if (empty($url) || empty($key)) {
|
||||
$this->log->addNotice('You need to configure retailcrm module first.');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Totals
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "'");
|
||||
$sinceIdOrders = $history['retailcrm_history_orders'] ? $history['retailcrm_history_orders'] : null;
|
||||
$sinceIdCustomers = $history['retailcrm_history_customers'] ? $history['retailcrm_history_customers'] : null;
|
||||
|
||||
if (isset($order['order_total'])) {
|
||||
$this->addOrderTotals($order_id, $order['order_total']);
|
||||
$packsOrders = $retailcrmApiClient->ordersHistory(array(
|
||||
'sinceId' => $sinceIdOrders ? $sinceIdOrders : 0
|
||||
), 1, 100);
|
||||
$packsCustomers = $retailcrmApiClient->customersHistory(array(
|
||||
'sinceId' => $sinceIdCustomers ? $sinceIdCustomers : 0
|
||||
), 1, 100);
|
||||
|
||||
if(!$packsOrders->isSuccessful() && count($packsOrders->history) <= 0 && !$packsCustomers->isSuccessful() && count($packsCustomers->history) <= 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add order products
|
||||
*
|
||||
* @param int $order_id
|
||||
* @param array $products
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addOrderProducts($order_id, $products)
|
||||
{
|
||||
foreach ($products as $product) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_id = '" . (int)$order_id . "', product_id = '" . (int)$product['product_id'] . "', name = '" . $this->db->escape($product['name']) . "', model = '" . $this->db->escape($product['model']) . "', quantity = '" . (int)$product['quantity'] . "', price = '" . (float)$product['price'] . "', total = '" . (float)$product['total'] . "', reward = '" . (float)$product['reward'] . "'");
|
||||
$generatedAt = $packsOrders['generatedAt'];
|
||||
$orders = RetailcrmHistoryHelper::assemblyOrder($packsOrders->history);
|
||||
$customers = RetailcrmHistoryHelper::assemblyCustomer($packsCustomers->history);
|
||||
|
||||
$order_product_id = $this->db->getLastId();
|
||||
$ordersHistory = $packsOrders->history;
|
||||
$customersHistory = $packsCustomers->history;
|
||||
|
||||
foreach ($product['option'] as $option) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "order_option SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', product_option_id = '" . (int)$option['product_option_id'] . "', product_option_value_id = '" . (int)$option['product_option_value_id'] . "', name = '" . $this->db->escape($option['name']) . "', `value` = '" . $this->db->escape($option['value']) . "', `type` = '" . $this->db->escape($option['type']) . "'");
|
||||
$lastChangeOrders = $ordersHistory ? end($ordersHistory) : null;
|
||||
$lastChangeCustomers = $customersHistory ? end($customersHistory) : null;
|
||||
|
||||
if ($lastChangeOrders !== null) {
|
||||
$sinceIdOrders = $lastChangeOrders['id'];
|
||||
}
|
||||
|
||||
if ($lastChangeCustomers !== null) {
|
||||
$sinceIdCustomers = $lastChangeCustomers['id'];
|
||||
}
|
||||
|
||||
$this->settings = $settings;
|
||||
$this->totalTitle = $this->totalTitles();
|
||||
$this->subtotalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'sub_total');
|
||||
$this->totalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'total');
|
||||
$this->shippingSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'shipping');
|
||||
|
||||
$this->delivery = array_flip($settings[\Retailcrm\Retailcrm::MODULE . '_delivery']);
|
||||
$this->payment = array_flip($settings[\Retailcrm\Retailcrm::MODULE . '_payment']);
|
||||
$this->status = array_flip($settings[\Retailcrm\Retailcrm::MODULE . '_status']);
|
||||
$this->delivery_default = $settings[\Retailcrm\Retailcrm::MODULE . '_default_shipping'];
|
||||
$this->payment_default = $settings[\Retailcrm\Retailcrm::MODULE . '_default_payment'];
|
||||
$this->ocPayment = $this->model_extension_retailcrm_references
|
||||
->getOpercartPaymentTypes();
|
||||
|
||||
$this->ocDelivery = $this->model_extension_retailcrm_references
|
||||
->getOpercartDeliveryTypes($this->opencartApiClient);
|
||||
|
||||
$this->zones = $this->model_localisation_zone->getZones();
|
||||
|
||||
if (isset($settings[\Retailcrm\Retailcrm::MODULE . '_custom_field'])) {
|
||||
$this->customFieldSetting = array_flip($settings[\Retailcrm\Retailcrm::MODULE . '_custom_field']);
|
||||
}
|
||||
|
||||
$updatedOrders = array();
|
||||
$newOrders = array();
|
||||
|
||||
foreach ($orders as $order) {
|
||||
|
||||
if (isset($order['deleted'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($order['externalId'])) {
|
||||
$updatedOrders[] = $order['id'];
|
||||
} else {
|
||||
$newOrders[] = $order['id'];
|
||||
}
|
||||
}
|
||||
|
||||
unset($orders);
|
||||
|
||||
$updateCustomers = array();
|
||||
|
||||
foreach ($customers as $customer) {
|
||||
|
||||
if (isset($customer['deleted'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($customer['externalId'])) {
|
||||
$updateCustomers[] = $customer['id'];
|
||||
}
|
||||
}
|
||||
|
||||
unset($customers);
|
||||
|
||||
if (!empty($updateCustomers)) {
|
||||
$customers = $retailcrmApiClient->customersList($filter = array('ids' => $updateCustomers));
|
||||
if ($customers) {
|
||||
$this->updateCustomers($customers['customers']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($newOrders)) {
|
||||
$orders = $retailcrmApiClient->ordersList($filter = array('ids' => $newOrders));
|
||||
if ($orders) {
|
||||
$this->createResult = $this->createOrders($orders['orders']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($updatedOrders)) {
|
||||
$orders = $retailcrmApiClient->ordersList($filter = array('ids' => $updatedOrders));
|
||||
if ($orders) {
|
||||
$this->updateOrders($orders['orders']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->model_setting_setting->editSetting(
|
||||
'retailcrm_history',
|
||||
array(
|
||||
'retailcrm_history_orders' => $sinceIdOrders,
|
||||
'retailcrm_history_customers' => $sinceIdCustomers,
|
||||
'retailcrm_history_datetime' => $generatedAt
|
||||
)
|
||||
);
|
||||
|
||||
if (!empty($this->createResult['customers'])) {
|
||||
$retailcrmApiClient->customersFixExternalIds($this->createResult['customers']);
|
||||
}
|
||||
|
||||
if (!empty($this->createResult['orders'])) {
|
||||
$retailcrmApiClient->ordersFixExternalIds($this->createResult['orders']);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add order totals
|
||||
*
|
||||
* @param int $order_id
|
||||
* @param array $totals
|
||||
*
|
||||
* Update orders from history
|
||||
*
|
||||
* @param array $orders
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addOrderTotals($order_id, $totals)
|
||||
protected function updateOrders($orders)
|
||||
{
|
||||
foreach ($totals as $total) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "order_total SET order_id = '" . (int)$order_id . "', code = '" . $this->db->escape($total['code']) . "', title = '" . $this->db->escape($total['title']) . "', `value` = '" . (float)$total['value'] . "', sort_order = '" . (int)$total['sort_order'] . "'");
|
||||
foreach ($orders as $order) {
|
||||
$ocOrder = $this->model_sale_order->getOrder($order['externalId']);
|
||||
|
||||
if (isset($order['payments']) && $order['payments']) {
|
||||
foreach ($order['payments'] as $orderPayment) {
|
||||
if (isset($orderPayment['externalId'])) {
|
||||
$payment = $orderPayment;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($payment) && count($order['payments']) == 1) {
|
||||
$payment = end($order['payments']);
|
||||
}
|
||||
} elseif (isset($order['paymentType'])) {
|
||||
$payment['type'] = $order['paymentType'];
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
$mail = isset($order['email']) ? $order['email'] : $order['customer']['email'];
|
||||
$phone = isset($order['phone']) ? $order['phone'] : '';
|
||||
|
||||
if (!$phone) {
|
||||
$data['telephone'] = $order['customer']['phones'] ? $order['customer']['phones'][0]['number'] : '80000000000';
|
||||
} else {
|
||||
$data['telephone'] = $phone;
|
||||
}
|
||||
|
||||
if (isset($order['customer']['externalId']) && $order['customer']['externalId']) {
|
||||
$customer = $this->model_customer_customer->getCustomer($order['customer']['externalId']);
|
||||
}
|
||||
|
||||
$data['customer'] = $order['firstName'];
|
||||
$data['customer_id'] = (isset($customer)) ? $customer['customer_id'] : 0;
|
||||
$data['customer_group_id'] = (isset($customer)) ? $customer['customer_group_id'] : 1;
|
||||
$data['firstname'] = $order['firstName'];
|
||||
$data['lastname'] = isset($order['lastName']) ? $order['lastName'] : $order['firstName'];
|
||||
$data['email'] = $mail ? $mail : uniqid() . '@retailrcm.ru';
|
||||
$data['comment'] = !empty($order['customerComment']) ? $order['customerComment'] : '';
|
||||
$data['payment_address'] = '0';
|
||||
$data['payment_firstname'] = $order['firstName'];
|
||||
$data['payment_lastname'] = isset($order['lastName']) ? $order['lastName'] : $order['firstName'];
|
||||
$data['payment_address_1'] = isset($order['customer']['address']) ? $order['customer']['address']['text'] : '';
|
||||
$data['payment_address_2'] = '';
|
||||
$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'];
|
||||
|
||||
$shippingZone = '';
|
||||
|
||||
if (is_int($order['delivery']['address']['region'])) {
|
||||
$shippingZone = $order['delivery']['address']['region'];
|
||||
} else {
|
||||
$shippingZone = $this->getZoneByName($order['delivery']['address']['region']);
|
||||
|
||||
if ($shippingZone) {
|
||||
$shipping_zone_id = $shippingZone['zone_id'];
|
||||
} else {
|
||||
$shipping_zone_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($order['customer']['address']['region'])) {
|
||||
$paymentZone = $this->getZoneByName($order['customer']['address']['region']);
|
||||
|
||||
if ($paymentZone) {
|
||||
$payment_zone_id = $paymentZone['zone_id'];
|
||||
} else {
|
||||
$payment_zone_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($order['countryIso']) && !empty($order['countryIso'])) {
|
||||
$shippingCountry = $this->getCountryByIsoCode($order['countryIso']);
|
||||
}
|
||||
|
||||
if (isset($order['customer']['address']['countryIso']) && !empty($order['customer']['address']['countryIso'])) {
|
||||
$paymentCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']);
|
||||
} else {
|
||||
$paymentCountry = $this->getCountryByIsoCode($order['countryIso']);
|
||||
}
|
||||
|
||||
$delivery = isset($order['delivery']['code']) ? $order['delivery']['code'] : null;
|
||||
$data['payment_country_id'] = $paymentCountry ? $paymentCountry['country_id'] : $ocOrder['payment_country_id'];
|
||||
$data['payment_country'] = isset($paymentCountry) ? $paymentCountry['name'] : $ocOrder['payment_country'];
|
||||
$data['payment_zone_id'] = $payment_zone_id ? $payment_zone_id : $ocOrder['payment_zone_id'];
|
||||
$data['payment_zone'] = isset($order['customer']['address']['region']) ? $order['customer']['address']['region'] : $ocOrder['payment_zone'];
|
||||
$data['shipping_country_id'] = isset($shippingCountry) ? $shippingCountry['country_id'] : $ocOrder['shipping_country_id'];
|
||||
$data['shipping_country'] = isset($shippingCountry) ? $shippingCountry['name'] : $ocOrder['shipping_country'];
|
||||
$data['shipping_zone_id'] = $shipping_zone_id ? $shipping_zone_id : $ocOrder['shipping_zone_id'];
|
||||
$data['shipping_zone'] = $shippingZone ? $shippingZone['name'] : $ocOrder['shipping_zone'];
|
||||
$data['shipping_address'] = '0';
|
||||
$data['shipping_firstname'] = $order['firstName'];
|
||||
$data['shipping_lastname'] = isset($order['lastName']) ? $order['lastName'] : $order['firstName'];
|
||||
$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'];
|
||||
|
||||
if ($delivery !== null) {
|
||||
if (isset($this->settings[\Retailcrm\Retailcrm::MODULE . '_delivery'][$ocOrder['shipping_code']])
|
||||
&& isset($this->delivery[$delivery])
|
||||
) {
|
||||
$data['shipping'] = $this->delivery[$delivery];
|
||||
|
||||
$shipping = explode('.', $data['shipping']);
|
||||
$shippingModule = $shipping[0];
|
||||
|
||||
if (isset($this->ocDelivery[$shippingModule][$data['shipping']]['title'])) {
|
||||
$data['shipping_method'] = $this->ocDelivery[$shippingModule][$data['shipping']]['title'];
|
||||
} else {
|
||||
$data['shipping_method'] = $this->ocDelivery[$shippingModule]['title'];
|
||||
}
|
||||
|
||||
$data['shipping_code'] = $data['shipping'];
|
||||
} elseif (!isset($this->settings[\Retailcrm\Retailcrm::MODULE . '_delivery'][$ocOrder['shipping_code']])
|
||||
) {
|
||||
$data['shipping_method'] = $ocOrder['shipping_method'];
|
||||
$data['shipping_code'] = $ocOrder['shipping_code'];
|
||||
}
|
||||
} else {
|
||||
if (!isset($this->settings[$ocOrder['shipping_code']])
|
||||
|| !isset($this->delivery[$delivery])
|
||||
) {
|
||||
$data['shipping_method'] = $ocOrder['shipping_method'];
|
||||
$data['shipping_code'] = $ocOrder['shipping_code'];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($payment)) {
|
||||
$data['payment'] = $this->payment[$payment['type']];
|
||||
$data['payment_method'] = isset($this->ocPayment[$data['payment']]) ? $this->ocPayment[$data['payment']] : $ocOrder['payment_method'];
|
||||
$data['payment_code'] = isset($this->payment[$payment['type']]) ? $this->payment[$payment['type']] : $ocOrder['payment_code'];
|
||||
} else {
|
||||
$data['payment_method'] = $ocOrder['payment_method'];
|
||||
$data['payment_code'] = $ocOrder['payment_code'];
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
$discount = false;
|
||||
|
||||
foreach ($order['items'] as $item) {
|
||||
$productId = $item['offer']['externalId'];
|
||||
$options = array();
|
||||
|
||||
if (isset($item['discountTotal']) && $item['discountTotal'] > 0) {
|
||||
$discount = true;
|
||||
}
|
||||
|
||||
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[] = array(
|
||||
'product_option_id' => $productOptionId,
|
||||
'product_option_value_id' => $productOptionValue['product_option_value_id'],
|
||||
'value' => $this->getOptionValue($productOptionValue['option_value_id'], 'name'),
|
||||
'type' => $productOption['type'],
|
||||
'name' => $productOption['name'],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$product = $this->model_catalog_product->getProduct($productId);
|
||||
$rewards = $this->model_catalog_product->getProductRewards($productId);
|
||||
|
||||
$data['order_product'][] = array(
|
||||
'name' => $product['name'],
|
||||
'model' => $product['model'],
|
||||
'price' => $item['initialPrice'],
|
||||
'total' => (float)($item['initialPrice'] * $item['quantity']),
|
||||
'product_id' => $productId,
|
||||
'quantity' => $item['quantity'],
|
||||
'option' => $options,
|
||||
'reward' => $rewards[$data['customer_group_id']]['points'] * $item['quantity']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->customFieldSetting) && $order['customFields']) {
|
||||
foreach ($order['customFields'] as $code => $value) {
|
||||
if (array_key_exists($code, $this->customFieldSetting)) {
|
||||
$fieldCode = str_replace('o_', '', $this->customFieldSetting[$code]);
|
||||
$customFields[$fieldCode] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$data['custom_field'] = isset($customFields) ? $customFields : '';
|
||||
} else {
|
||||
$data['custom_field'] = $ocOrder['custom_field'];
|
||||
}
|
||||
|
||||
$deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0;
|
||||
|
||||
$data['total'] = $order['totalSumm'];
|
||||
$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' => $data['shipping_method'],
|
||||
'value' => $deliveryCost,
|
||||
'text' => $deliveryCost,
|
||||
'sort_order' => $this->shippingSettings[$this->totalTitle . '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[$this->totalTitle . 'total_sort_order']
|
||||
)
|
||||
);
|
||||
|
||||
if ((isset($order['discount'])
|
||||
&& $order['discount'] > 0)
|
||||
|| $discount
|
||||
) {
|
||||
$orderTotals = $this->model_sale_order->getOrderTotals($order['externalId']);
|
||||
foreach ($orderTotals as $orderTotal) {
|
||||
if ($orderTotal['code'] == 'coupon'
|
||||
|| $orderTotal['code'] == 'reward'
|
||||
) {
|
||||
$data['order_total'][] = $orderTotal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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->editOrder($order['externalId'], $data);
|
||||
$this->opencartApiClient->addHistory($order['externalId'], $data['order_status_id']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total titles
|
||||
*
|
||||
* @return string $title
|
||||
*/
|
||||
protected function totalTitles()
|
||||
{
|
||||
if (version_compare(VERSION, '3.0', '<')) {
|
||||
$title = '';
|
||||
} else {
|
||||
$title = 'total_';
|
||||
}
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get country by iso code 2
|
||||
*
|
||||
* @param string $isoCode
|
||||
*
|
||||
* Create orders from history
|
||||
*
|
||||
* @param array $orders
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountryByIsoCode($isoCode)
|
||||
protected function createOrders($orders)
|
||||
{
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE iso_code_2 = '" . $isoCode . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
$customersIdsFix = array();
|
||||
$ordersIdsFix = array();
|
||||
|
||||
/**
|
||||
* Get zone by name
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getZoneByName($name)
|
||||
{
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE name = '" . $name . "'");
|
||||
foreach ($orders as $order) {
|
||||
$store = $this->config->get('config_store_id');
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
if (isset($order['payments']) && $order['payments']) {
|
||||
$payment = end($order['payments']);
|
||||
} elseif (isset($order['paymentType'])) {
|
||||
$payment['type'] = $order['paymentType'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get currency
|
||||
*
|
||||
* @param string $code
|
||||
* @param string $field (default = '')
|
||||
*
|
||||
* @return mixed array | string
|
||||
*/
|
||||
public function getCurrencyByCode($code, $field = '')
|
||||
{
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "currency` WHERE code = '" . $code . "'");
|
||||
$customer_id = (!empty($order['customer']['externalId']))
|
||||
? $order['customer']['externalId']
|
||||
: 0;
|
||||
|
||||
if (!$field) {
|
||||
return $query->row;
|
||||
$data = array();
|
||||
|
||||
if ($customer_id == 0) {
|
||||
if (isset($order['customer']['address']['countryIso'])) {
|
||||
$customerCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']);
|
||||
} else {
|
||||
$customerCountry = $this->getCountryByIsoCode($order['delivery']['address']['countryIso']);
|
||||
}
|
||||
|
||||
if (isset($order['customer']['address']['region'])) {
|
||||
$customerZone = $this->getZoneByName($order['customer']['address']['region']);
|
||||
} else {
|
||||
$customerZone = $this->getZoneByName($order['delivery']['address']['region']);
|
||||
}
|
||||
|
||||
$cData = array(
|
||||
'store_id' => 0,
|
||||
'customer_group_id' => '1',
|
||||
'firstname' => isset($order['patronymic']) ? $order['firstName'] . ' ' . $order['patronymic'] : $order['firstName'],
|
||||
'lastname' => (!empty($order['customer']['lastName'])) ? $order['customer']['lastName'] : ' ',
|
||||
'email' => $order['customer']['email'],
|
||||
'telephone' => $order['customer']['phones'] ? $order['customer']['phones'][0]['number'] : ' ',
|
||||
'fax' => '',
|
||||
'newsletter' => 0,
|
||||
'password' => 'tmppass',
|
||||
'status' => 1,
|
||||
'approved' => 1,
|
||||
'safe' => 0,
|
||||
'affiliate' => '',
|
||||
'address' => array(
|
||||
array(
|
||||
'firstname' => isset($order['patronymic']) ? $order['firstName'] . ' ' . $order['patronymic'] : $order['firstName'],
|
||||
'lastname' => (!empty($order['customer']['lastName'])) ? $order['customer']['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' => $customerZone ? $customerZone['zone_id'] : 0,
|
||||
'country_id' => $customerCountry ? $customerCountry['country_id'] : 0,
|
||||
'default' => '1'
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
$customer_id = $this->model_customer_customer->addCustomer($cData);
|
||||
|
||||
$customersIdsFix[] = array('id' => $order['customer']['id'], 'externalId' => (int)$customer_id);
|
||||
}
|
||||
|
||||
$mail = isset($order['email']) ? $order['email'] : $order['customer']['email'];
|
||||
$phone = isset($order['phone']) ? $order['phone'] : '';
|
||||
|
||||
if (!$phone) {
|
||||
$data['telephone'] = $order['customer']['phones'] ? $order['customer']['phones'][0]['number'] : '80000000000';
|
||||
} else {
|
||||
$data['telephone'] = $phone;
|
||||
}
|
||||
|
||||
$data['currency_code'] = $this->config->get('config_currency');
|
||||
$data['currency_value'] = $this->getCurrencyByCode($data['currency_code'], 'value');
|
||||
$data['currency_id'] = $this->getCurrencyByCode($data['currency_code'], 'currency_id');
|
||||
$data['language_id'] = $this->getLanguageByCode($this->config->get('config_language'), 'language_id');
|
||||
$data['store_id'] = $store == null ? 0 : $store;
|
||||
$data['store_name'] = $this->config->get('config_name');
|
||||
$data['customer'] = $order['firstName'];
|
||||
$data['customer_id'] = $customer_id;
|
||||
$data['customer_group_id'] = 1;
|
||||
$data['firstname'] = $order['firstName'];
|
||||
$data['lastname'] = (isset($order['lastName'])) ? $order['lastName'] : $order['firstName'];
|
||||
$data['email'] = $mail ? $mail : uniqid() . '@retailrcm.ru';
|
||||
$data['comment'] = !empty($order['customerComment']) ? $order['customerComment'] : '';
|
||||
$data['fax'] = '';
|
||||
$data['payment_address'] = '0';
|
||||
$data['payment_firstname'] = $order['firstName'];
|
||||
$data['payment_lastname'] = (isset($order['lastName'])) ? $order['lastName'] : $order['firstName'];
|
||||
$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'];
|
||||
|
||||
$shippingZone = '';
|
||||
|
||||
if (!empty($order['delivery']['address']['region']) && is_int($order['delivery']['address']['region'])) {
|
||||
$shippingZone = $order['delivery']['address']['region'];
|
||||
} else {
|
||||
$shippingZone = $this->getZoneByName($order['delivery']['address']['region']);
|
||||
|
||||
if ($shippingZone) {
|
||||
$shipping_zone_id = $shippingZone['zone_id'];
|
||||
} else {
|
||||
$shipping_zone_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($order['customer']['address']['region'])) {
|
||||
$paymentZone = $this->getZoneByName($order['customer']['address']['region']);
|
||||
|
||||
if ($paymentZone) {
|
||||
$payment_zone_id = $paymentZone['zone_id'];
|
||||
} else {
|
||||
$payment_zone_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($order['countryIso'])) {
|
||||
$shippingCountry = $this->getCountryByIsoCode($order['countryIso']);
|
||||
}
|
||||
|
||||
if (isset($order['customer']['address']['countryIso'])) {
|
||||
$paymentCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']);
|
||||
}
|
||||
|
||||
$delivery = isset($order['delivery']['code']) ? $order['delivery']['code'] : null;
|
||||
$data['payment_country_id'] = $paymentCountry ? $paymentCountry['country_id'] : 0;
|
||||
$data['payment_country'] = isset($paymentCountry) ? $paymentCountry['name'] : '';
|
||||
$data['payment_zone_id'] = $payment_zone_id;
|
||||
$data['payment_zone'] = isset($order['customer']['address']['region']) ? $order['customer']['address']['region'] : '';
|
||||
$data['shipping_country_id'] = isset($shippingCountry) ? $shippingCountry['country_id'] : 0;
|
||||
$data['shipping_country'] = isset($shippingCountry) ? $shippingCountry['name'] : '';
|
||||
$data['shipping_zone_id'] = $shipping_zone_id;
|
||||
$data['shipping_zone'] = $shippingZone ? $shippingZone['name'] : $data['payment_zone'];
|
||||
$data['shipping_address'] = '0';
|
||||
$data['shipping_firstname'] = $order['firstName'];
|
||||
$data['shipping_lastname'] = (isset($order['lastName'])) ? $order['lastName'] : $order['firstName'];
|
||||
$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'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default;
|
||||
$data['shipping_code'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default;
|
||||
|
||||
$shipping = explode('.', $data['shipping']);
|
||||
$shippingModule = $shipping[0];
|
||||
|
||||
if (isset($this->ocDelivery[$shippingModule][$data['shipping']]['title'])) {
|
||||
$data['shipping_method'] = $this->ocDelivery[$shippingModule][$data['shipping']]['title'];
|
||||
} else {
|
||||
$data['shipping_method'] = $this->ocDelivery[$shippingModule]['title'];
|
||||
}
|
||||
|
||||
if (isset($payment)) {
|
||||
$data['payment'] = $this->payment[$payment['type']];
|
||||
$data['payment_method'] = $this->ocPayment[$data['payment']];
|
||||
$data['payment_code'] = $this->payment[$payment['type']];
|
||||
} else {
|
||||
$data['payment'] = $this->payment_default;
|
||||
$data['payment_method'] = $this->ocPayment[$data['payment']];
|
||||
$data['payment_code'] = $this->payment_default;
|
||||
}
|
||||
|
||||
// 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'] = 0;
|
||||
$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) {
|
||||
$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[] = array(
|
||||
'product_option_id' => $productOptionId,
|
||||
'product_option_value_id' => $productOptionValue['product_option_value_id'],
|
||||
'value' => $this->getOptionValue($productOptionValue['option_value_id'], 'name'),
|
||||
'type' => $productOption['type'],
|
||||
'name' => $productOption['name'],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$product = $this->model_catalog_product->getProduct($productId);
|
||||
$rewards = $this->model_catalog_product->getProductRewards($productId);
|
||||
|
||||
$data['order_product'][] = array(
|
||||
'name' => $product['name'],
|
||||
'model' => $product['model'],
|
||||
'price' => $item['initialPrice'],
|
||||
'total' => (float)($item['initialPrice'] * $item['quantity']),
|
||||
'product_id' => $productId,
|
||||
'quantity' => $item['quantity'],
|
||||
'option' => $options,
|
||||
'reward' => $rewards[$data['customer_group_id']]['points'] * $item['quantity']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->customFieldSetting) && $order['customFields']) {
|
||||
foreach ($order['customFields'] as $code => $value) {
|
||||
if (array_key_exists($code, $this->customFieldSetting)) {
|
||||
$fieldCode = str_replace('o_', '', $this->customFieldSetting[$code]);
|
||||
$customFields[$fieldCode] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$data['custom_field'] = isset($customFields) ? $customFields : '';
|
||||
}
|
||||
|
||||
$deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0;
|
||||
|
||||
$data['total'] = $order['totalSumm'];
|
||||
$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' => $data['shipping_method'],
|
||||
'value' => $deliveryCost,
|
||||
'text' => $deliveryCost,
|
||||
'sort_order' => $this->shippingSettings[$this->totalTitle . '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[$this->totalTitle . 'total_sort_order']
|
||||
)
|
||||
);
|
||||
|
||||
$data['fromApi'] = true;
|
||||
$data['order_status_id'] = 1;
|
||||
|
||||
$order_id = $this->addOrder($data);
|
||||
|
||||
$ordersIdsFix[] = array('id' => $order['id'], 'externalId' => (int) $order_id);
|
||||
}
|
||||
|
||||
return $query->row[$field];
|
||||
return array('customers' => $customersIdsFix, 'orders' => $ordersIdsFix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language
|
||||
*
|
||||
* @param string $code
|
||||
* @param string $field (default = '')
|
||||
*
|
||||
* @return mixed array | string
|
||||
*/
|
||||
public function getLanguageByCode($code, $field = '')
|
||||
protected function updateCustomers($customers)
|
||||
{
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE code = '" . $code . "'");
|
||||
foreach ($customers as $customer) {
|
||||
$customer_id = $customer['externalId'];
|
||||
$customerData = $this->model_customer_customer->getCustomer($customer_id);
|
||||
$customerData['password'] = false;
|
||||
|
||||
if (!$field) {
|
||||
return $query->row;
|
||||
$customerData['firstname'] = $customer['firstName'];
|
||||
$customerData['lastname'] = isset($customer['lastName']) ? $customer['lastName'] : '';
|
||||
$customerData['email'] = $customer['email'];
|
||||
$customerData['telephone'] = $customer['phones'] ? $customer['phones'][0]['number'] : '';
|
||||
|
||||
$customerAddress = $this->model_customer_customer->getAddress($customerData['address_id']);
|
||||
|
||||
if (isset($customer['address']['countryIso'])) {
|
||||
$customerCountry = $this->getCountryByIsoCode($customer['address']['countryIso']);
|
||||
}
|
||||
|
||||
if (isset($customer['address']['region'])) {
|
||||
$customerZone = $this->getZoneByName($customer['address']['region']);
|
||||
}
|
||||
|
||||
$customerAddress['firstname'] = isset($customer['patronymic']) ? $customer['firstName'] . ' ' . $customer['patronymic'] : $customer['firstName'];
|
||||
$customerAddress['lastname'] = isset($customer['lastName']) ? $customer['lastName'] : '';
|
||||
$customerAddress['address_1'] = $customer['address']['text'];
|
||||
$customerAddress['city'] = $customer['address']['city'];
|
||||
$customerAddress['postcode'] = isset($customer['address']['index']) ? $customer['address']['index'] : '';
|
||||
|
||||
if (isset($customerCountry)) {
|
||||
$customerAddress['country_id'] = $customerCountry['country_id'];
|
||||
}
|
||||
|
||||
if (isset($customerZone) && isset($customerZone['zone_id'])) {
|
||||
$customerAddress['zone_id'] = $customerZone['zone_id'];
|
||||
}
|
||||
|
||||
$customerData['address'] = array($customerAddress);
|
||||
|
||||
if (isset($this->customFieldSetting) && $customer['customFields']) {
|
||||
foreach ($customer['customFields'] as $code => $value) {
|
||||
if (array_key_exists($code, $this->customFieldSetting)) {
|
||||
$fieldCode = str_replace('c_', '', $this->customFieldSetting[$code]);
|
||||
$customFields[$fieldCode] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$customerData['custom_field'] = isset($customFields) ? $customFields : '';
|
||||
}
|
||||
|
||||
$this->model_customer_customer->editCustomer($customer_id, $customerData);
|
||||
}
|
||||
|
||||
return $query->row[$field];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get product option value
|
||||
*
|
||||
* @param int $option_value_id
|
||||
* @param string $field
|
||||
*
|
||||
* @return mixed array | string
|
||||
*/
|
||||
public function getOptionValue($option_value_id, $field = '')
|
||||
{
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "option_value_description` WHERE option_value_id = '" . $option_value_id . "'");
|
||||
|
||||
if (!$field) {
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
return $query->row[$field];
|
||||
}
|
||||
}
|
||||
|
@ -1,117 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once 'v4_5.php';
|
||||
|
||||
class ModelExtensionRetailcrmHistoryV3 extends ModelExtensionRetailcrmHistoryV45
|
||||
{
|
||||
protected $createResult;
|
||||
|
||||
/**
|
||||
* Getting changes from RetailCRM
|
||||
*
|
||||
* @param \RetailcrmProxy $retailcrmApiClient
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function request($retailcrmApiClient)
|
||||
{
|
||||
$moduleTitle = $this->retailcrm->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;
|
||||
}
|
||||
|
||||
$lastRun = !empty($history['retailcrm_history_datetime'])
|
||||
? new DateTime($history['retailcrm_history_datetime'])
|
||||
: new DateTime(date('Y-m-d H:i:s', strtotime('-1 days', strtotime(date('Y-m-d H:i:s')))));
|
||||
|
||||
$packsOrders = $retailcrmApiClient->ordersHistory($lastRun);
|
||||
|
||||
if(!$packsOrders->isSuccessful() && count($packsOrders['orders']) <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$generatedAt = $packsOrders['generatedAt'];
|
||||
|
||||
$this->totalTitle = $this->totalTitles();
|
||||
$this->subtotalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'sub_total');
|
||||
$this->totalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'total');
|
||||
$this->shippingSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'shipping');
|
||||
$this->delivery = array_flip($settings[$moduleTitle . '_delivery']);
|
||||
$this->payment = array_flip($settings[$moduleTitle . '_payment']);
|
||||
$this->status = array_flip($settings[$moduleTitle . '_status']);
|
||||
$this->payment_default = $settings[$moduleTitle . '_default_payment'];
|
||||
$this->delivery_default = $settings[$moduleTitle . '_default_shipping'];
|
||||
$this->ocPayment = $this->model_extension_retailcrm_references
|
||||
->getOpercartPaymentTypes();
|
||||
|
||||
$this->ocDelivery = $this->model_extension_retailcrm_references
|
||||
->getOpercartDeliveryTypes();
|
||||
|
||||
$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 = $retailcrmApiClient->ordersList($filter = array('ids' => $newOrders));
|
||||
if ($orders) {
|
||||
$this->createResult = $this->createOrders($orders['orders']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($updatedOrders)) {
|
||||
$orders = $retailcrmApiClient->ordersList($filter = array('ids' => $updatedOrders));
|
||||
if ($orders) {
|
||||
$this->updateOrders($orders['orders']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->model_setting_setting->editSetting('retailcrm_history', array('retailcrm_history_datetime' => $generatedAt));
|
||||
|
||||
if (!empty($this->createResult['customers'])) {
|
||||
$retailcrmApiClient->customersFixExternalIds($this->createResult['customers']);
|
||||
}
|
||||
|
||||
if (!empty($this->createResult['orders'])) {
|
||||
$retailcrmApiClient->ordersFixExternalIds($this->createResult['orders']);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,827 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../history.php';
|
||||
|
||||
class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory
|
||||
{
|
||||
protected $createResult;
|
||||
protected $settings;
|
||||
protected $moduleTitle;
|
||||
protected $opencartApiClient;
|
||||
|
||||
private $customFieldSetting;
|
||||
|
||||
public function __construct($registry)
|
||||
{
|
||||
parent::__construct($registry);
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
$this->moduleTitle = $this->retailcrm->getModuleTitle();
|
||||
$this->opencartApiClient = $this->retailcrm->getOcApiClient($registry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getting changes from RetailCRM
|
||||
* @param \RetailcrmProxy $retailcrmApiClient
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function request($retailcrmApiClient)
|
||||
{
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
$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($this->moduleTitle);
|
||||
$history = $this->model_setting_setting->getSetting('retailcrm_history');
|
||||
$settings['domain'] = parse_url(HTTP_SERVER, PHP_URL_HOST);
|
||||
|
||||
$url = isset($settings[$this->moduleTitle . '_url']) ? $settings[$this->moduleTitle . '_url'] : null;
|
||||
$key = isset($settings[$this->moduleTitle . '_apikey']) ? $settings[$this->moduleTitle . '_apikey'] : null;
|
||||
|
||||
if (empty($url) || empty($key)) {
|
||||
$this->log->addNotice('You need to configure retailcrm module first.');
|
||||
return false;
|
||||
}
|
||||
|
||||
$sinceIdOrders = $history['retailcrm_history_orders'] ? $history['retailcrm_history_orders'] : null;
|
||||
$sinceIdCustomers = $history['retailcrm_history_customers'] ? $history['retailcrm_history_customers'] : null;
|
||||
|
||||
$packsOrders = $retailcrmApiClient->ordersHistory(array(
|
||||
'sinceId' => $sinceIdOrders ? $sinceIdOrders : 0
|
||||
), 1, 100);
|
||||
$packsCustomers = $retailcrmApiClient->customersHistory(array(
|
||||
'sinceId' => $sinceIdCustomers ? $sinceIdCustomers : 0
|
||||
), 1, 100);
|
||||
|
||||
if(!$packsOrders->isSuccessful() && count($packsOrders->history) <= 0 && !$packsCustomers->isSuccessful() && count($packsCustomers->history) <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$generatedAt = $packsOrders['generatedAt'];
|
||||
$orders = RetailcrmHistoryHelper::assemblyOrder($packsOrders->history);
|
||||
$customers = RetailcrmHistoryHelper::assemblyCustomer($packsCustomers->history);
|
||||
|
||||
$ordersHistory = $packsOrders->history;
|
||||
$customersHistory = $packsCustomers->history;
|
||||
|
||||
$lastChangeOrders = $ordersHistory ? end($ordersHistory) : null;
|
||||
$lastChangeCustomers = $customersHistory ? end($customersHistory) : null;
|
||||
|
||||
if ($lastChangeOrders !== null) {
|
||||
$sinceIdOrders = $lastChangeOrders['id'];
|
||||
}
|
||||
|
||||
if ($lastChangeCustomers !== null) {
|
||||
$sinceIdCustomers = $lastChangeCustomers['id'];
|
||||
}
|
||||
|
||||
$this->settings = $settings;
|
||||
$this->totalTitle = $this->totalTitles();
|
||||
$this->subtotalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'sub_total');
|
||||
$this->totalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'total');
|
||||
$this->shippingSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'shipping');
|
||||
|
||||
$this->delivery = array_flip($settings[$this->moduleTitle . '_delivery']);
|
||||
$this->payment = array_flip($settings[$this->moduleTitle . '_payment']);
|
||||
$this->status = array_flip($settings[$this->moduleTitle . '_status']);
|
||||
$this->delivery_default = $settings[$this->moduleTitle . '_default_shipping'];
|
||||
$this->payment_default = $settings[$this->moduleTitle . '_default_payment'];
|
||||
$this->ocPayment = $this->model_extension_retailcrm_references
|
||||
->getOpercartPaymentTypes();
|
||||
|
||||
$this->ocDelivery = $this->model_extension_retailcrm_references
|
||||
->getOpercartDeliveryTypes();
|
||||
|
||||
$this->zones = $this->model_localisation_zone->getZones();
|
||||
|
||||
if (isset($settings[$this->moduleTitle . '_custom_field'])) {
|
||||
$this->customFieldSetting = array_flip($settings[$this->moduleTitle . '_custom_field']);
|
||||
}
|
||||
|
||||
$updatedOrders = array();
|
||||
$newOrders = array();
|
||||
|
||||
foreach ($orders as $order) {
|
||||
|
||||
if (isset($order['deleted'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($order['externalId'])) {
|
||||
$updatedOrders[] = $order['id'];
|
||||
} else {
|
||||
$newOrders[] = $order['id'];
|
||||
}
|
||||
}
|
||||
|
||||
unset($orders);
|
||||
|
||||
$updateCustomers = array();
|
||||
|
||||
foreach ($customers as $customer) {
|
||||
|
||||
if (isset($customer['deleted'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($customer['externalId'])) {
|
||||
$updateCustomers[] = $customer['id'];
|
||||
}
|
||||
}
|
||||
|
||||
unset($customers);
|
||||
|
||||
if (!empty($updateCustomers)) {
|
||||
$customers = $retailcrmApiClient->customersList($filter = array('ids' => $updateCustomers));
|
||||
if ($customers) {
|
||||
$this->updateCustomers($customers['customers']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($newOrders)) {
|
||||
$orders = $retailcrmApiClient->ordersList($filter = array('ids' => $newOrders));
|
||||
if ($orders) {
|
||||
$this->createResult = $this->createOrders($orders['orders']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($updatedOrders)) {
|
||||
$orders = $retailcrmApiClient->ordersList($filter = array('ids' => $updatedOrders));
|
||||
if ($orders) {
|
||||
$this->updateOrders($orders['orders']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->model_setting_setting->editSetting(
|
||||
'retailcrm_history',
|
||||
array(
|
||||
'retailcrm_history_orders' => $sinceIdOrders,
|
||||
'retailcrm_history_customers' => $sinceIdCustomers,
|
||||
'retailcrm_history_datetime' => $generatedAt
|
||||
)
|
||||
);
|
||||
|
||||
if (!empty($this->createResult['customers'])) {
|
||||
$retailcrmApiClient->customersFixExternalIds($this->createResult['customers']);
|
||||
}
|
||||
|
||||
if (!empty($this->createResult['orders'])) {
|
||||
$retailcrmApiClient->ordersFixExternalIds($this->createResult['orders']);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update orders from history
|
||||
*
|
||||
* @param array $orders
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function updateOrders($orders)
|
||||
{
|
||||
foreach ($orders as $order) {
|
||||
$ocOrder = $this->model_sale_order->getOrder($order['externalId']);
|
||||
|
||||
if (isset($order['payments']) && $order['payments']) {
|
||||
foreach ($order['payments'] as $orderPayment) {
|
||||
if (isset($orderPayment['externalId'])) {
|
||||
$payment = $orderPayment;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($payment) && count($order['payments']) == 1) {
|
||||
$payment = end($order['payments']);
|
||||
}
|
||||
} elseif (isset($order['paymentType'])) {
|
||||
$payment['type'] = $order['paymentType'];
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
$mail = isset($order['email']) ? $order['email'] : $order['customer']['email'];
|
||||
$phone = isset($order['phone']) ? $order['phone'] : '';
|
||||
|
||||
if (!$phone) {
|
||||
$data['telephone'] = $order['customer']['phones'] ? $order['customer']['phones'][0]['number'] : '80000000000';
|
||||
} else {
|
||||
$data['telephone'] = $phone;
|
||||
}
|
||||
|
||||
if (isset($order['customer']['externalId']) && $order['customer']['externalId']) {
|
||||
$customer = $this->model_customer_customer->getCustomer($order['customer']['externalId']);
|
||||
}
|
||||
|
||||
$data['customer'] = $order['firstName'];
|
||||
$data['customer_id'] = (isset($customer)) ? $customer['customer_id'] : 0;
|
||||
$data['customer_group_id'] = (isset($customer)) ? $customer['customer_group_id'] : 1;
|
||||
$data['firstname'] = $order['firstName'];
|
||||
$data['lastname'] = isset($order['lastName']) ? $order['lastName'] : $order['firstName'];
|
||||
$data['email'] = $mail ? $mail : uniqid() . '@retailrcm.ru';
|
||||
$data['comment'] = !empty($order['customerComment']) ? $order['customerComment'] : '';
|
||||
$data['payment_address'] = '0';
|
||||
$data['payment_firstname'] = $order['firstName'];
|
||||
$data['payment_lastname'] = isset($order['lastName']) ? $order['lastName'] : $order['firstName'];
|
||||
$data['payment_address_1'] = isset($order['customer']['address']) ? $order['customer']['address']['text'] : '';
|
||||
$data['payment_address_2'] = '';
|
||||
$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'];
|
||||
|
||||
$shippingZone = '';
|
||||
|
||||
if (is_int($order['delivery']['address']['region'])) {
|
||||
$shippingZone = $order['delivery']['address']['region'];
|
||||
} else {
|
||||
$shippingZone = $this->getZoneByName($order['delivery']['address']['region']);
|
||||
|
||||
if ($shippingZone) {
|
||||
$shipping_zone_id = $shippingZone['zone_id'];
|
||||
} else {
|
||||
$shipping_zone_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($order['customer']['address']['region'])) {
|
||||
$paymentZone = $this->getZoneByName($order['customer']['address']['region']);
|
||||
|
||||
if ($paymentZone) {
|
||||
$payment_zone_id = $paymentZone['zone_id'];
|
||||
} else {
|
||||
$payment_zone_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($order['countryIso']) && !empty($order['countryIso'])) {
|
||||
$shippingCountry = $this->getCountryByIsoCode($order['countryIso']);
|
||||
}
|
||||
|
||||
if (isset($order['customer']['address']['countryIso']) && !empty($order['customer']['address']['countryIso'])) {
|
||||
$paymentCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']);
|
||||
} else {
|
||||
$paymentCountry = $this->getCountryByIsoCode($order['countryIso']);
|
||||
}
|
||||
|
||||
$delivery = isset($order['delivery']['code']) ? $order['delivery']['code'] : null;
|
||||
$data['payment_country_id'] = $paymentCountry ? $paymentCountry['country_id'] : $ocOrder['payment_country_id'];
|
||||
$data['payment_country'] = isset($paymentCountry) ? $paymentCountry['name'] : $ocOrder['payment_country'];
|
||||
$data['payment_zone_id'] = $payment_zone_id ? $payment_zone_id : $ocOrder['payment_zone_id'];
|
||||
$data['payment_zone'] = isset($order['customer']['address']['region']) ? $order['customer']['address']['region'] : $ocOrder['payment_zone'];
|
||||
$data['shipping_country_id'] = isset($shippingCountry) ? $shippingCountry['country_id'] : $ocOrder['shipping_country_id'];
|
||||
$data['shipping_country'] = isset($shippingCountry) ? $shippingCountry['name'] : $ocOrder['shipping_country'];
|
||||
$data['shipping_zone_id'] = $shipping_zone_id ? $shipping_zone_id : $ocOrder['shipping_zone_id'];
|
||||
$data['shipping_zone'] = $shippingZone ? $shippingZone['name'] : $ocOrder['shipping_zone'];
|
||||
$data['shipping_address'] = '0';
|
||||
$data['shipping_firstname'] = $order['firstName'];
|
||||
$data['shipping_lastname'] = isset($order['lastName']) ? $order['lastName'] : $order['firstName'];
|
||||
$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'];
|
||||
|
||||
if ($delivery !== null) {
|
||||
if (isset($this->settings[$this->moduleTitle . '_delivery'][$ocOrder['shipping_code']])
|
||||
&& isset($this->delivery[$delivery])
|
||||
) {
|
||||
$data['shipping'] = $this->delivery[$delivery];
|
||||
|
||||
$shipping = explode('.', $data['shipping']);
|
||||
$shippingModule = $shipping[0];
|
||||
|
||||
if (isset($this->ocDelivery[$shippingModule][$data['shipping']]['title'])) {
|
||||
$data['shipping_method'] = $this->ocDelivery[$shippingModule][$data['shipping']]['title'];
|
||||
} else {
|
||||
$data['shipping_method'] = $this->ocDelivery[$shippingModule]['title'];
|
||||
}
|
||||
|
||||
$data['shipping_code'] = $data['shipping'];
|
||||
} elseif (!isset($this->settings[$this->moduleTitle . '_delivery'][$ocOrder['shipping_code']])
|
||||
) {
|
||||
$data['shipping_method'] = $ocOrder['shipping_method'];
|
||||
$data['shipping_code'] = $ocOrder['shipping_code'];
|
||||
}
|
||||
} else {
|
||||
if (!isset($this->settings[$ocOrder['shipping_code']])
|
||||
|| !isset($this->delivery[$delivery])
|
||||
) {
|
||||
$data['shipping_method'] = $ocOrder['shipping_method'];
|
||||
$data['shipping_code'] = $ocOrder['shipping_code'];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($payment)) {
|
||||
$data['payment'] = $this->payment[$payment['type']];
|
||||
$data['payment_method'] = isset($this->ocPayment[$data['payment']]) ? $this->ocPayment[$data['payment']] : $ocOrder['payment_method'];
|
||||
$data['payment_code'] = isset($this->payment[$payment['type']]) ? $this->payment[$payment['type']] : $ocOrder['payment_code'];
|
||||
} else {
|
||||
$data['payment_method'] = $ocOrder['payment_method'];
|
||||
$data['payment_code'] = $ocOrder['payment_code'];
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
$discount = false;
|
||||
|
||||
foreach ($order['items'] as $item) {
|
||||
$productId = $item['offer']['externalId'];
|
||||
$options = array();
|
||||
|
||||
if (isset($item['discountTotal']) && $item['discountTotal'] > 0) {
|
||||
$discount = true;
|
||||
}
|
||||
|
||||
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[] = array(
|
||||
'product_option_id' => $productOptionId,
|
||||
'product_option_value_id' => $productOptionValue['product_option_value_id'],
|
||||
'value' => $this->getOptionValue($productOptionValue['option_value_id'], 'name'),
|
||||
'type' => $productOption['type'],
|
||||
'name' => $productOption['name'],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$product = $this->model_catalog_product->getProduct($productId);
|
||||
$rewards = $this->model_catalog_product->getProductRewards($productId);
|
||||
|
||||
$data['order_product'][] = array(
|
||||
'name' => $product['name'],
|
||||
'model' => $product['model'],
|
||||
'price' => $item['initialPrice'],
|
||||
'total' => (float)($item['initialPrice'] * $item['quantity']),
|
||||
'product_id' => $productId,
|
||||
'quantity' => $item['quantity'],
|
||||
'option' => $options,
|
||||
'reward' => $rewards[$data['customer_group_id']]['points'] * $item['quantity']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->customFieldSetting) && $order['customFields']) {
|
||||
foreach ($order['customFields'] as $code => $value) {
|
||||
if (array_key_exists($code, $this->customFieldSetting)) {
|
||||
$fieldCode = str_replace('o_', '', $this->customFieldSetting[$code]);
|
||||
$customFields[$fieldCode] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$data['custom_field'] = isset($customFields) ? $customFields : '';
|
||||
} else {
|
||||
$data['custom_field'] = $ocOrder['custom_field'];
|
||||
}
|
||||
|
||||
$deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0;
|
||||
|
||||
$data['total'] = $order['totalSumm'];
|
||||
$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' => $data['shipping_method'],
|
||||
'value' => $deliveryCost,
|
||||
'text' => $deliveryCost,
|
||||
'sort_order' => $this->shippingSettings[$this->totalTitle . '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[$this->totalTitle . 'total_sort_order']
|
||||
)
|
||||
);
|
||||
|
||||
if ((isset($order['discount'])
|
||||
&& $order['discount'] > 0)
|
||||
|| $discount
|
||||
) {
|
||||
$orderTotals = $this->model_sale_order->getOrderTotals($order['externalId']);
|
||||
foreach ($orderTotals as $orderTotal) {
|
||||
if ($orderTotal['code'] == 'coupon'
|
||||
|| $orderTotal['code'] == 'reward'
|
||||
) {
|
||||
$data['order_total'][] = $orderTotal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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->editOrder($order['externalId'], $data);
|
||||
$this->opencartApiClient->addHistory($order['externalId'], $data['order_status_id']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create orders from history
|
||||
*
|
||||
* @param array $orders
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function createOrders($orders)
|
||||
{
|
||||
$customersIdsFix = array();
|
||||
$ordersIdsFix = array();
|
||||
|
||||
foreach ($orders as $order) {
|
||||
$store = $this->config->get('config_store_id');
|
||||
|
||||
if (isset($order['payments']) && $order['payments']) {
|
||||
$payment = end($order['payments']);
|
||||
} elseif (isset($order['paymentType'])) {
|
||||
$payment['type'] = $order['paymentType'];
|
||||
}
|
||||
|
||||
$customer_id = (!empty($order['customer']['externalId']))
|
||||
? $order['customer']['externalId']
|
||||
: 0;
|
||||
|
||||
$data = array();
|
||||
|
||||
if ($customer_id == 0) {
|
||||
if (isset($order['customer']['address']['countryIso'])) {
|
||||
$customerCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']);
|
||||
} else {
|
||||
$customerCountry = $this->getCountryByIsoCode($order['delivery']['address']['countryIso']);
|
||||
}
|
||||
|
||||
if (isset($order['customer']['address']['region'])) {
|
||||
$customerZone = $this->getZoneByName($order['customer']['address']['region']);
|
||||
} else {
|
||||
$customerZone = $this->getZoneByName($order['delivery']['address']['region']);
|
||||
}
|
||||
|
||||
$cData = array(
|
||||
'store_id' => 0,
|
||||
'customer_group_id' => '1',
|
||||
'firstname' => isset($order['patronymic']) ? $order['firstName'] . ' ' . $order['patronymic'] : $order['firstName'],
|
||||
'lastname' => (!empty($order['customer']['lastName'])) ? $order['customer']['lastName'] : ' ',
|
||||
'email' => $order['customer']['email'],
|
||||
'telephone' => $order['customer']['phones'] ? $order['customer']['phones'][0]['number'] : ' ',
|
||||
'fax' => '',
|
||||
'newsletter' => 0,
|
||||
'password' => 'tmppass',
|
||||
'status' => 1,
|
||||
'approved' => 1,
|
||||
'safe' => 0,
|
||||
'affiliate' => '',
|
||||
'address' => array(
|
||||
array(
|
||||
'firstname' => isset($order['patronymic']) ? $order['firstName'] . ' ' . $order['patronymic'] : $order['firstName'],
|
||||
'lastname' => (!empty($order['customer']['lastName'])) ? $order['customer']['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' => $customerZone ? $customerZone['zone_id'] : 0,
|
||||
'country_id' => $customerCountry ? $customerCountry['country_id'] : 0,
|
||||
'default' => '1'
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
$customer_id = $this->model_customer_customer->addCustomer($cData);
|
||||
|
||||
$customersIdsFix[] = array('id' => $order['customer']['id'], 'externalId' => (int)$customer_id);
|
||||
}
|
||||
|
||||
$mail = isset($order['email']) ? $order['email'] : $order['customer']['email'];
|
||||
$phone = isset($order['phone']) ? $order['phone'] : '';
|
||||
|
||||
if (!$phone) {
|
||||
$data['telephone'] = $order['customer']['phones'] ? $order['customer']['phones'][0]['number'] : '80000000000';
|
||||
} else {
|
||||
$data['telephone'] = $phone;
|
||||
}
|
||||
|
||||
$data['currency_code'] = $this->config->get('config_currency');
|
||||
$data['currency_value'] = $this->getCurrencyByCode($data['currency_code'], 'value');
|
||||
$data['currency_id'] = $this->getCurrencyByCode($data['currency_code'], 'currency_id');
|
||||
$data['language_id'] = $this->getLanguageByCode($this->config->get('config_language'), 'language_id');
|
||||
$data['store_id'] = $store == null ? 0 : $store;
|
||||
$data['store_name'] = $this->config->get('config_name');
|
||||
$data['customer'] = $order['firstName'];
|
||||
$data['customer_id'] = $customer_id;
|
||||
$data['customer_group_id'] = 1;
|
||||
$data['firstname'] = $order['firstName'];
|
||||
$data['lastname'] = (isset($order['lastName'])) ? $order['lastName'] : $order['firstName'];
|
||||
$data['email'] = $mail ? $mail : uniqid() . '@retailrcm.ru';
|
||||
$data['comment'] = !empty($order['customerComment']) ? $order['customerComment'] : '';
|
||||
$data['fax'] = '';
|
||||
$data['payment_address'] = '0';
|
||||
$data['payment_firstname'] = $order['firstName'];
|
||||
$data['payment_lastname'] = (isset($order['lastName'])) ? $order['lastName'] : $order['firstName'];
|
||||
$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'];
|
||||
|
||||
$shippingZone = '';
|
||||
|
||||
if (!empty($order['delivery']['address']['region']) && is_int($order['delivery']['address']['region'])) {
|
||||
$shippingZone = $order['delivery']['address']['region'];
|
||||
} else {
|
||||
$shippingZone = $this->getZoneByName($order['delivery']['address']['region']);
|
||||
|
||||
if ($shippingZone) {
|
||||
$shipping_zone_id = $shippingZone['zone_id'];
|
||||
} else {
|
||||
$shipping_zone_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($order['customer']['address']['region'])) {
|
||||
$paymentZone = $this->getZoneByName($order['customer']['address']['region']);
|
||||
|
||||
if ($paymentZone) {
|
||||
$payment_zone_id = $paymentZone['zone_id'];
|
||||
} else {
|
||||
$payment_zone_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($order['countryIso'])) {
|
||||
$shippingCountry = $this->getCountryByIsoCode($order['countryIso']);
|
||||
}
|
||||
|
||||
if (isset($order['customer']['address']['countryIso'])) {
|
||||
$paymentCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']);
|
||||
}
|
||||
|
||||
$delivery = isset($order['delivery']['code']) ? $order['delivery']['code'] : null;
|
||||
$data['payment_country_id'] = $paymentCountry ? $paymentCountry['country_id'] : 0;
|
||||
$data['payment_country'] = isset($paymentCountry) ? $paymentCountry['name'] : '';
|
||||
$data['payment_zone_id'] = $payment_zone_id;
|
||||
$data['payment_zone'] = isset($order['customer']['address']['region']) ? $order['customer']['address']['region'] : '';
|
||||
$data['shipping_country_id'] = isset($shippingCountry) ? $shippingCountry['country_id'] : 0;
|
||||
$data['shipping_country'] = isset($shippingCountry) ? $shippingCountry['name'] : '';
|
||||
$data['shipping_zone_id'] = $shipping_zone_id;
|
||||
$data['shipping_zone'] = $shippingZone ? $shippingZone['name'] : $data['payment_zone'];
|
||||
$data['shipping_address'] = '0';
|
||||
$data['shipping_firstname'] = $order['firstName'];
|
||||
$data['shipping_lastname'] = (isset($order['lastName'])) ? $order['lastName'] : $order['firstName'];
|
||||
$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'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default;
|
||||
$data['shipping_code'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default;
|
||||
|
||||
$shipping = explode('.', $data['shipping']);
|
||||
$shippingModule = $shipping[0];
|
||||
|
||||
if (isset($this->ocDelivery[$shippingModule][$data['shipping']]['title'])) {
|
||||
$data['shipping_method'] = $this->ocDelivery[$shippingModule][$data['shipping']]['title'];
|
||||
} else {
|
||||
$data['shipping_method'] = $this->ocDelivery[$shippingModule]['title'];
|
||||
}
|
||||
|
||||
if (isset($payment)) {
|
||||
$data['payment'] = $this->payment[$payment['type']];
|
||||
$data['payment_method'] = $this->ocPayment[$data['payment']];
|
||||
$data['payment_code'] = $this->payment[$payment['type']];
|
||||
} else {
|
||||
$data['payment'] = $this->payment_default;
|
||||
$data['payment_method'] = $this->ocPayment[$data['payment']];
|
||||
$data['payment_code'] = $this->payment_default;
|
||||
}
|
||||
|
||||
// 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'] = 0;
|
||||
$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) {
|
||||
$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[] = array(
|
||||
'product_option_id' => $productOptionId,
|
||||
'product_option_value_id' => $productOptionValue['product_option_value_id'],
|
||||
'value' => $this->getOptionValue($productOptionValue['option_value_id'], 'name'),
|
||||
'type' => $productOption['type'],
|
||||
'name' => $productOption['name'],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$product = $this->model_catalog_product->getProduct($productId);
|
||||
$rewards = $this->model_catalog_product->getProductRewards($productId);
|
||||
|
||||
$data['order_product'][] = array(
|
||||
'name' => $product['name'],
|
||||
'model' => $product['model'],
|
||||
'price' => $item['initialPrice'],
|
||||
'total' => (float)($item['initialPrice'] * $item['quantity']),
|
||||
'product_id' => $productId,
|
||||
'quantity' => $item['quantity'],
|
||||
'option' => $options,
|
||||
'reward' => $rewards[$data['customer_group_id']]['points'] * $item['quantity']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->customFieldSetting) && $order['customFields']) {
|
||||
foreach ($order['customFields'] as $code => $value) {
|
||||
if (array_key_exists($code, $this->customFieldSetting)) {
|
||||
$fieldCode = str_replace('o_', '', $this->customFieldSetting[$code]);
|
||||
$customFields[$fieldCode] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$data['custom_field'] = isset($customFields) ? $customFields : '';
|
||||
}
|
||||
|
||||
$deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0;
|
||||
|
||||
$data['total'] = $order['totalSumm'];
|
||||
$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' => $data['shipping_method'],
|
||||
'value' => $deliveryCost,
|
||||
'text' => $deliveryCost,
|
||||
'sort_order' => $this->shippingSettings[$this->totalTitle . '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[$this->totalTitle . 'total_sort_order']
|
||||
)
|
||||
);
|
||||
|
||||
$data['fromApi'] = true;
|
||||
$data['order_status_id'] = 1;
|
||||
|
||||
$order_id = $this->addOrder($data);
|
||||
|
||||
$ordersIdsFix[] = array('id' => $order['id'], 'externalId' => (int) $order_id);
|
||||
}
|
||||
|
||||
return array('customers' => $customersIdsFix, 'orders' => $ordersIdsFix);
|
||||
}
|
||||
|
||||
protected function updateCustomers($customers)
|
||||
{
|
||||
foreach ($customers as $customer) {
|
||||
$customer_id = $customer['externalId'];
|
||||
$customerData = $this->model_customer_customer->getCustomer($customer_id);
|
||||
$customerData['password'] = false;
|
||||
|
||||
$customerData['firstname'] = $customer['firstName'];
|
||||
$customerData['lastname'] = isset($customer['lastName']) ? $customer['lastName'] : '';
|
||||
$customerData['email'] = $customer['email'];
|
||||
$customerData['telephone'] = $customer['phones'] ? $customer['phones'][0]['number'] : '';
|
||||
|
||||
$customerAddress = $this->model_customer_customer->getAddress($customerData['address_id']);
|
||||
|
||||
if (isset($customer['address']['countryIso'])) {
|
||||
$customerCountry = $this->getCountryByIsoCode($customer['address']['countryIso']);
|
||||
}
|
||||
|
||||
if (isset($customer['address']['region'])) {
|
||||
$customerZone = $this->getZoneByName($customer['address']['region']);
|
||||
}
|
||||
|
||||
$customerAddress['firstname'] = isset($customer['patronymic']) ? $customer['firstName'] . ' ' . $customer['patronymic'] : $customer['firstName'];
|
||||
$customerAddress['lastname'] = isset($customer['lastName']) ? $customer['lastName'] : '';
|
||||
$customerAddress['address_1'] = $customer['address']['text'];
|
||||
$customerAddress['city'] = $customer['address']['city'];
|
||||
$customerAddress['postcode'] = isset($customer['address']['index']) ? $customer['address']['index'] : '';
|
||||
|
||||
if (isset($customerCountry)) {
|
||||
$customerAddress['country_id'] = $customerCountry['country_id'];
|
||||
}
|
||||
|
||||
if (isset($customerZone) && isset($customerZone['zone_id'])) {
|
||||
$customerAddress['zone_id'] = $customerZone['zone_id'];
|
||||
}
|
||||
|
||||
$customerData['address'] = array($customerAddress);
|
||||
|
||||
if (isset($this->customFieldSetting) && $customer['customFields']) {
|
||||
foreach ($customer['customFields'] as $code => $value) {
|
||||
if (array_key_exists($code, $this->customFieldSetting)) {
|
||||
$fieldCode = str_replace('c_', '', $this->customFieldSetting[$code]);
|
||||
$customFields[$fieldCode] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$customerData['custom_field'] = isset($customFields) ? $customFields : '';
|
||||
}
|
||||
|
||||
$this->model_customer_customer->editCustomer($customer_id, $customerData);
|
||||
}
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ class ModelExtensionRetailcrmIcml extends Model
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*
|
||||
* @param Registry $registry
|
||||
*/
|
||||
public function __construct($registry)
|
||||
@ -267,7 +267,7 @@ class ModelExtensionRetailcrmIcml extends Model
|
||||
private function generateImage($image)
|
||||
{
|
||||
$this->load->model('tool/image');
|
||||
|
||||
|
||||
$currentTheme = $this->config->get('config_theme');
|
||||
$width = $this->config->get($currentTheme . '_image_related_width') ? $this->config->get($currentTheme . '_image_related_width') : 200;
|
||||
$height = $this->config->get($currentTheme . '_image_related_height') ? $this->config->get($currentTheme . '_image_related_height') : 200;
|
||||
|
@ -1,305 +1,188 @@
|
||||
<?php
|
||||
|
||||
class ModelExtensionRetailcrmOrder extends Model {
|
||||
protected $settings;
|
||||
protected $moduleTitle;
|
||||
protected $retailcrmApiClient;
|
||||
|
||||
protected static $lastRepsonse = null;
|
||||
|
||||
public function __construct($registry)
|
||||
{
|
||||
parent::__construct($registry);
|
||||
$this->load->model('setting/setting');
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
|
||||
$this->moduleTitle = $this->retailcrm->getModuleTitle();
|
||||
$this->settings = $this->model_setting_setting->getSetting($this->moduleTitle);
|
||||
}
|
||||
|
||||
class ModelExtensionRetailcrmOrder extends Model
|
||||
{
|
||||
/**
|
||||
* Upload orders to CRM
|
||||
* Create order in OC
|
||||
*
|
||||
* @param array $orders
|
||||
* @param \RetailcrmProxy $retailcrmApiClient
|
||||
* @param array $order
|
||||
*
|
||||
* @return mixed
|
||||
* @return int $order_id
|
||||
*/
|
||||
public function uploadToCrm($orders, $retailcrmApiClient)
|
||||
public function addOrder($order)
|
||||
{
|
||||
if ($retailcrmApiClient === false) {
|
||||
return false;
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET store_id = '" . (int)$order['store_id'] . "', store_name = '" . $order['store_name'] . "', customer_id = '" . (int)$order['customer_id'] . "', customer_group_id = '" . (int)$order['customer_group_id'] . "', firstname = '" . $this->db->escape($order['firstname']) . "', lastname = '" . $this->db->escape($order['lastname']) . "', email = '" . $this->db->escape($order['email']) . "', telephone = '" . $this->db->escape($order['telephone']) . "', custom_field = '" . $this->db->escape(isset($order['custom_field']) ? json_encode($order['custom_field']) : '') . "', payment_firstname = '" . $this->db->escape($order['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($order['payment_lastname']) . "', payment_address_1 = '" . $this->db->escape($order['payment_address_1']) . "', payment_city = '" . $this->db->escape($order['payment_city']) . "', payment_postcode = '" . $this->db->escape($order['payment_postcode']) . "', payment_country = '" . $this->db->escape($order['payment_country']) . "', payment_country_id = '" . (int)$order['payment_country_id'] . "', payment_zone = '" . $this->db->escape($order['payment_zone']) . "', payment_zone_id = '" . (int)$order['payment_zone_id'] . "', payment_method = '" . $this->db->escape($order['payment_method']) . "', payment_code = '" . $this->db->escape($order['payment_code']) . "', shipping_firstname = '" . $this->db->escape($order['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($order['shipping_lastname']) . "', shipping_address_1 = '" . $this->db->escape($order['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($order['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($order['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($order['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($order['shipping_country']) . "', shipping_country_id = '" . (int)$order['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($order['shipping_zone']) . "', shipping_zone_id = '" . (int)$order['shipping_zone_id'] . "', shipping_method = '" . $this->db->escape($order['shipping_method']) . "', shipping_code = '" . $this->db->escape($order['shipping_code']) . "', comment = '" . $this->db->escape($order['comment']) . "', total = '" . (float)$order['total'] . "', affiliate_id = '" . (int)$order['affiliate_id'] . "', language_id = '" . (int)$order['language_id'] . "', currency_id = '" . (int)$order['currency_id'] . "', currency_code = '" . $this->db->escape($order['currency_code']) . "', currency_value = '" . (float)$order['currency_value'] . "', order_status_id = '" . (int)$order['order_status_id'] . "', date_added = NOW(), date_modified = NOW()");
|
||||
|
||||
$order_id = $this->db->getLastId();
|
||||
|
||||
// Products
|
||||
if (isset($order['order_product']) && $order['order_product']) {
|
||||
$this->addOrderProducts($order_id, $order['order_product']);
|
||||
}
|
||||
|
||||
$ordersToCrm = array();
|
||||
|
||||
foreach ($orders as $order) {
|
||||
$ordersToCrm[] = $this->process($order);
|
||||
// Totals
|
||||
if (isset($order['order_total'])) {
|
||||
$this->addOrderTotals($order_id, $order['order_total']);
|
||||
}
|
||||
|
||||
$chunkedOrders = array_chunk($ordersToCrm, 50);
|
||||
|
||||
foreach($chunkedOrders as $ordersPart) {
|
||||
$retailcrmApiClient->ordersUpload($ordersPart);
|
||||
}
|
||||
|
||||
return $chunkedOrders;
|
||||
return $order_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send one order by id
|
||||
*
|
||||
* @param array $order_data
|
||||
* @param \RetailcrmProxy $retailcrmApiClient
|
||||
* Edit order in OC
|
||||
*
|
||||
* @return mixed
|
||||
* @param int $order_id
|
||||
* @param array $order
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function uploadOrder($order_data, $retailcrmApiClient)
|
||||
public function editOrder($order_id, $order)
|
||||
{
|
||||
if ($retailcrmApiClient === false) {
|
||||
return false;
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "order` SET customer_id = '" . (int)$order['customer_id'] . "', customer_group_id = '" . (int)$order['customer_group_id'] . "', firstname = '" . $this->db->escape($order['firstname']) . "', lastname = '" . $this->db->escape($order['lastname']) . "', email = '" . $this->db->escape($order['email']) . "', telephone = '" . $this->db->escape($order['telephone']) . "', custom_field = '" . $this->db->escape(json_encode($order['custom_field'])) . "', payment_firstname = '" . $this->db->escape($order['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($order['payment_lastname']) . "', payment_address_1 = '" . $this->db->escape($order['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($order['payment_address_2']) . "', payment_city = '" . $this->db->escape($order['payment_city']) . "', payment_postcode = '" . $this->db->escape($order['payment_postcode']) . "', payment_country = '" . $this->db->escape($order['payment_country']) . "', payment_country_id = '" . (int)$order['payment_country_id'] . "', payment_zone = '" . $this->db->escape($order['payment_zone']) . "', payment_zone_id = '" . (int)$order['payment_zone_id'] . "', payment_method = '" . $this->db->escape($order['payment_method']) . "', payment_code = '" . $this->db->escape($order['payment_code']) . "', shipping_firstname = '" . $this->db->escape($order['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($order['shipping_lastname']) . "', shipping_address_1 = '" . $this->db->escape($order['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($order['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($order['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($order['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($order['shipping_country']) . "', shipping_country_id = '" . (int)$order['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($order['shipping_zone']) . "', shipping_zone_id = '" . (int)$order['shipping_zone_id'] . "', shipping_method = '" . $this->db->escape($order['shipping_method']) . "', shipping_code = '" . $this->db->escape($order['shipping_code']) . "', comment = '" . $this->db->escape($order['comment']) . "', total = '" . (float)$order['total'] . "', order_status_id = '" . (int)$order['order_status_id'] . "', date_modified = NOW() WHERE order_id = '" . (int)$order_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
|
||||
|
||||
// Products
|
||||
if (isset($order['order_product']) && $order['order_product']) {
|
||||
$this->addOrderProducts($order_id, $order['order_product']);
|
||||
}
|
||||
|
||||
if (isset($this->request->post['fromApi'])) {
|
||||
return false;
|
||||
// Totals
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "'");
|
||||
|
||||
if (isset($order['order_total'])) {
|
||||
$this->addOrderTotals($order_id, $order['order_total']);
|
||||
}
|
||||
|
||||
$order = $this->process($order_data);
|
||||
|
||||
if (isset($order['customer']['externalId'])) {
|
||||
$this->load->model('extension/retailcrm/customer');
|
||||
$this->load->model('customer/customer');
|
||||
$customer = $this->model_customer_customer->getCustomer($order['customer']['externalId']);
|
||||
$this->model_extension_retailcrm_customer->sendToCrm($customer, $retailcrmApiClient);
|
||||
} else {
|
||||
$customers = $retailcrmApiClient->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);
|
||||
}
|
||||
|
||||
self::$lastRepsonse = $retailcrmApiClient->ordersCreate($order);
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process order
|
||||
*
|
||||
* @param array $order_data
|
||||
*
|
||||
* @return array $order
|
||||
* Add order products
|
||||
*
|
||||
* @param int $order_id
|
||||
* @param array $products
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function process($order_data) {
|
||||
$order = array();
|
||||
public function addOrderProducts($order_id, $products)
|
||||
{
|
||||
foreach ($products as $product) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_id = '" . (int)$order_id . "', product_id = '" . (int)$product['product_id'] . "', name = '" . $this->db->escape($product['name']) . "', model = '" . $this->db->escape($product['model']) . "', quantity = '" . (int)$product['quantity'] . "', price = '" . (float)$product['price'] . "', total = '" . (float)$product['total'] . "', reward = '" . (float)$product['reward'] . "'");
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
$order_product_id = $this->db->getLastId();
|
||||
|
||||
if (!empty($order_data['payment_code']) && isset($this->settings[$this->moduleTitle . '_payment'][$order_data['payment_code']])) {
|
||||
$payment_code = $this->settings[$this->moduleTitle . '_payment'][$order_data['payment_code']];
|
||||
} else {
|
||||
$payment_code = '';
|
||||
}
|
||||
|
||||
if (!empty($order_data['shipping_code'])) {
|
||||
$shippingCode = explode('.', $order_data['shipping_code']);
|
||||
$shippingModule = $shippingCode[0];
|
||||
|
||||
if (isset($this->settings[$this->moduleTitle . '_delivery'][$order_data['shipping_code']])) {
|
||||
$delivery_code = $this->settings[$this->moduleTitle . '_delivery'][$order_data['shipping_code']];
|
||||
} elseif (isset($this->settings[$this->moduleTitle . '_delivery'][$shippingModule])) {
|
||||
$delivery_code = $this->settings[$this->moduleTitle . '_delivery'][$shippingModule];
|
||||
foreach ($product['option'] as $option) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "order_option SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', product_option_id = '" . (int)$option['product_option_id'] . "', product_option_value_id = '" . (int)$option['product_option_value_id'] . "', name = '" . $this->db->escape($option['name']) . "', `value` = '" . $this->db->escape($option['value']) . "', `type` = '" . $this->db->escape($option['type']) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($delivery_code) && isset($shippingModule)) {
|
||||
if (isset($this->settings[$this->moduleTitle . '_delivery'])
|
||||
&& $this->settings[$this->moduleTitle . '_delivery']
|
||||
) {
|
||||
$deliveries = array_keys($this->settings[$this->moduleTitle . '_delivery']);
|
||||
$shipping_code = '';
|
||||
|
||||
array_walk($deliveries, function($item, $key) use ($shippingModule, &$shipping_code) {
|
||||
if (strripos($item, $shippingModule) !== false) {
|
||||
$shipping_code = $item;
|
||||
}
|
||||
});
|
||||
|
||||
$delivery_code = $this->settings[$this->moduleTitle . '_delivery'][$shipping_code];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($order_data['payment_iso_code_2'])) {
|
||||
$order['countryIso'] = $order_data['payment_iso_code_2'];
|
||||
}
|
||||
|
||||
if (isset($this->settings[$this->moduleTitle . '_order_number'])
|
||||
&& $this->settings[$this->moduleTitle . '_order_number'] == 1
|
||||
) {
|
||||
$order['number'] = $order_data['order_id'];
|
||||
}
|
||||
|
||||
$order['externalId'] = $order_data['order_id'];
|
||||
$order['firstName'] = $order_data['firstname'];
|
||||
$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'];
|
||||
}
|
||||
|
||||
if ($order_data['customer_id']) {
|
||||
$order['customer']['externalId'] = $order_data['customer_id'];
|
||||
}
|
||||
|
||||
$deliveryCost = 0;
|
||||
$orderTotals = isset($order_data['totals']) ? $order_data['totals'] : $order_data['order_total'] ;
|
||||
|
||||
foreach ($orderTotals as $totals) {
|
||||
if ($totals['code'] == 'shipping') {
|
||||
$deliveryCost = $totals['value'];
|
||||
}
|
||||
}
|
||||
|
||||
$order['createdAt'] = $order_data['date_added'];
|
||||
|
||||
if ($this->settings[$this->moduleTitle . '_apiversion'] != 'v5') {
|
||||
$order['paymentType'] = $payment_code;
|
||||
}
|
||||
|
||||
$country = (isset($order_data['shipping_country'])) ? $order_data['shipping_country'] : '' ;
|
||||
|
||||
$order['delivery'] = array(
|
||||
'code' => isset($delivery_code) ? $delivery_code : '',
|
||||
'cost' => $deliveryCost,
|
||||
'address' => array(
|
||||
'countryIso' => $order_data['shipping_iso_code_2'],
|
||||
'index' => $order_data['shipping_postcode'],
|
||||
'city' => $order_data['shipping_city'],
|
||||
'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'];
|
||||
$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);
|
||||
}
|
||||
|
||||
if ($this->settings[$this->moduleTitle . '_apiversion'] != 'v3') {
|
||||
$item = array(
|
||||
'offer' => array(
|
||||
'externalId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id']
|
||||
),
|
||||
'productName' => $product['name'],
|
||||
'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;
|
||||
}
|
||||
|
||||
if (isset($order_data['order_status_id']) && $order_data['order_status_id'] > 0) {
|
||||
$order['status'] = $this->settings[$this->moduleTitle . '_status'][$order_data['order_status_id']];
|
||||
}
|
||||
|
||||
if ($this->settings[$this->moduleTitle . '_apiversion'] == 'v5') {
|
||||
if ($payment_code) {
|
||||
$payment = array(
|
||||
'externalId' => $order_data['order_id'],
|
||||
'type' => $payment_code
|
||||
);
|
||||
|
||||
$order['payments'][] = $payment;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->settings[$this->moduleTitle . '_custom_field']) && $order_data['custom_field']) {
|
||||
$customFields = json_decode($order_data['custom_field']);
|
||||
|
||||
foreach ($customFields as $key => $value) {
|
||||
if (isset($this->settings[$this->moduleTitle . '_custom_field']['o_' . $key])) {
|
||||
$customFieldsToCrm[$this->settings[$this->moduleTitle . '_custom_field']['o_' . $key]] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($customFieldsToCrm)) {
|
||||
$order['customFields'] = $customFieldsToCrm;
|
||||
}
|
||||
}
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* Add order totals
|
||||
*
|
||||
* @param int $order_id
|
||||
* @param array $totals
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function getLastResponse()
|
||||
public function addOrderTotals($order_id, $totals)
|
||||
{
|
||||
return self::$lastRepsonse;
|
||||
foreach ($totals as $total) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "order_total SET order_id = '" . (int)$order_id . "', code = '" . $this->db->escape($total['code']) . "', title = '" . $this->db->escape($total['title']) . "', `value` = '" . (float)$total['value'] . "', sort_order = '" . (int)$total['sort_order'] . "'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total titles
|
||||
*
|
||||
* @return string $title
|
||||
*/
|
||||
protected function totalTitles()
|
||||
{
|
||||
return 'total_';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get country by iso code 2
|
||||
*
|
||||
* @param string $isoCode
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountryByIsoCode($isoCode)
|
||||
{
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE iso_code_2 = '" . $isoCode . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get zone by name
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getZoneByName($name)
|
||||
{
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE name = '" . $name . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get currency
|
||||
*
|
||||
* @param string $code
|
||||
* @param string $field (default = '')
|
||||
*
|
||||
* @return mixed array | string
|
||||
*/
|
||||
public function getCurrencyByCode($code, $field = '')
|
||||
{
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "currency` WHERE code = '" . $code . "'");
|
||||
|
||||
if (!$field) {
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
return $query->row[$field];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language
|
||||
*
|
||||
* @param string $code
|
||||
* @param string $field (default = '')
|
||||
*
|
||||
* @return mixed array | string
|
||||
*/
|
||||
public function getLanguageByCode($code, $field = '')
|
||||
{
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE code = '" . $code . "'");
|
||||
|
||||
if (!$field) {
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
return $query->row[$field];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get product option value
|
||||
*
|
||||
* @param int $option_value_id
|
||||
* @param string $field
|
||||
*
|
||||
* @return mixed array | string
|
||||
*/
|
||||
public function getOptionValue($option_value_id, $field = '')
|
||||
{
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "option_value_description` WHERE option_value_id = '" . $option_value_id . "'");
|
||||
|
||||
if (!$field) {
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
return $query->row[$field];
|
||||
}
|
||||
}
|
||||
|
@ -3,45 +3,34 @@
|
||||
class ModelExtensionRetailcrmPrices extends Model
|
||||
{
|
||||
protected $settings;
|
||||
protected $moduleTitle;
|
||||
|
||||
private $options;
|
||||
private $optionValues;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Registry $registry
|
||||
* Upload prices to CRM
|
||||
*
|
||||
* @param array $products
|
||||
* @param \RetailcrmProxy $retailcrm_api_client
|
||||
* @param \Retailcrm\Retailcrm $retailcrm
|
||||
*
|
||||
* @return mixed bool | array
|
||||
*/
|
||||
public function __construct($registry)
|
||||
public function uploadPrices($products, $retailcrm_api_client, $retailcrm)
|
||||
{
|
||||
parent::__construct($registry);
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
$this->load->model('catalog/option');
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$this->moduleTitle = $this->retailcrm->getModuleTitle();
|
||||
$this->settings = $this->model_setting_setting->getSetting($this->moduleTitle);
|
||||
}
|
||||
$prices = $this->getPrices($products, $retailcrm_api_client, $retailcrm);
|
||||
|
||||
/**
|
||||
* Upload prices to CRM
|
||||
*
|
||||
* @param array $products
|
||||
* @param \RetailcrmProxy $retailcrmApiClient
|
||||
* @return mixed bool | array
|
||||
*/
|
||||
public function uploadPrices($products, $retailcrmApiClient)
|
||||
{
|
||||
$prices = $this->getPrices($products, $retailcrmApiClient);
|
||||
|
||||
if ($retailcrmApiClient === false || !$prices) {
|
||||
if ($retailcrm_api_client === false || !$prices) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$pricesUpload = array_chunk($prices, 250);
|
||||
|
||||
foreach ($pricesUpload as $priceUpload) {
|
||||
$retailcrmApiClient->storePricesUpload($priceUpload);
|
||||
$retailcrm_api_client->storePricesUpload($priceUpload);
|
||||
}
|
||||
|
||||
return $pricesUpload;
|
||||
@ -49,18 +38,21 @@ class ModelExtensionRetailcrmPrices extends Model
|
||||
|
||||
/**
|
||||
* Get prices
|
||||
*
|
||||
*
|
||||
* @param array $products
|
||||
*
|
||||
* @param \RetailcrmProxy $retailcrm_api_client
|
||||
* @param \Retailcrm\Retailcrm $retailcrm
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getPrices($products, $retailcrmApiClient)
|
||||
protected function getPrices($products, $retailcrm_api_client, $retailcrm)
|
||||
{
|
||||
$prices = array();
|
||||
$site = $this->getSite($retailcrmApiClient);
|
||||
$settings = $this->model_setting_setting->getSetting(\retailcrm\Retailcrm::MODULE);
|
||||
|
||||
if (!isset($this->settings[$this->moduleTitle . '_special'])
|
||||
|| $this->settings[$this->moduleTitle . '_apiversion'] == 'v3'
|
||||
$prices = array();
|
||||
$site = $this->getSite($retailcrm_api_client);
|
||||
|
||||
if (!isset($settings[\Retailcrm\Retailcrm::MODULE . '_special'])
|
||||
|| $settings[\Retailcrm\Retailcrm::MODULE . '_apiversion'] == 'v3'
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
@ -80,7 +72,7 @@ class ModelExtensionRetailcrmPrices extends Model
|
||||
}
|
||||
}
|
||||
|
||||
$offers = $this->retailcrm->getOffers($product);
|
||||
$offers = $retailcrm->getOffers($product);
|
||||
|
||||
foreach ($offers as $optionsString => $optionsValues) {
|
||||
$optionsString = explode('_', $optionsString);
|
||||
@ -115,7 +107,7 @@ class ModelExtensionRetailcrmPrices extends Model
|
||||
'site' => $site,
|
||||
'prices' => array(
|
||||
array(
|
||||
'code' => $this->settings[$this->moduleTitle . '_special'],
|
||||
'code' => $settings[\Retailcrm\Retailcrm::MODULE . '_special'],
|
||||
'price' => $productPrice + $optionsValues['price']
|
||||
)
|
||||
)
|
||||
@ -128,9 +120,9 @@ class ModelExtensionRetailcrmPrices extends Model
|
||||
|
||||
/**
|
||||
* Get actual special
|
||||
*
|
||||
*
|
||||
* @param array $specials
|
||||
*
|
||||
*
|
||||
* @return float $productPrice
|
||||
*/
|
||||
private function getSpecialPrice($specials)
|
||||
@ -157,10 +149,10 @@ class ModelExtensionRetailcrmPrices extends Model
|
||||
|
||||
/**
|
||||
* Get data option
|
||||
*
|
||||
*
|
||||
* @param int $optionId
|
||||
* @param int $optionValueId
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getOptionData($optionId, $optionValueId) {
|
||||
@ -191,9 +183,9 @@ class ModelExtensionRetailcrmPrices extends Model
|
||||
*
|
||||
* @return mixed boolean | string
|
||||
*/
|
||||
private function getSite($retailcrmApiClient)
|
||||
private function getSite($retailcrm_api_client)
|
||||
{
|
||||
$response = $retailcrmApiClient->sitesList();
|
||||
$response = $retailcrm_api_client->sitesList();
|
||||
|
||||
if ($response && $response->isSuccessful()) {
|
||||
$sites = $response->sites;
|
||||
|
9
src/upload/admin/model/extension/retailcrm/products.php
Normal file
9
src/upload/admin/model/extension/retailcrm/products.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
class ModelExtensionRetailcrmProducts extends Model {
|
||||
public function getProductOptions($product_id) {
|
||||
$this->load->model('catalog/product_option');
|
||||
|
||||
return $this->model_catalog_product_option->getProductOptionsByProductId($product_id);
|
||||
}
|
||||
}
|
@ -1,93 +1,72 @@
|
||||
<?php
|
||||
|
||||
class ModelExtensionRetailcrmReferences extends Model
|
||||
{
|
||||
protected $settings;
|
||||
protected $moduleTitle;
|
||||
protected $retailcrmApiClient;
|
||||
|
||||
private $opencartApiClient;
|
||||
|
||||
public function __construct($registry)
|
||||
{
|
||||
parent::__construct($registry);
|
||||
$this->load->model('setting/setting');
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
|
||||
$this->moduleTitle = $this->retailcrm->getModuleTitle();
|
||||
$this->settings = $this->model_setting_setting->getSetting($this->moduleTitle);
|
||||
$this->retailcrmApiClient = $this->retailcrm->getApiClient();
|
||||
}
|
||||
class ModelExtensionRetailcrmReferences extends Model {
|
||||
|
||||
/**
|
||||
* Get opencart delivery methods
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOpercartDeliveryTypes()
|
||||
public function getOpercartDeliveryTypes($opencart_api_client)
|
||||
{
|
||||
$this->opencartApiClient = $this->retailcrm->getOcApiClient($this->registry);
|
||||
|
||||
return $this->opencartApiClient->getDeliveryTypes();
|
||||
return $opencart_api_client->getDeliveryTypes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all delivery types
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDeliveryTypes()
|
||||
public function getDeliveryTypes($opencart_api_client, $retailcrm_api_client)
|
||||
{
|
||||
$this->load->model('setting/store');
|
||||
|
||||
return array(
|
||||
'opencart' => $this->getOpercartDeliveryTypes(),
|
||||
'retailcrm' => $this->getApiDeliveryTypes()
|
||||
'opencart' => $this->getOpercartDeliveryTypes($opencart_api_client),
|
||||
'retailcrm' => $this->getApiDeliveryTypes($retailcrm_api_client)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all statuses
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOrderStatuses()
|
||||
public function getOrderStatuses($retailcrm_api_client)
|
||||
{
|
||||
return array(
|
||||
'opencart' => $this->getOpercartOrderStatuses(),
|
||||
'retailcrm' => $this->getApiOrderStatuses()
|
||||
'retailcrm' => $this->getApiOrderStatuses($retailcrm_api_client)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all payment types
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPaymentTypes()
|
||||
public function getPaymentTypes($retailcrm_api_client)
|
||||
{
|
||||
return array(
|
||||
'opencart' => $this->getOpercartPaymentTypes(),
|
||||
'retailcrm' => $this->getApiPaymentTypes()
|
||||
'retailcrm' => $this->getApiPaymentTypes($retailcrm_api_client)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all custom fields
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomFields()
|
||||
public function getCustomFields($retailcrm_api_client)
|
||||
{
|
||||
return array(
|
||||
'opencart' => $this->getOpencartCustomFields(),
|
||||
'retailcrm' => $this->getApiCustomFields()
|
||||
'retailcrm' => $this->getApiCustomFields($retailcrm_api_client)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get opencart order statuses
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOpercartOrderStatuses()
|
||||
@ -100,7 +79,7 @@ class ModelExtensionRetailcrmReferences extends Model
|
||||
|
||||
/**
|
||||
* Get opencart payment types
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOpercartPaymentTypes()
|
||||
@ -113,7 +92,7 @@ class ModelExtensionRetailcrmReferences extends Model
|
||||
$extension = basename($file, '.php');
|
||||
|
||||
$this->load->language('extension/payment/' . $extension);
|
||||
|
||||
|
||||
if (version_compare(VERSION, '3.0', '<')) {
|
||||
$configStatus = $extension . '_status';
|
||||
} else {
|
||||
@ -133,80 +112,80 @@ class ModelExtensionRetailcrmReferences extends Model
|
||||
|
||||
/**
|
||||
* Get opencart custom fields
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOpencartCustomFields()
|
||||
{
|
||||
$this->load->model('customer/custom_field');
|
||||
|
||||
|
||||
return $this->model_customer_custom_field->getCustomFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get RetailCRM delivery types
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getApiDeliveryTypes()
|
||||
public function getApiDeliveryTypes($retailcrm_api_client)
|
||||
{
|
||||
$response = $this->retailcrmApiClient->deliveryTypesList();
|
||||
$response = $retailcrm_api_client->deliveryTypesList();
|
||||
|
||||
return (!$response->isSuccessful()) ? array() : $response->deliveryTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get RetailCRM order statuses
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getApiOrderStatuses()
|
||||
public function getApiOrderStatuses($retailcrm_api_client)
|
||||
{
|
||||
$response = $this->retailcrmApiClient->statusesList();
|
||||
$response = $retailcrm_api_client->statusesList();
|
||||
|
||||
return (!$response->isSuccessful()) ? array() : $response->statuses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get RetailCRM payment types
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getApiPaymentTypes()
|
||||
public function getApiPaymentTypes($retailcrm_api_client)
|
||||
{
|
||||
$response = $this->retailcrmApiClient->paymentTypesList();
|
||||
$response = $retailcrm_api_client->paymentTypesList();
|
||||
|
||||
return (!$response->isSuccessful()) ? array() : $response->paymentTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get RetailCRM custom fields
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getApiCustomFields()
|
||||
public function getApiCustomFields($retailcrm_api_client)
|
||||
{
|
||||
$customers = $this->retailcrmApiClient->customFieldsList(array('entity' => 'customer'));
|
||||
$orders = $this->retailcrmApiClient->customFieldsList(array('entity' => 'order'));
|
||||
$customers = $retailcrm_api_client->customFieldsList(array('entity' => 'customer'));
|
||||
$orders = $retailcrm_api_client->customFieldsList(array('entity' => 'order'));
|
||||
|
||||
$customFieldsCustomers = (!$customers->isSuccessful()) ? array() : $customers->customFields;
|
||||
$customFieldsOrders = (!$orders->isSuccessful()) ? array() : $orders->customFields;
|
||||
$custom_fields_customers = (!$customers->isSuccessful()) ? array() : $customers->customFields;
|
||||
$custom_fields_orders = (!$orders->isSuccessful()) ? array() : $orders->customFields;
|
||||
|
||||
if (!$customFieldsCustomers && !$customFieldsOrders) {
|
||||
if (!$custom_fields_customers && !$custom_fields_orders) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return array('customers' => $customFieldsCustomers, 'orders' => $customFieldsOrders);
|
||||
|
||||
return array('customers' => $custom_fields_customers, 'orders' => $custom_fields_orders);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get RetailCRM price types
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPriceTypes()
|
||||
public function getPriceTypes($retailcrm_api_client)
|
||||
{
|
||||
$response = $this->retailcrmApiClient->priceTypesList();
|
||||
$response = $retailcrm_api_client->priceTypesList();
|
||||
|
||||
return (!$response->isSuccessful()) ? array() : $response->priceTypes;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
.retailcrm_unit {margin-bottom: 10px;}
|
||||
.retailcrm_unit input {width: 30%;}
|
||||
.retailcrm_unit input {width: 60%;}
|
||||
.checkbox input{width: auto;}
|
||||
.retailcrm_unit input[type=checkbox] {width: 13px;}
|
||||
.retailcrm_unit select {max-width: 500px;}
|
@ -1,600 +0,0 @@
|
||||
<?php echo $header; ?><?php echo $column_left;?>
|
||||
<div id="content">
|
||||
<div class="page-header">
|
||||
<div class="container-fluid">
|
||||
<div class="pull-right">
|
||||
<?php if ($export_file) : ?>
|
||||
<button type="button" id="export" data-toggle="tooltip" title="<?php echo $text_button_export; ?>" class="btn btn-success"><i class="fa fa-download"></i></button>
|
||||
<?php endif; ?>
|
||||
<button type="button" id="icml" data-toggle="tooltip" title="<?php echo $text_button_catalog; ?>" class="btn btn-success"><i class="fa fa-file-text-o"></i></button>
|
||||
<button type="submit" form="form-retailcrm" data-toggle="tooltip" title="<?php echo $button_save; ?>" class="btn btn-primary"><i class="fa fa-save"></i></button>
|
||||
<a href="<?php echo $cancel; ?>" data-toggle="tooltip" title="<?php echo $button_cancel; ?>" class="btn btn-default"><i class="fa fa-reply"></i></a>
|
||||
</div>
|
||||
<h1><?php echo $heading_title; ?></h1>
|
||||
<ul class="breadcrumb">
|
||||
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
|
||||
<li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-fluid">
|
||||
<?php if ($error_warning) : ?>
|
||||
<div class="alert alert-danger">
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
<i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($saved_settings['retailcrm_url'])): ?>
|
||||
<div class="alert alert-info"><i class="fa fa-exclamation-circle"></i>
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
<?php echo $text_notice; ?>
|
||||
<a href="<?php echo $saved_settings['retailcrm_url']; ?>/admin/settings#t-main"><?php echo $saved_settings['retailcrm_url']; ?>/admin/settings#t-main</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-retailcrm" class="form-horizontal">
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a href="#tab-general" data-toggle="tab"><?php echo $general_tab_text; ?></a></li>
|
||||
<?php if (isset($saved_settings['retailcrm_apikey']) && $saved_settings['retailcrm_apikey'] != '' && isset($saved_settings['retailcrm_url']) && $saved_settings['retailcrm_url'] != ''): ?>
|
||||
<li><a href="#tab-references" data-toggle="tab"><?php echo $references_tab_text; ?></a></li>
|
||||
<li><a href="#tab-collector" data-toggle="tab"><?php echo $collector_tab_text; ?></a></li>
|
||||
<?php if ($saved_settings['retailcrm_apiversion'] == 'v5') : ?>
|
||||
<li><a href="#tab-custom_fields" data-toggle="tab"><?php echo $custom_fields_tab_text; ?></a></li>
|
||||
<?php endif; ?>
|
||||
<li><a href="#tab-logs" data-toggle="tab"><?php echo $logs_tab_text; ?></a></li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active" id="tab-general">
|
||||
<input type="hidden" name="retailcrm_status" value="1">
|
||||
<fieldset>
|
||||
<legend><?php echo $retailcrm_base_settings; ?></legend>
|
||||
<div class="form-group retailcrm_unit">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_url"><?php echo $retailcrm_apiversion; ?></label>
|
||||
<div class="col-lg-1 col-md-2 col-sm-2">
|
||||
<select name="retailcrm_apiversion" class="form-control">
|
||||
<?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>
|
||||
<div class="form-group retailcrm_unit">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_url"><?php echo $retailcrm_url; ?></label>
|
||||
<div class="col-lg-4 col-md-6 col-sm-10">
|
||||
<input id="retailcrm_url" type="text" name="retailcrm_url" value="<?php if (isset($saved_settings['retailcrm_url'])): echo $saved_settings['retailcrm_url']; endif; ?>" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group retailcrm_unit">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_apikey"><?php echo $retailcrm_apikey; ?></label>
|
||||
<div class="col-lg-4 col-md-6 col-sm-10">
|
||||
<input id="retailcrm_apikey" type="text" name="retailcrm_apikey" value="<?php if (isset($saved_settings['retailcrm_apikey'])): echo $saved_settings['retailcrm_apikey']; endif;?>" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend><?php echo $retailcrm_countries_settings; ?></legend>
|
||||
<div class="form-group retailcrm_unit">
|
||||
<label class="col-sm-2 control-label">Страны</label>
|
||||
<div class="col-lg-4 col-md-6 col-sm-10">
|
||||
<div class="well well-sm" style="height: 150px; overflow: auto;">
|
||||
<?php foreach($countries as $country) : ?>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name="<?php echo 'retailcrm_country[]'; ?>" value="<?php echo $country['country_id']; ?>" <?php if(isset($saved_settings['retailcrm_country']) && in_array($country['country_id'], $saved_settings['retailcrm_country'])): echo 'checked'; endif;?>>
|
||||
<?php echo $country['name']; ?>
|
||||
</label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php if (isset($saved_settings['retailcrm_apikey']) && $saved_settings['retailcrm_apikey'] != '' && isset($saved_settings['retailcrm_url']) && $saved_settings['retailcrm_url'] != ''): ?>
|
||||
<?php if (!empty($retailcrm_errors)) : ?>
|
||||
<?php foreach($retailcrm_errors as $retailcrm_error): ?>
|
||||
<div class="warning"><?php echo $retailcrm_error ?></div>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<fieldset>
|
||||
<legend><?php echo $retailcrm_upload_order; ?></legend>
|
||||
<div class="form-group retailcrm_unit">
|
||||
<label class="col-sm-2 control-label"><?php echo $text_button_export_order; ?> №</label>
|
||||
<div class="col-sm-10">
|
||||
<div class="row">
|
||||
<div class="col-lg-3 col-md-6 col-sm-6">
|
||||
<input type="text" name="order_id" class="form-control" />
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-4 col-sm-6">
|
||||
<button type="button" id="export_order" class="btn btn-success"><i class="fa fa-download"></i> <?php echo $text_button_export_order; ?></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php if (isset($saved_settings['retailcrm_apiversion']) && $saved_settings['retailcrm_apiversion'] != 'v3') : ?>
|
||||
<fieldset>
|
||||
<legend><?php echo $special_price_settings; ?></legend>
|
||||
<div class="form-group retailcrm_unit">
|
||||
<label class="col-sm-2 control-label"><?php echo $special_price_settings; ?></label>
|
||||
<div class="col-md-4 col-sm-10">
|
||||
<select id="retailcrm_special" name="retailcrm_special" class="form-control">
|
||||
<?php foreach ($priceTypes as $priceType) :?>
|
||||
<?php if ($priceType['active'] == true) :?>
|
||||
<option value="<?php echo $priceType['code']; ?>" <?php if(isset($saved_settings['retailcrm_special']) && $saved_settings['retailcrm_special'] == $priceType['code']):?>selected="selected"<?php endif;?>>
|
||||
<?php echo $priceType['name']; ?>
|
||||
</option>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php endif; ?>
|
||||
<fieldset>
|
||||
<legend><?php echo $order_number; ?></legend>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_order_number"><?php echo $text_order_number; ?></label>
|
||||
<div class="col-sm-10">
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="retailcrm_order_number" value="1" <?php if (isset($saved_settings['retailcrm_order_number']) &&
|
||||
$saved_settings['retailcrm_order_number'] == 1) :
|
||||
echo 'checked'; endif; ?> />
|
||||
<?php echo $text_yes; ?>
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="retailcrm_order_number" value="0" <?php if (!isset($saved_settings['retailcrm_order_number']) ||
|
||||
$saved_settings['retailcrm_order_number'] == 0) :
|
||||
echo 'checked'; endif; ?> />
|
||||
<?php echo $text_no; ?>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="tab-pane" id="tab-references">
|
||||
<fieldset>
|
||||
<legend><?php echo $retailcrm_dict_settings; ?></legend>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label"><?php echo $retailcrm_dict_delivery; ?></label>
|
||||
<div class="col-sm-10">
|
||||
<div class="row">
|
||||
<?php if ($delivery['opencart']) :?>
|
||||
<?php foreach($delivery['opencart'] as $value): ?>
|
||||
<div class="col-sm-12" style="margin-bottom:10px;">
|
||||
<div class="pm" style="margin-bottom:5px;"><?php echo $value['title'].':'; ?></div>
|
||||
<?php unset($value['title']); ?>
|
||||
<?php foreach ($value as $key => $val): ?>
|
||||
<div class="row retailcrm_unit">
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
<select id="retailcrm_delivery_<?php echo $val['code']; ?>" name="retailcrm_delivery[<?php echo $val['code']; ?>]" class="form-control">
|
||||
<?php foreach ($delivery['retailcrm'] as $k => $v): ?>
|
||||
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_delivery'][$key]) && $v['code'] == $saved_settings['retailcrm_delivery'][$key]):?>selected="selected"<?php endif;?>>
|
||||
<?php echo $v['name'];?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
<label class="control-label" style="text-align:left!important;" for="retailcrm_pm_<?php echo $val['code']; ?>"><?php echo $val['title']; ?></label>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php else :?>
|
||||
<div class="alert alert-info"><i class="fa fa-exclamation-circle"></i>
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
<?php echo $text_error_delivery; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label"><?php echo $retailcrm_dict_status; ?></label>
|
||||
<div class="col-sm-10">
|
||||
<?php foreach ($statuses['opencart'] as $status): ?>
|
||||
<?php $uid = $status['order_status_id']?>
|
||||
<div class="row retailcrm_unit">
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
<select id="retailcrm_status_<?php echo $uid; ?>" name="retailcrm_status[<?php echo $uid; ?>]" class="form-control">
|
||||
<?php foreach ($statuses['retailcrm'] as $k => $v): ?>
|
||||
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_status'][$uid]) && $v['code'] == $saved_settings['retailcrm_status'][$uid]):?>selected="selected"<?php endif;?>>
|
||||
<?php echo $v['name'];?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
<label class="control-label" style="text-align:left!important;" for="retailcrm_status_<?php echo $status['order_status_id']; ?>"><?php echo $status['name']; ?></label>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label"><?php echo $retailcrm_dict_payment; ?></label>
|
||||
<div class="col-sm-10">
|
||||
<?php foreach ($payments['opencart'] as $key => $value): ?>
|
||||
<div class="row retailcrm_unit">
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
<select id="retailcrm_payment_<?php echo $key; ?>" name="retailcrm_payment[<?php echo $key; ?>]" class="form-control">
|
||||
<?php foreach ($payments['retailcrm'] as $k => $v): ?>
|
||||
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_payment'][$key]) && $v['code'] == $saved_settings['retailcrm_payment'][$key]):?>selected="selected"<?php endif;?>>
|
||||
<?php echo $v['name'];?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
<label class="control-label" for="retailcrm_payment_<?php echo $key; ?>"><?php echo $value; ?></label>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label"><?php echo $retailcrm_dict_default; ?></label>
|
||||
<div class="col-sm-10">
|
||||
<div class="row">
|
||||
<div class="retailcrm_unit col-sm-12">
|
||||
<div class="row">
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
<select id="retailcrm_default_payment" name="retailcrm_default_payment" class="form-control">
|
||||
<?php foreach ($payments['opencart'] as $k => $v): ?>
|
||||
<option value="<?php echo $k;?>" <?php if(isset($saved_settings['retailcrm_default_payment']) && $k == $saved_settings['retailcrm_default_payment']):?>selected="selected"<?php endif;?>>
|
||||
<?php echo $v;?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
<label class="control-label" for="retailcrm_default_payment"><?php echo $text_payment; ?></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="retailcrm_unit col-sm-12">
|
||||
<div class="row">
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
<select id="retailcrm_default_shipping" name="retailcrm_default_shipping" class="form-control">
|
||||
<?php foreach ($delivery['opencart'] as $key => $value): ?>
|
||||
<optgroup label="<?php echo $value['title']; ?>">
|
||||
<?php unset($value['title']); ?>
|
||||
<?php foreach ($value as $v): ?>
|
||||
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_default_shipping']) && $v['code'] == $saved_settings['retailcrm_default_shipping']):?>selected="selected"<?php endif;?>>
|
||||
<?php echo $v['title'];?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</optgroup>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
<label class="control-label" for="retailcrm_default_payment"><?php echo $text_shipping; ?></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label"><?php echo $retailcrm_missing_status; ?></label>
|
||||
<div class="col-sm-10">
|
||||
<div class="row">
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
<select id="retailcrm_missing_status" name="retailcrm_missing_status" class="form-control">
|
||||
<option>-- Выберите --</option>
|
||||
<?php foreach ($statuses['retailcrm'] as $k => $v): ?>
|
||||
<option value="<?php echo $k;?>" <?php if(isset($saved_settings['retailcrm_missing_status']) && $k == $saved_settings['retailcrm_missing_status']):?>selected="selected"<?php endif;?>>
|
||||
<?php echo $v['name'];?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="tab-pane" id="tab-collector">
|
||||
<fieldset>
|
||||
<legend><?php echo $daemon_collector; ?></legend>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_collector_active"><?php echo $text_collector_activity; ?></label>
|
||||
<div class="col-sm-10">
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="retailcrm_collector_active" value="1" <?php if (isset($saved_settings['retailcrm_collector_active']) &&
|
||||
$saved_settings['retailcrm_collector_active'] == 1) :
|
||||
echo 'checked'; endif; ?> />
|
||||
<?php echo $text_yes; ?>
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="retailcrm_collector_active" value="0" <?php if (!isset($saved_settings['retailcrm_collector_active']) ||
|
||||
$saved_settings['retailcrm_collector_active'] == 0) :
|
||||
echo 'checked'; endif; ?> />
|
||||
<?php echo $text_no; ?>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_collector" class="col-md-4"><?php echo $collector_site_key; ?></label>
|
||||
<div class="col-sm-10">
|
||||
<input id="retailcrm_collector_site_key" type="text" name="retailcrm_collector[site_key]" value="<?php if (isset($saved_settings['retailcrm_collector']['site_key'])): echo $saved_settings['retailcrm_collector']['site_key']; endif; ?>" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_collector"><?php echo $text_collector_form_capture; ?></label>
|
||||
<div class="col-sm-10">
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="retailcrm_collector[form_capture]" value="1" <?php if (isset($saved_settings['retailcrm_collector']['form_capture']) &&
|
||||
$saved_settings['retailcrm_collector']['form_capture'] == 1) :
|
||||
echo 'checked'; endif; ?>>
|
||||
<?php echo $text_yes; ?>
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="retailcrm_collector[form_capture]" value="0" <?php if (!isset($saved_settings['retailcrm_collector']['form_capture']) ||
|
||||
$saved_settings['retailcrm_collector']['form_capture'] == 0) :
|
||||
echo 'checked'; endif; ?>>
|
||||
<?php echo $text_no; ?>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_collector_period" class="col-md-4"><?php echo $text_collector_period; ?></label>
|
||||
<div class="col-sm-4">
|
||||
<input id="retailcrm_collector_period" type="text" name="retailcrm_collector[period]" value="<?php if (isset($saved_settings['retailcrm_collector']['period'])): echo $saved_settings['retailcrm_collector']['period']; endif; ?>" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_collector[]"><?php echo $text_label_promo; ?></label>
|
||||
<div class="col-sm-10">
|
||||
<input id="retailcrm_collector[]" type="text" name="retailcrm_collector[label_promo]" value="<?php if (isset($saved_settings['retailcrm_collector']['label_promo'])): echo $saved_settings['retailcrm_collector']['label_promo']; endif; ?>" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_collector_label_send"><?php echo $text_label_send; ?></label>
|
||||
<div class="col-sm-10">
|
||||
<input id="retailcrm_collector_label_send" type="text" name="retailcrm_collector[label_send]" value="<?php if (isset($saved_settings['retailcrm_collector']['label_send'])): echo $saved_settings['retailcrm_collector']['label_send']; endif; ?>" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_collector"><?php echo $collector_custom_text; ?></label>
|
||||
<div class="col-sm-10">
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="retailcrm_collector[custom_form]" value="1" <?php if (isset($saved_settings['retailcrm_collector']['custom_form']) &&
|
||||
$saved_settings['retailcrm_collector']['custom_form'] == 1) :
|
||||
echo 'checked'; endif; ?>>
|
||||
<?php echo $text_yes; ?>
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="retailcrm_collector[custom_form]" value="0" <?php if (!isset($saved_settings['retailcrm_collector']['custom_form']) ||
|
||||
$saved_settings['retailcrm_collector']['custom_form'] == 0) :
|
||||
echo 'checked'; endif; ?>>
|
||||
<?php echo $text_no; ?>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<?php foreach ($collectorFields as $field => $label) : ?>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_collector"><?php echo $label; ?></label>
|
||||
<div class="col-sm-10">
|
||||
<div class="row">
|
||||
<div class="col-md-4 col-sm-6">
|
||||
<input id="retailcrm_collector" type="text" name="retailcrm_collector[custom][<?php echo $field; ?>]" value="<?php if (isset($saved_settings['retailcrm_collector']['custom'][$field])) : echo $saved_settings['retailcrm_collector']['custom'][$field]; endif; ?>" class="form-control" />
|
||||
</div>
|
||||
<div class="col-md-8 col-sm-6" style="margin-top: 8px;">
|
||||
<input style="margin-top: 0; vertical-align: middle;" type="checkbox" name="retailcrm_collector[require][<?php echo $field; ?>_require]" value="1" <?php if (isset($saved_settings['retailcrm_collector']['require'][$field.'_require'])) : echo 'checked'; endif;?> />
|
||||
<label style="margin-bottom: 0; vertical-align: middle; margin-left: 5px;" for="retailcrm_collector"><?php echo $text_require; ?></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</fieldset>
|
||||
</div>
|
||||
<?php if (isset($saved_settings['retailcrm_apiversion']) && $saved_settings['retailcrm_apiversion'] == 'v5' && isset($customFields)) : ?>
|
||||
<div class="tab-pane" id="tab-custom_fields">
|
||||
<fieldset>
|
||||
<legend><?php echo $retailcrm_dict_custom_fields; ?></legend>
|
||||
<?php if ($customFields['retailcrm'] && $customFields['opencart']) : ?>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_custom_field_active"><?php echo $text_custom_field_activity; ?></label>
|
||||
<div class="col-sm-10">
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="retailcrm_custom_field_active" value="1" <?php if (isset($saved_settings['retailcrm_custom_field_active']) &&
|
||||
$saved_settings['retailcrm_custom_field_active'] == 1) :
|
||||
echo 'checked'; endif; ?> />
|
||||
<?php echo $text_yes; ?>
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="retailcrm_custom_field_active" value="0" <?php if (!isset($saved_settings['retailcrm_custom_field_active']) ||
|
||||
$saved_settings['retailcrm_custom_field_active'] == 0) :
|
||||
echo 'checked'; endif; ?> />
|
||||
<?php echo $text_no; ?>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label"><?php echo $text_customers_custom_fields; ?></label>
|
||||
<div class="col-sm-10">
|
||||
<div class="row">
|
||||
<?php foreach ($customFields['opencart'] as $customField) : ?>
|
||||
<div class="col-sm-12" style="margin-bottom:5px;">
|
||||
<div class="row">
|
||||
<?php $fid = 'c_' . $customField['custom_field_id'] ?>
|
||||
<div class="col-sm-4">
|
||||
<select id="retailcrm_custom_field_<?php echo $fid; ?>" name="retailcrm_custom_field[<?php echo $fid; ?>]" class="form-control">
|
||||
<?php foreach ($customFields['retailcrm']['customers'] as $v): ?>
|
||||
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_custom_field'][$fid]) && $v['code'] == $saved_settings['retailcrm_custom_field'][$fid]):?>selected="selected"<?php endif;?>>
|
||||
<?php echo $v['name'];?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<label style="padding-top: 9px;" for="retailcrm_custom_field_<?php echo $fid; ?>"><?php echo $customField['name']; ?></label>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label"><?php echo $text_orders_custom_fields; ?></label>
|
||||
<div class="col-sm-10">
|
||||
<div class="row">
|
||||
<?php foreach ($customFields['opencart'] as $customField) : ?>
|
||||
<div class="col-sm-12" style="margin-bottom:5px;">
|
||||
<div class="row">
|
||||
<?php $fid = 'o_' . $customField['custom_field_id'] ?>
|
||||
<div class="col-sm-4">
|
||||
<select id="retailcrm_custom_field_<?php echo $fid; ?>" name="retailcrm_custom_field[<?php echo $fid; ?>]" class="form-control">
|
||||
<?php foreach ($customFields['retailcrm']['orders'] as $v): ?>
|
||||
<option value="<?php echo $v['code'];?>" <?php if(isset($saved_settings['retailcrm_custom_field'][$fid]) && $v['code'] == $saved_settings['retailcrm_custom_field'][$fid]):?>selected="selected"<?php endif;?>>
|
||||
<?php echo $v['name'];?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<label style="padding-top: 9px;" for="retailcrm_custom_field_<?php echo $fid; ?>"><?php echo $customField['name']; ?></label>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php elseif (!$customFields['retailcrm'] && !$customFields['opencart']) : ?>
|
||||
<div class="alert alert-info"><i class="fa fa-exclamation-circle"></i>
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
<?php echo $text_error_custom_field; ?>
|
||||
</div>
|
||||
<?php elseif (!$customFields['retailcrm']) : ?>
|
||||
<div class="alert alert-info"><i class="fa fa-exclamation-circle"></i>
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
<?php echo $text_error_cf_retailcrm; ?>
|
||||
</div>
|
||||
<?php elseif (!$customFields['opencart']) : ?>
|
||||
<div class="alert alert-info"><i class="fa fa-exclamation-circle"></i>
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
<?php echo $text_error_cf_opencart; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</fieldset>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="tab-pane" id="tab-logs">
|
||||
<fieldset style="margin-bottom: 30px;">
|
||||
<legend>Retailcrm API error log</legend>
|
||||
<div class="retailcrm_unit">
|
||||
<a onclick="confirm('<?php echo $text_confirm_log; ?>') ? location.href='<?php echo $clear_retailcrm; ?>' : false;" data-toggle="tooltip" title="<?php echo $button_clear; ?>" class="btn btn-danger"><i class="fa fa-eraser"></i> <span class="hidden-xs"><?php echo $button_clear; ?></span></a>
|
||||
</div>
|
||||
<?php if (isset($logs['retailcrm_log'])) : ?>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<textarea wrap="off" rows="15" readonly class="form-control"><?php echo $logs['retailcrm_log']; ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<?php elseif (isset($logs['retailcrm_error'])) : ?>
|
||||
<div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> <?php echo $logs['retailcrm_error']; ?>
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Opencart API error log</legend>
|
||||
<div class="retailcrm_unit">
|
||||
<a onclick="confirm('<?php echo $text_confirm_log; ?>') ? location.href='<?php echo $clear_opencart; ?>' : false;" data-toggle="tooltip" title="<?php echo $button_clear; ?>" class="btn btn-danger"><i class="fa fa-eraser"></i> <span class="hidden-xs"><?php echo $button_clear; ?></span></a>
|
||||
</div>
|
||||
<?php if (isset($logs['oc_api_log'])) : ?>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<textarea wrap="off" rows="15" readonly class="form-control"><?php echo $logs['oc_api_log']; ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<?php elseif (isset($logs['oc_error'])) : ?>
|
||||
<div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> <?php echo $logs['oc_error']; ?>
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php echo $footer; ?>
|
||||
|
||||
<script type="text/javascript">
|
||||
var token = '<?php echo $token; ?>';
|
||||
$('#icml').on('click', function() {
|
||||
$.ajax({
|
||||
url: '<?php echo $catalog; ?>' + 'admin/index.php?route=extension/module/retailcrm/icml&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> <?php echo $text_success_catalog; ?></div>');
|
||||
$('#icml').button('reset');
|
||||
},
|
||||
error: function(){
|
||||
alert('error');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#export').on('click', function() {
|
||||
$.ajax({
|
||||
url: '<?php echo $catalog; ?>' + 'admin/index.php?route=extension/module/retailcrm/export&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> <?php echo $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: '<?php echo $catalog; ?>' + 'admin/index.php?route=extension/module/retailcrm/exportOrder&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) {
|
||||
response = JSON.parse(jqXHR['responseText']);
|
||||
if (response['status_code'] == '400') {
|
||||
$('.alert-danger').remove();
|
||||
$('#content > .container-fluid').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i><?php echo $text_error_order; ?>' + response['error_msg'] + '</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><?php echo $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> <?php echo $text_error_order_id; ?></div>');
|
||||
$('#export_order').button('reset');
|
||||
}
|
||||
});
|
||||
</script>
|
@ -2,19 +2,19 @@
|
||||
<div id="content">
|
||||
<div class="page-header">
|
||||
<div class="container-fluid">
|
||||
<div class="pull-right">
|
||||
<div class="float-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="button" id="icml" data-toggle="tooltip" title="{{ text_button_catalog }}" class="btn btn-success"><i class="fa fa-file"></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>
|
||||
<a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}" class="btn btn-light"><i class="fa fa-reply"></i></a></div>
|
||||
<h1>{{ heading_title }}</h1>
|
||||
<ul class="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
{% for breadcrumb in breadcrumbs %}
|
||||
<li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-fluid">
|
||||
@ -35,14 +35,14 @@
|
||||
<div class="panel-body">
|
||||
<form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-module" class="form-horizontal">
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a href="#tab-general" data-toggle="tab">{{ general_tab_text }}</a></li>
|
||||
<li class="nav-item"><a href="#tab-general" data-toggle="tab" class="nav-link active show">{{ 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>
|
||||
<li class="nav-item"><a href="#tab-references" data-toggle="tab" class="nav-link">{{ references_tab_text }}</a></li>
|
||||
<li class="nav-item"><a href="#tab-collector" data-toggle="tab" class="nav-link">{{ collector_tab_text }}</a></li>
|
||||
{% if saved_settings.module_retailcrm_apiversion == 'v5' %}
|
||||
<li><a href="#tab-custom_fields" data-toggle="tab"> {{ custom_fields_tab_text }} </a></li>
|
||||
<li><a href="#tab-custom_fields" data-toggle="tab" class="nav-link"> {{ custom_fields_tab_text }} </a></li>
|
||||
{% endif %}
|
||||
<li><a href="#tab-logs" data-toggle="tab">{{ logs_tab_text }}</a></li>
|
||||
<li class="nav-item"><a href="#tab-logs" data-toggle="tab" class="nav-link">{{ logs_tab_text }}</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
@ -50,8 +50,8 @@
|
||||
<input type="hidden" name="module_retailcrm_status" value="1">
|
||||
<fieldset>
|
||||
<legend>{{ retailcrm_base_settings }}</legend>
|
||||
<div class="form-group retailcrm_unit">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_url">{{ retailcrm_apiversion }}</label>
|
||||
<div class="row form-group retailcrm_unit">
|
||||
<label class="col-sm-2 col-form-label" for="retailcrm_url">{{ retailcrm_apiversion }}</label>
|
||||
<div class="col-lg-1 col-md-2 col-sm-2">
|
||||
<select name="module_retailcrm_apiversion" class="form-control">
|
||||
{% for version in api_versions %}
|
||||
@ -60,14 +60,14 @@
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group retailcrm_unit">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_url">{{ retailcrm_url }}</label>
|
||||
<div class="row form-group retailcrm_unit">
|
||||
<label class="col-sm-2 col-form-label" for="retailcrm_url">{{ retailcrm_url }}</label>
|
||||
<div class="col-lg-4 col-md-6 col-sm-10">
|
||||
<input class="form-control" 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>
|
||||
<div class="form-group retailcrm_unit">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_apikey">{{ retailcrm_apikey }}</label>
|
||||
<div class="row form-group retailcrm_unit">
|
||||
<label class="col-sm-2 col-form-label" for="retailcrm_apikey">{{ retailcrm_apikey }}</label>
|
||||
<div class="col-lg-4 col-md-6 col-sm-10">
|
||||
<input class="form-control" 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>
|
||||
@ -75,10 +75,10 @@
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>{{ retailcrm_countries_settings }}</legend>
|
||||
<div class="form-group retailcrm_unit">
|
||||
<label class="col-sm-2 control-label"></label>
|
||||
<div class="row form-group retailcrm_unit">
|
||||
<label class="col-sm-2 col-form-label">{{ retailcrm_countries_settings }}</label>
|
||||
<div class="col-lg-4 col-md-6 col-sm-10">
|
||||
<div class="well well-sm" style="height: 150px; overflow: auto;">
|
||||
<div class="form-control well well-sm" style="height: 150px; overflow: auto;">
|
||||
{% for country in countries %}
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
@ -99,8 +99,8 @@
|
||||
{% else %}
|
||||
<fieldset>
|
||||
<legend>{{ retailcrm_upload_order }}</legend>
|
||||
<div class="form-group retailcrm_unit">
|
||||
<label class="col-sm-2 control-label">{{ text_button_export_order }} № </label>
|
||||
<div class="row form-group retailcrm_unit">
|
||||
<label class="col-sm-2 col-form-label">{{ text_button_export_order }} № </label>
|
||||
<div class="col-sm-10">
|
||||
<div class="row">
|
||||
<div class="col-lg-3 col-md-6 col-sm-6">
|
||||
@ -116,8 +116,8 @@
|
||||
{% if saved_settings.module_retailcrm_apiversion is defined and saved_settings.module_retailcrm_apiversion != 'v3' %}
|
||||
<fieldset>
|
||||
<legend>{{ special_price_settings }}</legend>
|
||||
<div class="form-group retailcrm_unit">
|
||||
<label class="col-sm-2 control-label">{{ special_price_settings }}</label>
|
||||
<div class="row form-group retailcrm_unit">
|
||||
<label class="col-sm-2 col-form-label" for="module_retailcrm_special">{{ special_price_settings }}</label>
|
||||
<div class="col-md-4 col-sm-10">
|
||||
<select id="module_retailcrm_special" name="module_retailcrm_special" class="form-control">
|
||||
{% for priceType in priceTypes %}
|
||||
@ -134,23 +134,49 @@
|
||||
{% endif %}
|
||||
<fieldset>
|
||||
<legend>{{ order_number }}</legend>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" class="col-sm-2 control-label" for="module_retailcrm_order_number">{{ text_order_number }}</label>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label" class="col-sm-2 col-form-label" for="module_retailcrm_order_number">{{ text_order_number }}</label>
|
||||
<div class="col-sm-10">
|
||||
<label class="control-label" class="radio-inline">
|
||||
<input type="radio" name="module_retailcrm_order_number" value="1"
|
||||
{% if saved_settings.module_retailcrm_order_number is defined and saved_settings.module_retailcrm_order_number == 1 %}
|
||||
checked
|
||||
{% endif %} />
|
||||
{{ text_yes }}
|
||||
</label>
|
||||
<label class="control-label" class="radio-inline">
|
||||
<input type="radio" name="module_retailcrm_order_number" value="0"
|
||||
{% if saved_settings.module_retailcrm_order_number is not defined or saved_settings.module_retailcrm_order_number == 0 %}
|
||||
checked
|
||||
{% endif %} />
|
||||
{{ text_no }}
|
||||
</label>
|
||||
<div class="btn-group btn-group-toggle" data-toggle="buttons">
|
||||
{% if saved_settings.module_retailcrm_order_number is defined and saved_settings.module_retailcrm_order_number == 1 %}
|
||||
{% set check_order_number = true %}
|
||||
{% endif %}
|
||||
<label class="btn btn-outline-secondary{% if check_order_number == true %} active{% endif %}">
|
||||
<input type="radio" name="module_retailcrm_order_number" value="1" {% if check_order_number == true %}checked{% endif %}/>
|
||||
{{ text_yes }}
|
||||
</label>
|
||||
{% if saved_settings.module_retailcrm_order_number is not defined or saved_settings.module_retailcrm_order_number == 0 %}
|
||||
{%set check_order_number = false %}
|
||||
{% endif %}
|
||||
<label class="btn btn-outline-secondary{% if check_order_number == false %} active{% endif %}">
|
||||
<input type="radio" name="module_retailcrm_order_number" value="0" {% if check_order_number == false %}checked{% endif %}/>
|
||||
{{ text_no }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>{{ debug }}</legend>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label" class="col-sm-2 col-form-label" for="module_retailcrm_debug_mode">{{ text_debug }}</label>
|
||||
<div class="col-sm-10">
|
||||
<div class="btn-group btn-group-toggle" data-toggle="buttons">
|
||||
{% if saved_settings.module_retailcrm_debug_mode is defined and saved_settings.module_retailcrm_debug_mode == 1 %}
|
||||
{% set debug_mode = true %}
|
||||
{% endif %}
|
||||
<label class="btn btn-outline-secondary{% if debug_mode == true %} active{% endif %}">
|
||||
<input type="radio" name="module_retailcrm_debug_mode" value="1"{% if debug_mode == true %} checked{% endif %}>
|
||||
{{ text_yes }}
|
||||
</label>
|
||||
{% if saved_settings.module_retailcrm_debug_mode is not defined or saved_settings.module_retailcrm_debug_mode == 0 %}
|
||||
{% set debug_mode = false %}
|
||||
{% endif %}
|
||||
<label class="btn btn-outline-secondary{% if debug_mode == false %} active{% endif %}">
|
||||
<input type="radio" name="module_retailcrm_debug_mode" value="0"{% if debug_mode == false %} checked{% endif %}>
|
||||
{{ text_no }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
@ -158,8 +184,8 @@
|
||||
<div class="tab-pane" id="tab-references">
|
||||
<fieldset>
|
||||
<legend>{{ retailcrm_dict_settings }}</legend>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label"> {{ retailcrm_dict_delivery }}</label>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label"> {{ retailcrm_dict_delivery }}</label>
|
||||
<div class="col-sm-10">
|
||||
<div class="row">
|
||||
{% if delivery.opencart is not empty %}
|
||||
@ -168,9 +194,9 @@
|
||||
<div class="pm">{{ value.title ~ ':' }}</div>
|
||||
{% for key, val in value %}
|
||||
{% if key != 'title' %}
|
||||
<div class="form-group retailcrm_unit">
|
||||
<div class="row form-group retailcrm_unit">
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
<select id="retailcrm_delivery_{{ val.code }}" name="module_retailcrm_delivery[{{ val.code }}]" >
|
||||
<select id="retailcrm_delivery_{{ val.code }}" name="module_retailcrm_delivery[{{ val.code }}]" class="form-control">
|
||||
{% 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 }}
|
||||
@ -179,7 +205,7 @@
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_pm_{{ val.code }}">{{ val.title }}</label>
|
||||
<label class="col-form-label" for="retailcrm_pm_{{ val.code }}">{{ val.title }}</label>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
@ -195,8 +221,8 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">{{ retailcrm_dict_status }}</label>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label">{{ retailcrm_dict_status }}</label>
|
||||
<div class="col-sm-10">
|
||||
{% for status in statuses.opencart %}
|
||||
{% set uid = status.order_status_id %}
|
||||
@ -211,14 +237,14 @@
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
<label class="control-label" for="retailcrm_status_{{ status.order_status_id }} ">{{ status.name }}</label>
|
||||
<label class="col-form-label" for="retailcrm_status_{{ status.order_status_id }} ">{{ status.name }}</label>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">{{ retailcrm_dict_payment }}</label>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label">{{ retailcrm_dict_payment }}</label>
|
||||
<div class="col-sm-10">
|
||||
{% for key, value in payments.opencart %}
|
||||
<div class="row retailcrm_unit">
|
||||
@ -232,14 +258,14 @@
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
<label class="control-label" for="retailcrm_payment_{{ key }}">{{ value }}</label>
|
||||
<label class="col-form-label" for="retailcrm_payment_{{ key }}">{{ value }}</label>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">{{ retailcrm_dict_default }}</label>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label">{{ retailcrm_dict_default }}</label>
|
||||
<div class="col-sm-10">
|
||||
<div class="row">
|
||||
<div class="retailcrm_unit col-sm-12">
|
||||
@ -254,7 +280,7 @@
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
<label class="col-sm-2 control-label" for="module_retailcrm_default_payment">{{ text_payment }}</label>
|
||||
<label class="col-sm-2 col-form-label" for="module_retailcrm_default_payment">{{ text_payment }}</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -276,15 +302,15 @@
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
<label class="col-sm-2 control-label" for="module_retailcrm_default_shipping">{{ text_shipping }}</label>
|
||||
<label class="col-sm-2 col-form-label" for="module_retailcrm_default_shipping">{{ text_shipping }}</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">{{ retailcrm_missing_status }}</label>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label">{{ retailcrm_missing_status }}</label>
|
||||
<div class="col-sm-10">
|
||||
<div class="row">
|
||||
<div class="col-lg-4 col-md-6 col-sm-6">
|
||||
@ -307,84 +333,102 @@
|
||||
<div class="tab-pane" id="tab-collector">
|
||||
<fieldset>
|
||||
<legend>{{ daemon_collector }}</legend>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_collector_active" class="col-md-4">{{ text_collector_activity }}</label>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label" for="retailcrm_collector_active" class="col-md-4">{{ text_collector_activity }}</label>
|
||||
<div class="col-sm-10">
|
||||
<label class="control-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="control-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 class="btn-group btn-group-toggle" data-toggle="buttons">
|
||||
{% if saved_settings.module_retailcrm_collector_active is defined
|
||||
and saved_settings.module_retailcrm_collector_active == 1 %}
|
||||
{% set collector_active = true %}
|
||||
{% endif %}
|
||||
<label class="btn btn-outline-secondary{% if collector_active == true %} active{% endif %}">
|
||||
<input type="radio" name="module_retailcrm_collector_active" value="1"{% if collector_active == true %} checked{% endif %}>
|
||||
{{ text_yes }}
|
||||
</label>
|
||||
{% if not saved_settings.module_retailcrm_collector_active
|
||||
or saved_settings.module_retailcrm_collector_active == 0 %}
|
||||
{% set collector_active = false %}
|
||||
{% endif %}
|
||||
<label class="btn btn-outline-secondary{% if collector_active == false %} active{% endif %}">
|
||||
<input type="radio" name="module_retailcrm_collector_active" value="0"{% if collector_active == false %} checked{% endif %}>
|
||||
{{ text_no }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_collector" class="col-md-4">{{ collector_site_key }}</label>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label" for="retailcrm_collector" class="col-md-4">{{ collector_site_key }}</label>
|
||||
<div class="col-sm-4">
|
||||
<input class="form-control" 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>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_collector" class="col-md-4">{{ text_collector_form_capture }}</label>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label" for="retailcrm_collector" class="col-md-4">{{ text_collector_form_capture }}</label>
|
||||
<div class="col-sm-10">
|
||||
<label class="control-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="control-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 class="btn-group btn-group-toggle" data-toggle="buttons">
|
||||
{% if saved_settings.module_retailcrm_collector.form_capture is defined
|
||||
and saved_settings.module_retailcrm_collector.form_capture == 1 %}
|
||||
{% set form_capture = true %}
|
||||
{% endif %}
|
||||
<label class="btn btn-outline-secondary{% if form_capture == true %} active{% endif %}">
|
||||
<input type="radio" name="module_retailcrm_collector[form_capture]" value="1"{% if form_capture == true %} checked{% endif %}>
|
||||
{{ text_yes }}
|
||||
</label>
|
||||
{% if saved_settings.module_retailcrm_collector.form_capture is not defined
|
||||
or saved_settings.module_retailcrm_collector.form_capture == 0 %}
|
||||
{% set form_capture = false %}
|
||||
{% endif %}
|
||||
<label class="btn btn-outline-secondary{% if form_capture == false %} active{% endif %}">
|
||||
<input type="radio" name="module_retailcrm_collector[form_capture]" value="0"{% if form_capture == false %} checked{% endif %}>
|
||||
{{ text_no }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="module_retailcrm_collector" class="col-md-4">{{ text_collector_period }}</label>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label" for="module_retailcrm_collector" class="col-md-4">{{ text_collector_period }}</label>
|
||||
<div class="col-sm-2">
|
||||
<input class="form-control" id="module_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>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="module_retailcrm_collector" class="col-md-4">{{ text_label_promo }}</label>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label" for="module_retailcrm_collector" class="col-md-4">{{ text_label_promo }}</label>
|
||||
<div class="col-sm-4">
|
||||
<input class="form-control" id="module_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>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="module_retailcrm_collector" class="col-md-4">{{ text_label_send }}</label>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label" for="module_retailcrm_collector" class="col-md-4">{{ text_label_send }}</label>
|
||||
<div class="col-sm-4">
|
||||
<input class="form-control" id="module_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>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="module_retailcrm_collector" class="col-md-4">{{ collector_custom_text }}</label>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label" for="module_retailcrm_collector" class="col-md-4">{{ collector_custom_text }}</label>
|
||||
<div class="col-sm-10">
|
||||
<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 not defined or
|
||||
saved_settings.module_retailcrm_collector.custom_form == 0 %} {{ 'checked' }}
|
||||
{% endif %}>
|
||||
{{ text_no }}
|
||||
</label>
|
||||
<div class="btn-group btn-group-toggle" data-toggle="buttons">
|
||||
{% if saved_settings.module_retailcrm_collector.custom_form is defined
|
||||
and saved_settings.module_retailcrm_collector.custom_form == 1 %}
|
||||
{% set custom_form = true %}
|
||||
{% endif %}
|
||||
<label class="btn btn-outline-secondary{% if custom_form == true %} active{% endif %}">
|
||||
<input type="radio" name="module_retailcrm_collector[custom_form]" value="1"{% if custom_form == true %} checked{% endif %}>
|
||||
{{ text_yes }}
|
||||
</label>
|
||||
{% if saved_settings.module_retailcrm_collector.custom_form is not defined
|
||||
or saved_settings.module_retailcrm_collector.custom_form == 0 %}
|
||||
{% set custom_form = false %}
|
||||
{% endif %}
|
||||
<label class="btn btn-outline-secondary{% if custom_form == false %} active{% endif %}">
|
||||
<input type="radio" name="module_retailcrm_collector[custom_form]" value="0"{% if custom_form == false %} checked{% endif %}>
|
||||
{{ text_no }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% for field, label in collectorFields %}
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_collector">{{ label }}</label>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label" for="retailcrm_collector">{{ label }}</label>
|
||||
<div class="col-sm-10">
|
||||
<div class="row">
|
||||
<div class="col-md-4 col-sm-6">
|
||||
@ -405,25 +449,31 @@
|
||||
<fieldset>
|
||||
<legend>{{ retailcrm_dict_custom_fields }}</legend>
|
||||
{% if customFields.retailcrm is not empty and customFields.opencart is not empty %}
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label" for="retailcrm_custom_field_active">{{ text_custom_field_activity }}</label>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label" for="retailcrm_custom_field_active">{{ text_custom_field_activity }}</label>
|
||||
<div class="col-sm-10">
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="module_retailcrm_custom_field_active" value="1" {% if saved_settings.module_retailcrm_custom_field_active is defined and
|
||||
saved_settings.module_retailcrm_custom_field_active == 1 %}
|
||||
checked {% endif %} >
|
||||
{{ text_yes }}
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="module_retailcrm_custom_field_active" value="0" {% if saved_settings.module_retailcrm_custom_field_active is not defined or
|
||||
saved_settings.module_retailcrm_custom_field_active == 0 %}
|
||||
checked {% endif %} >
|
||||
{{ text_no }}
|
||||
</label>
|
||||
<div class="btn-group btn-group-toggle" data-toggle="buttons">
|
||||
{% if saved_settings.module_retailcrm_custom_field_active is defined
|
||||
and saved_settings.module_retailcrm_custom_field_active == 1 %}
|
||||
{% set custom_field_active = true %}
|
||||
{% endif %}
|
||||
<label class="btn btn-outline-secondary{% if custom_field_active == true %} active{% endif %}">
|
||||
<input type="radio" name="module_retailcrm_custom_field_active" value="1"{% if custom_field_active == true %} checked{% endif %}>
|
||||
{{ text_yes }}
|
||||
</label>
|
||||
{% if saved_settings.module_retailcrm_custom_field_active is not defined
|
||||
or saved_settings.module_retailcrm_custom_field_active == 0 %}
|
||||
{% set custom_field_active = false %}
|
||||
{% endif %}
|
||||
<label class="btn btn-outline-secondary{% if custom_field_active == false %} active{% endif %}">
|
||||
<input type="radio" name="module_retailcrm_custom_field_active" value="0"{% if custom_field_active == false %} checked{% endif %}>
|
||||
{{ text_no }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">{{ text_customers_custom_fields }}</label>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label">{{ text_customers_custom_fields }}</label>
|
||||
<div class="col-sm-10">
|
||||
<div class="row">
|
||||
{% for customField in customFields.opencart %}
|
||||
@ -446,8 +496,8 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">{{ text_orders_custom_fields }}</label>
|
||||
<div class="row form-group">
|
||||
<label class="col-sm-2 col-form-label">{{ text_orders_custom_fields }}</label>
|
||||
<div class="col-sm-10">
|
||||
<div class="row">
|
||||
{% for customField in customFields.opencart %}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class ControllerApiRetailcrm extends Controller
|
||||
class ControllerApiRetailcrm extends Controller
|
||||
{
|
||||
public function getDeliveryTypes()
|
||||
{
|
||||
@ -12,12 +12,14 @@ class ControllerApiRetailcrm extends Controller
|
||||
$this->load->model('localisation/country');
|
||||
$this->load->model('setting/setting');
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
$moduleTitle = $this->retailcrm->getModuleTitle();
|
||||
$setting = $this->model_setting_setting->getSetting($moduleTitle);
|
||||
$setting = $this->model_setting_setting->getSetting(\Retailcrm\Retailcrm::MODULE);
|
||||
$response = array();
|
||||
|
||||
if (isset($setting[$moduleTitle . '_country']) && $setting[$moduleTitle . '_country']) {
|
||||
foreach ($setting[$moduleTitle . '_country'] as $country) {
|
||||
if (
|
||||
isset($setting[\Retailcrm\Retailcrm::MODULE . '_country'])
|
||||
&& $setting[\Retailcrm\Retailcrm::MODULE . '_country']
|
||||
) {
|
||||
foreach ($setting[\Retailcrm\Retailcrm::MODULE . '_country'] as $country) {
|
||||
$response = array_merge($response, $this->getDeliveryTypesByZones($country));
|
||||
}
|
||||
}
|
||||
@ -60,7 +62,7 @@ class ControllerApiRetailcrm extends Controller
|
||||
}
|
||||
|
||||
protected function getDeliveryTypesByZones($country_id)
|
||||
{
|
||||
{
|
||||
$this->loadModels();
|
||||
$this->load->model('localisation/zone');
|
||||
$this->load->model('localisation/country');
|
||||
@ -80,7 +82,7 @@ class ControllerApiRetailcrm extends Controller
|
||||
'postcode' => '',
|
||||
'city' => ''
|
||||
);
|
||||
|
||||
|
||||
foreach ($shippingModules as $shippingModule) {
|
||||
$this->load->model('extension/shipping/' . $shippingModule['code']);
|
||||
|
||||
@ -98,7 +100,7 @@ class ControllerApiRetailcrm extends Controller
|
||||
$this->config->set('free_total', 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($this->{'model_extension_shipping_' . $shippingModule['code']}->getQuote($address)) {
|
||||
$quote_data[] = $this->{'model_extension_shipping_' . $shippingModule['code']}->getQuote($address);
|
||||
} else {
|
||||
@ -139,17 +141,9 @@ class ControllerApiRetailcrm extends Controller
|
||||
return array('error' => 'Not found api key');
|
||||
}
|
||||
|
||||
if (isset($this->request->get['key'])
|
||||
&& !empty($this->request->get['key'])
|
||||
) {
|
||||
$this->load->model('account/api');
|
||||
|
||||
if ( version_compare(VERSION, '3.0', '<')) {
|
||||
$api = $this->model_account_api->getApiByKey($this->request->get['key']);
|
||||
} else {
|
||||
$this->load->model('extension/retailcrm/api');
|
||||
$api = $this->model_extension_retailcrm_api->login($this->request->get['username'], $this->request->get['key']);
|
||||
}
|
||||
if (isset($this->request->get['key']) && !empty($this->request->get['key'])) {
|
||||
$this->load->model('extension/retailcrm/api');
|
||||
$api = $this->model_extension_retailcrm_api->login($this->request->get['username'], $this->request->get['key']);
|
||||
|
||||
if (!empty($api)) {
|
||||
return $api;
|
||||
@ -161,14 +155,7 @@ class ControllerApiRetailcrm extends Controller
|
||||
|
||||
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';
|
||||
}
|
||||
$this->load->model('setting/extension');
|
||||
$this->modelExtension = 'setting_extension';
|
||||
}
|
||||
}
|
||||
|
@ -2,15 +2,13 @@
|
||||
class ControllerExtensionAnalyticsDaemonCollector extends Controller {
|
||||
public function index() {
|
||||
$this->load->model('setting/setting');
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
$moduleTitle = $this->retailcrm->getModuleTitle();
|
||||
|
||||
$settings = $this->model_setting_setting->getSetting($moduleTitle);
|
||||
$setting = $settings[$moduleTitle . '_collector'];
|
||||
$settings = $this->model_setting_setting->getSetting(\Retailcrm\Retailcrm::MODULE);
|
||||
$setting = $settings[\Retailcrm\Retailcrm::MODULE . '_collector'];
|
||||
$siteCode = isset($setting['site_key']) ? $setting['site_key'] : '';
|
||||
|
||||
if ($this->customer->isLogged()) $customerId = $this->customer->getID();
|
||||
|
||||
|
||||
$customer = isset($customerId) ? "'customerId': '" . $customerId . "'" : "";
|
||||
$labelPromo = !empty($setting['label_promo']) ? $setting['label_promo'] : null;
|
||||
$labelSend = !empty($setting['label_send']) ? $setting['label_send'] : null;
|
||||
@ -54,7 +52,7 @@ class ControllerExtensionAnalyticsDaemonCollector extends Controller {
|
||||
'period': " . $settings[$moduleTitle . '_collector']['period'] . ",
|
||||
" . $customForm . "
|
||||
});";
|
||||
}
|
||||
}
|
||||
} elseif ($labelPromo != null || $labelSend != null) {
|
||||
$captureForm = "_rc('require', 'capture-form', {
|
||||
" . $customForm . "
|
||||
|
@ -11,176 +11,108 @@
|
||||
*/
|
||||
class ControllerExtensionModuleRetailcrm extends Controller {
|
||||
|
||||
private $retailcrmApiClient;
|
||||
|
||||
public function __construct($registry)
|
||||
{
|
||||
parent::__construct($registry);
|
||||
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
$this->retailcrmApiClient = $this->retailcrm->getApiClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create order on event
|
||||
*
|
||||
* @param string $trigger
|
||||
* @param array $data
|
||||
* @param int $order_id order identificator
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param int $output
|
||||
*
|
||||
* @return void
|
||||
* @return boolean
|
||||
*/
|
||||
public function order_create($trigger, $data, $order_id = null) {
|
||||
$this->load->model('checkout/order');
|
||||
$this->load->model('account/order');
|
||||
public function orderCreate($route, $args, $output) {
|
||||
if ($route != 'checkout/order/addOrder') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
$data = $args[0];
|
||||
$data['order_id'] = $output;
|
||||
$retailcrm_order = $this->retailcrm->createObject(\Retailcrm\Order::class);
|
||||
|
||||
$data = $this->model_checkout_order->getOrder($order_id);;
|
||||
$data['products'] = $this->model_account_order->getOrderProducts($order_id);
|
||||
$data['totals'] = $this->model_account_order->getOrderTotals($order_id);
|
||||
$moduleTitle = $this->retailcrm->getModuleTitle();
|
||||
$retailcrm_order->prepare($data);
|
||||
$retailcrm_order->setField('externalId', $output);
|
||||
$retailcrm_order->create($this->retailcrm->getApiClient());
|
||||
|
||||
foreach ($data['products'] as $key => $product) {
|
||||
$productOptions = $this->model_account_order->getOrderOptions($order_id, $product['order_product_id']);
|
||||
|
||||
if (!empty($productOptions)) {
|
||||
$data['products'][$key]['option'] = $productOptions;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($data['fromApi'])) {
|
||||
$this->load->model('setting/setting');
|
||||
$status = $this->model_setting_setting->getSetting($moduleTitle);
|
||||
|
||||
if (isset($data['order_status_id']) && $data['order_status_id'] > 0) {
|
||||
$data['order_status'] = $status[$moduleTitle . '_status'][$data['order_status_id']];
|
||||
}
|
||||
|
||||
if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/order.php')) {
|
||||
$this->load->model('extension/retailcrm/custom/order');
|
||||
$order = $this->model_extension_retailcrm_custom_order->processOrder($data);
|
||||
$this->model_extension_retailcrm_custom_order->sendToCrm($order, $this->retailcrmApiClient);
|
||||
} else {
|
||||
$this->load->model('extension/retailcrm/order');
|
||||
$order = $this->model_extension_retailcrm_order->processOrder($data);
|
||||
$this->model_extension_retailcrm_order->sendToCrm($order, $this->retailcrmApiClient);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update order on event
|
||||
*
|
||||
* @param string $trigger
|
||||
* @param array $parameter2
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
*
|
||||
* @return void
|
||||
* @return boolean
|
||||
*/
|
||||
public function order_edit($trigger, $parameter2 = null) {
|
||||
$order_id = $parameter2[0];
|
||||
public function orderEdit($route, $args) {
|
||||
if ($route != 'checkout/order/editOrder') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$order_id = $args[0];
|
||||
$data = $args[1];
|
||||
|
||||
$this->load->model('checkout/order');
|
||||
$this->load->model('account/order');
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
$this->load->model('extension/module/retailcrm');
|
||||
|
||||
$moduleTitle = $this->retailcrm->getModuleTitle();
|
||||
$data = $this->model_checkout_order->getOrder($order_id);
|
||||
$order_status_id = $this->model_extension_module_retailcrm->getOrderStatusId($order_id);
|
||||
$data['order_status_id'] = $order_status_id;
|
||||
$retailcrm_order = $this->retailcrm->createObject(\Retailcrm\Order::class);
|
||||
|
||||
if ($data['order_status_id'] == 0) {
|
||||
return;
|
||||
}
|
||||
$retailcrm_order->prepare($data);
|
||||
$retailcrm_order->setField('externalId', $order_id);
|
||||
$retailcrm_order->edit($this->retailcrm->getApiClient());
|
||||
|
||||
$data['products'] = $this->model_account_order->getOrderProducts($order_id);
|
||||
$data['totals'] = $this->model_account_order->getOrderTotals($order_id);
|
||||
|
||||
foreach ($data['products'] as $key => $product) {
|
||||
$productOptions = $this->model_account_order->getOrderOptions($order_id, $product['order_product_id']);
|
||||
|
||||
if (!empty($productOptions)) {
|
||||
$data['products'][$key]['option'] = $productOptions;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($data['fromApi'])) {
|
||||
$this->load->model('setting/setting');
|
||||
$status = $this->model_setting_setting->getSetting($moduleTitle);
|
||||
|
||||
if ($data['order_status_id'] > 0) {
|
||||
$data['order_status'] = $status[$moduleTitle . '_status'][$data['order_status_id']];
|
||||
}
|
||||
|
||||
if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/order.php')) {
|
||||
$this->load->model('extension/retailcrm/custom/order');
|
||||
$order = $this->model_extension_retailcrm_custom_order->processOrder($data, false);
|
||||
$this->model_extension_retailcrm_custom_order->sendToCrm($order, $this->retailcrmApiClient, false);
|
||||
} else {
|
||||
$this->load->model('extension/retailcrm/order');
|
||||
$order = $this->model_extension_retailcrm_order->processOrder($data, false);
|
||||
$this->model_extension_retailcrm_order->sendToCrm($order, $this->retailcrmApiClient, false);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create customer on event
|
||||
*
|
||||
* @param int $customerId customer identificator
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param int $output
|
||||
*
|
||||
* @return void
|
||||
* @return boolean
|
||||
*/
|
||||
public function customer_create($parameter1, $parameter2 = null, $parameter3 = null) {
|
||||
$this->load->model('account/customer');
|
||||
$this->load->model('localisation/country');
|
||||
$this->load->model('localisation/zone');
|
||||
|
||||
$customerId = $parameter3;
|
||||
$customer = $this->model_account_customer->getCustomer($customerId);
|
||||
|
||||
if ($this->request->post) {
|
||||
$country = $this->model_localisation_country->getCountry($this->request->post['country_id']);
|
||||
$zone = $this->model_localisation_zone->getZone($this->request->post['zone_id']);
|
||||
|
||||
$customer['address'] = array(
|
||||
'address_1' => $this->request->post['address_1'],
|
||||
'address_2' => $this->request->post['address_2'],
|
||||
'city' => $this->request->post['city'],
|
||||
'postcode' => $this->request->post['postcode'],
|
||||
'iso_code_2' => $country['iso_code_2'],
|
||||
'zone' => $zone['name']
|
||||
);
|
||||
public function customerCreate($route, $args, $output) {
|
||||
if ($route != 'account/customer/addCustomer') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/customer.php')) {
|
||||
$this->load->model('extension/retailcrm/custom/customer');
|
||||
$this->model_extension_retailcrm_custom_customer->sendToCrm($customer, $this->retailcrmApiClient);
|
||||
} else {
|
||||
$this->load->model('extension/retailcrm/customer');
|
||||
$this->model_extension_retailcrm_customer->sendToCrm($customer, $this->retailcrmApiClient);
|
||||
}
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
$retailcrm_customer = $this->retailcrm->createObject(\Retailcrm\Customer::class);
|
||||
|
||||
$retailcrm_customer->prepare($args[0]);
|
||||
$retailcrm_customer->setField('externalId', $output);
|
||||
$retailcrm_customer->create($this->retailcrm->getApiClient());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update customer on event
|
||||
*
|
||||
* @param int $customerId customer identificator
|
||||
*
|
||||
* @return void
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @return boolean
|
||||
*/
|
||||
public function customer_edit($parameter1, $parameter2, $parameter3) {
|
||||
$customerId = $this->customer->getId();
|
||||
|
||||
$this->load->model('account/customer');
|
||||
$customer = $this->model_account_customer->getCustomer($customerId);
|
||||
|
||||
$this->load->model('account/address');
|
||||
$customer['address'] = $this->model_account_address->getAddress($customer['address_id']);
|
||||
|
||||
if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/customer.php')) {
|
||||
$this->load->model('extension/retailcrm/custom/customer');
|
||||
$this->model_extension_retailcrm_custom_customer->changeInCrm($customer, $this->retailcrmApiClient);
|
||||
} else {
|
||||
$this->load->model('extension/retailcrm/customer');
|
||||
$this->model_extension_retailcrm_customer->changeInCrm($customer, $this->retailcrmApiClient);
|
||||
public function customerEdit($route, $args) {
|
||||
if ($route != 'account/customer/editCustomer') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$customer_id = $args[0];
|
||||
$data = $args[1];
|
||||
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
$retailcrm_customer = $this->retailcrm->createObject(\Retailcrm\Customer::class);
|
||||
|
||||
$retailcrm_customer->process($data);
|
||||
$retailcrm_customer->setField('externalId', $customer_id);
|
||||
$retailcrm_customer->edit($this->retailcrm->getApiClient());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,104 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ModelExtensionRetailcrmCustomer extends Model {
|
||||
protected $settings;
|
||||
protected $moduleTitle;
|
||||
|
||||
public function __construct($registry)
|
||||
{
|
||||
parent::__construct($registry);
|
||||
$this->load->model('setting/setting');
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
|
||||
$this->moduleTitle = $this->retailcrm->getModuleTitle();
|
||||
$this->settings = $this->model_setting_setting->getSetting($this->moduleTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create customer
|
||||
*
|
||||
* @param array $customer
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendToCrm($customer, $retailcrmApiClient)
|
||||
{
|
||||
if (empty($customer) || $retailcrmApiClient === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$customerToCrm = $this->process($customer);
|
||||
|
||||
$retailcrmApiClient->customersCreate($customerToCrm);
|
||||
|
||||
return $customerToCrm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit customer
|
||||
*
|
||||
* @param array $customer
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function changeInCrm($customer, $retailcrmApiClient)
|
||||
{
|
||||
if (empty($customer) || $retailcrmApiClient === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$customerToCrm = $this->process($customer);
|
||||
|
||||
$retailcrmApiClient->customersEdit($customerToCrm);
|
||||
|
||||
return $customerToCrm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process customer
|
||||
*
|
||||
* @param array $customer
|
||||
*
|
||||
* @return array $customerToCrm
|
||||
*/
|
||||
private function process($customer) {
|
||||
$customerToCrm = array(
|
||||
'externalId' => $customer['customer_id'],
|
||||
'firstName' => $customer['firstname'],
|
||||
'lastName' => $customer['lastname'],
|
||||
'email' => $customer['email'],
|
||||
'phones' => array(
|
||||
array(
|
||||
'number' => $customer['telephone']
|
||||
)
|
||||
),
|
||||
'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']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->settings[$this->moduleTitle . '_custom_field']) && $customer['custom_field']) {
|
||||
$customFields = json_decode($customer['custom_field']);
|
||||
|
||||
foreach ($customFields as $key => $value) {
|
||||
if (isset($this->settings[$this->moduleTitle . '_custom_field']['c_' . $key])) {
|
||||
$customFieldsToCrm[$this->settings[$this->moduleTitle . '_custom_field']['c_' . $key]] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($customFieldsToCrm)) {
|
||||
$customerToCrm['customFields'] = $customFieldsToCrm;
|
||||
}
|
||||
}
|
||||
|
||||
return $customerToCrm;
|
||||
}
|
||||
}
|
@ -1,350 +1,9 @@
|
||||
<?php
|
||||
|
||||
class ModelExtensionRetailcrmOrder extends Model {
|
||||
protected $settings;
|
||||
protected $moduleTitle;
|
||||
public function getOrderStatusId($order_id) {
|
||||
$query = $this->db->query("SELECT order_status_id FROM " . DB_PREFIX . "order WHERE order_id = '" . (int)$order_id . "'");
|
||||
|
||||
public function __construct($registry) {
|
||||
parent::__construct($registry);
|
||||
$this->load->model('setting/setting');
|
||||
$this->load->library('retailcrm/retailcrm');
|
||||
|
||||
$this->moduleTitle = $this->retailcrm->getModuleTitle();
|
||||
$this->settings = $this->model_setting_setting->getSetting($this->moduleTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create order in CRM
|
||||
*
|
||||
* @param array $order
|
||||
* @param \RetailcrmProxy $retailcrmApiClient
|
||||
* @param bool $create (default = true)
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function sendToCrm($order, $retailcrmApiClient, $create = true) {
|
||||
if (isset($this->request->post['fromApi']) || $retailcrmApiClient === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($order['customer']['externalId'])) {
|
||||
$customer = $this->searchCustomer($order['phone'], $order['email'], $retailcrmApiClient);
|
||||
|
||||
if ($customer) {
|
||||
$order['customer']['id'] = $customer['id'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($create) {
|
||||
$retailcrmApiClient->ordersCreate($order);
|
||||
} else {
|
||||
$order_payment = reset($order['payments']);
|
||||
unset($order['payments']);
|
||||
$response = $retailcrmApiClient->ordersEdit($order);
|
||||
|
||||
if ($this->settings[$this->moduleTitle . '_apiversion'] == 'v5' && $response->isSuccessful()) {
|
||||
$this->updatePayment($order_payment, $order['externalId'], $retailcrmApiClient);
|
||||
}
|
||||
}
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process order
|
||||
*
|
||||
* @param array $order_data
|
||||
* @param bool $create (default = true)
|
||||
*
|
||||
* @return array $order
|
||||
*/
|
||||
public function processOrder($order_data, $create = true) {
|
||||
$this->load->model('setting/setting');
|
||||
$this->load->model('catalog/product');
|
||||
$this->settings = $this->model_setting_setting->getSetting($this->moduleTitle);
|
||||
$order_id = $order_data['order_id'];
|
||||
|
||||
if (!empty($order_data['payment_code']) && isset($this->settings[$this->moduleTitle . '_payment'][$order_data['payment_code']])) {
|
||||
$payment_code = $this->settings[$this->moduleTitle . '_payment'][$order_data['payment_code']];
|
||||
} else {
|
||||
$payment_code = '';
|
||||
}
|
||||
|
||||
if (!empty($order_data['shipping_code'])) {
|
||||
$shippingCode = explode('.', $order_data['shipping_code']);
|
||||
$shippingModule = $shippingCode[0];
|
||||
|
||||
if (isset($this->settings[$this->moduleTitle . '_delivery'][$order_data['shipping_code']])) {
|
||||
$delivery_code = $this->settings[$this->moduleTitle . '_delivery'][$order_data['shipping_code']];
|
||||
} elseif (isset($this->settings[$this->moduleTitle . '_delivery'][$shippingModule])) {
|
||||
$delivery_code = $this->settings[$this->moduleTitle . '_delivery'][$shippingModule];
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($delivery_code) && isset($shippingModule)) {
|
||||
if (isset($this->settings[$this->moduleTitle . '_delivery'])
|
||||
&& $this->settings[$this->moduleTitle . '_delivery']
|
||||
) {
|
||||
$deliveries = array_keys($this->settings[$this->moduleTitle . '_delivery']);
|
||||
$shipping_code = '';
|
||||
|
||||
array_walk($deliveries, function ($item, $key) use ($shippingModule, &$shipping_code) {
|
||||
if (strripos($item, $shippingModule) !== false) {
|
||||
$shipping_code = $item;
|
||||
}
|
||||
});
|
||||
|
||||
$delivery_code = $this->settings[$this->moduleTitle . '_delivery'][$shipping_code];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($order_data['payment_iso_code_2'])) {
|
||||
$order['countryIso'] = $order_data['payment_iso_code_2'];
|
||||
}
|
||||
|
||||
if (isset($this->settings[$this->moduleTitle . '_order_number'])
|
||||
&& $this->settings[$this->moduleTitle . '_order_number'] == 1
|
||||
) {
|
||||
$order['number'] = $order_data['order_id'];
|
||||
}
|
||||
|
||||
$order['externalId'] = $order_id;
|
||||
$order['firstName'] = $order_data['firstname'];
|
||||
$order['lastName'] = $order_data['lastname'];
|
||||
$order['phone'] = $order_data['telephone'];
|
||||
$order['customerComment'] = $order_data['comment'];
|
||||
|
||||
if ($order_data['customer_id']) {
|
||||
$order['customer']['externalId'] = $order_data['customer_id'];
|
||||
}
|
||||
|
||||
if (!empty($order_data['email'])) {
|
||||
$order['email'] = $order_data['email'];
|
||||
}
|
||||
|
||||
$deliveryCost = 0;
|
||||
$couponTotal = 0;
|
||||
$orderTotals = isset($order_data['totals']) ? $order_data['totals'] : $order_data['order_total'] ;
|
||||
|
||||
$totals = $this->explodeTotals($orderTotals);
|
||||
|
||||
if (isset($totals['shipping'])) {
|
||||
$deliveryCost = $totals['shipping'];
|
||||
}
|
||||
|
||||
if (isset($totals['coupon'])) {
|
||||
$couponTotal += abs($totals['coupon']);
|
||||
}
|
||||
|
||||
if (isset($totals['reward'])) {
|
||||
$couponTotal += abs($totals['reward']);
|
||||
}
|
||||
|
||||
$order['createdAt'] = $order_data['date_added'];
|
||||
|
||||
if ($this->settings[$this->moduleTitle . '_apiversion'] != 'v5') {
|
||||
$order['paymentType'] = $payment_code;
|
||||
if ($couponTotal > 0) {
|
||||
$order['discount'] = $couponTotal;
|
||||
}
|
||||
} else {
|
||||
if ($couponTotal > 0) {
|
||||
$order['discountManualAmount'] = $couponTotal;
|
||||
}
|
||||
}
|
||||
|
||||
$country = isset($order_data['shipping_country']) ? $order_data['shipping_country'] : '' ;
|
||||
|
||||
$order['delivery'] = array(
|
||||
'code' => isset($delivery_code) ? $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']
|
||||
))
|
||||
)
|
||||
);
|
||||
|
||||
if (!empty($deliveryCost)){
|
||||
$order['delivery']['cost'] = $deliveryCost;
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
if ($this->settings[$this->moduleTitle . '_apiversion'] != 'v3') {
|
||||
$item = array(
|
||||
'offer' => array(
|
||||
'externalId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id']
|
||||
),
|
||||
'productName' => $product['name'],
|
||||
'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;
|
||||
|
||||
if (isset($order_data['order_status_id']) && $order_data['order_status_id'] > 0) {
|
||||
$order['status'] = $this->settings[$this->moduleTitle . '_status'][$order_data['order_status_id']];
|
||||
} elseif (isset($order_data['order_status_id']) && $order_data['order_status_id'] == 0) {
|
||||
$order['status'] = $this->settings[$this->moduleTitle . '_missing_status'];
|
||||
}
|
||||
|
||||
if (isset($this->settings[$this->moduleTitle . '_custom_field']) && $order_data['custom_field']) {
|
||||
$customFields = $order_data['custom_field'];
|
||||
|
||||
foreach ($customFields as $key => $value) {
|
||||
if (isset($this->settings[$this->moduleTitle . '_custom_field']['o_' . $key])) {
|
||||
$customFieldsToCrm[$this->settings[$this->moduleTitle . '_custom_field']['o_' . $key]] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($customFieldsToCrm)) {
|
||||
$order['customFields'] = $customFieldsToCrm;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$payment = array(
|
||||
'externalId' => $order_id,
|
||||
'type' => $payment_code,
|
||||
'amount' => $totals['total']
|
||||
);
|
||||
|
||||
if (!$create) {
|
||||
$payment['order'] = array(
|
||||
'externalId' => $order_id
|
||||
);
|
||||
}
|
||||
|
||||
$order['payments'][] = $payment;
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update payment in CRM
|
||||
*
|
||||
* @param array $order_payment
|
||||
* @param int $orderId
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function updatePayment($order_payment, $orderId, $retailcrmApiClient) {
|
||||
$response_order = $retailcrmApiClient->ordersGet($orderId);
|
||||
|
||||
if ($response_order->isSuccessful()) {
|
||||
$order_info = $response_order['order'];
|
||||
}
|
||||
|
||||
foreach ($order_info['payments'] as $payment_data) {
|
||||
if (isset($payment_data['externalId']) && $payment_data['externalId'] == $orderId) {
|
||||
$payment = $payment_data;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($payment) && $payment['type'] != $order_payment['type']) {
|
||||
$response = $retailcrmApiClient->ordersPaymentDelete($payment['id']);
|
||||
|
||||
if ($response->isSuccessful()) {
|
||||
$retailcrmApiClient->ordersPaymentCreate($order_payment);
|
||||
}
|
||||
} elseif (isset($payment) && $payment['type'] == $order_payment['type']) {
|
||||
$retailcrmApiClient->ordersPaymentEdit($order_payment);
|
||||
}
|
||||
}
|
||||
|
||||
private function searchCustomer($phone, $email, $retailcrmApiClient) {
|
||||
$customer = array();
|
||||
|
||||
$response = $retailcrmApiClient->customersList(
|
||||
array(
|
||||
'name' => $phone,
|
||||
'email' => $email
|
||||
),
|
||||
1,
|
||||
100
|
||||
);
|
||||
|
||||
if ($response->isSuccessful() && isset($response['customers'])) {
|
||||
$customers = $response['customers'];
|
||||
|
||||
if ($customers) {
|
||||
$customer = end($customers);
|
||||
}
|
||||
}
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $totals
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function explodeTotals($totals)
|
||||
{
|
||||
$resultTotals = array();
|
||||
|
||||
foreach ($totals as $total) {
|
||||
$resultTotals[$total['code']] = $total['value'];
|
||||
}
|
||||
|
||||
return $resultTotals;
|
||||
return $query->rows;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
class ModelExtensionRetailcrmProducts extends Model {
|
||||
public function getProductOptions($product_id) {
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
return $this->model_catalog_product->getProductOptions($product_id);
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ if (!isset($cli_action)) {
|
||||
}
|
||||
|
||||
// Version
|
||||
$version = '2.3.0';
|
||||
$version = '3.1';
|
||||
$indexFile = file_get_contents(realpath(dirname(__FILE__)) . '/../../index.php');
|
||||
preg_match("/define\([\s]*['\"]VERSION['\"][\s]*,[\s]*['\"](.*)['\"][\s]*\)[\s]*;/mi", $indexFile, $versionMatches);
|
||||
|
||||
@ -132,16 +132,13 @@ $registry->set('cache', $cache);
|
||||
|
||||
$registry->set('response', $response);
|
||||
|
||||
if (version_compare(VERSION, '3.0', '<')) {
|
||||
$session = new Session();
|
||||
} else {
|
||||
$session = new Session($config->get('session_engine'), $registry);
|
||||
}
|
||||
$session = new Session($config->get('session_engine'), $registry);
|
||||
|
||||
$registry->set('session', $session);
|
||||
|
||||
$languages = array();
|
||||
$query = $db->query("SELECT * FROM " . DB_PREFIX . "language");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$languages[$result['code']] = $result;
|
||||
}
|
||||
@ -149,33 +146,24 @@ foreach ($query->rows as $result) {
|
||||
$adminLanguageCode = $config->get('config_admin_language');
|
||||
$config->set('config_language_id', $languages[$adminLanguageCode]['language_id']);
|
||||
|
||||
if (version_compare(VERSION, '2.3', '<')) {
|
||||
$language = new Language($languages[$adminLanguageCode]['directory']);
|
||||
} else {
|
||||
$language = new Language($adminLanguageCode);
|
||||
}
|
||||
$language = new Language($languages[$adminLanguageCode]['directory']);
|
||||
|
||||
if(isset($languages[$adminLanguageCode]['filename'])) {
|
||||
$language->load($languages[$adminLanguageCode]['filename']);
|
||||
} else {
|
||||
$language->load($languages[$adminLanguageCode]['directory']);
|
||||
}
|
||||
|
||||
$registry->set('language', $language);
|
||||
|
||||
$document = new Document();
|
||||
$registry->set('document', $document);
|
||||
|
||||
|
||||
$registry->set('currency', new Cart\Currency($registry));
|
||||
$registry->set('weight', new Cart\Weight($registry));
|
||||
$registry->set('length', new Cart\Length($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 Router($registry);
|
||||
|
||||
$action = new Action($cli_action);
|
||||
$controller->dispatch($action, new Action('error/not_found'));
|
||||
|
@ -1,3 +0,0 @@
|
||||
<?php
|
||||
$cli_action = 'extension/module/retailcrm/icml';
|
||||
require_once('dispatch.php');
|
@ -1,4 +0,0 @@
|
||||
<?php
|
||||
$cli_action = 'extension/module/retailcrm/prices';
|
||||
require_once('dispatch.php');
|
||||
|
@ -1,831 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* API client class
|
||||
*
|
||||
* @category RetailCrm
|
||||
* @package RetailCrm
|
||||
* @author RetailCrm <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion3
|
||||
*/
|
||||
class RetailcrmApiClient3
|
||||
{
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* Site code
|
||||
*/
|
||||
protected $siteCode;
|
||||
|
||||
/**
|
||||
* Client creating
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $apiKey
|
||||
* @param string $site
|
||||
* @return mixed
|
||||
*/
|
||||
public function __construct($url, $apiKey, $version = null, $site = null)
|
||||
{
|
||||
if ('/' != substr($url, strlen($url) - 1, 1)) {
|
||||
$url .= '/';
|
||||
}
|
||||
|
||||
$url = $version == null ? $url . 'api' : $url . 'api/' . $version;
|
||||
|
||||
$this->client = new RetailcrmHttpClient($url, array('apiKey' => $apiKey));
|
||||
$this->siteCode = $site;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns api versions list
|
||||
*
|
||||
* @throws \RetailCrm\Exception\InvalidJsonException
|
||||
* @throws \RetailCrm\Exception\CurlException
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return ApiResponse
|
||||
*/
|
||||
public function apiVersions()
|
||||
{
|
||||
return $this->client->makeRequest('/api-versions', RetailcrmHttpClient::METHOD_GET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a order
|
||||
*
|
||||
* @param array $order
|
||||
* @param string $site (default: null)
|
||||
* @return ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
public function deliveryServicesList()
|
||||
{
|
||||
return $this->client->makeRequest('/reference/delivery-services', RetailcrmHttpClient::METHOD_GET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns deliveryTypes list
|
||||
*
|
||||
* @return ApiResponse
|
||||
*/
|
||||
public function deliveryTypesList()
|
||||
{
|
||||
return $this->client->makeRequest('/reference/delivery-types', RetailcrmHttpClient::METHOD_GET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns orderMethods list
|
||||
*
|
||||
* @return ApiResponse
|
||||
*/
|
||||
public function orderMethodsList()
|
||||
{
|
||||
return $this->client->makeRequest('/reference/order-methods', RetailcrmHttpClient::METHOD_GET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns orderTypes list
|
||||
*
|
||||
* @return ApiResponse
|
||||
*/
|
||||
public function orderTypesList()
|
||||
{
|
||||
return $this->client->makeRequest('/reference/order-types', RetailcrmHttpClient::METHOD_GET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns paymentStatuses list
|
||||
*
|
||||
* @return ApiResponse
|
||||
*/
|
||||
public function paymentStatusesList()
|
||||
{
|
||||
return $this->client->makeRequest('/reference/payment-statuses', RetailcrmHttpClient::METHOD_GET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns paymentTypes list
|
||||
*
|
||||
* @return ApiResponse
|
||||
*/
|
||||
public function paymentTypesList()
|
||||
{
|
||||
return $this->client->makeRequest('/reference/payment-types', RetailcrmHttpClient::METHOD_GET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns productStatuses list
|
||||
*
|
||||
* @return ApiResponse
|
||||
*/
|
||||
public function productStatusesList()
|
||||
{
|
||||
return $this->client->makeRequest('/reference/product-statuses', RetailcrmHttpClient::METHOD_GET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns statusGroups list
|
||||
*
|
||||
* @return ApiResponse
|
||||
*/
|
||||
public function statusGroupsList()
|
||||
{
|
||||
return $this->client->makeRequest('/reference/status-groups', RetailcrmHttpClient::METHOD_GET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns statuses list
|
||||
*
|
||||
* @return ApiResponse
|
||||
*/
|
||||
public function statusesList()
|
||||
{
|
||||
return $this->client->makeRequest('/reference/statuses', RetailcrmHttpClient::METHOD_GET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns sites list
|
||||
*
|
||||
* @return ApiResponse
|
||||
*/
|
||||
public function sitesList()
|
||||
{
|
||||
return $this->client->makeRequest('/reference/sites', RetailcrmHttpClient::METHOD_GET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns stores list
|
||||
*
|
||||
* @return ApiResponse
|
||||
*/
|
||||
public function storesList()
|
||||
{
|
||||
return $this->client->makeRequest('/reference/stores', RetailcrmHttpClient::METHOD_GET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit deliveryService
|
||||
*
|
||||
* @param array $data delivery service data
|
||||
* @return ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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 ApiResponse
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -14,9 +14,11 @@ class OpencartApiClient {
|
||||
|
||||
public function __construct(Registry &$registry) {
|
||||
$this->registry = $registry;
|
||||
$moduleTitle = $this->getModuleTitle();
|
||||
$settings = $this->model_setting_setting->getSetting($moduleTitle);
|
||||
$this->cookieFileName = $settings[$moduleTitle . '_apikey'];
|
||||
$settings = $this->model_setting_setting->getSetting(\Retailcrm\Retailcrm::MODULE);
|
||||
|
||||
if (isset($settings[\Retailcrm\Retailcrm::MODULE . '_apikey'])) {
|
||||
$this->cookieFileName = $settings[\Retailcrm\Retailcrm::MODULE . '_apikey'];
|
||||
}
|
||||
|
||||
$this->auth();
|
||||
}
|
||||
@ -47,22 +49,19 @@ class OpencartApiClient {
|
||||
}
|
||||
|
||||
private function request($method, $getParams, $postParams) {
|
||||
$this->load->model('setting/store');
|
||||
$opencartStoreInfo = $this->model_setting_store->getStore($this->opencartStoreId);
|
||||
|
||||
if ($this->apiToken !== false) {
|
||||
if (version_compare(VERSION, '3.0', '<')) {
|
||||
$getParams['key'] = $this->apiToken['key'];
|
||||
} else {
|
||||
$getParams['key'] = $this->apiToken['key'];
|
||||
$getParams['username'] = $this->apiToken['username'];
|
||||
$getParams['key'] = $this->apiToken['key'];
|
||||
$getParams['username'] = $this->apiToken['username'];
|
||||
|
||||
if (isset($this->session->data['user_token'])) {
|
||||
$getParams['api_token'] = $this->session->data['user_token'];
|
||||
} else {
|
||||
$session = $this->registry->get('session');
|
||||
$session->start();
|
||||
$getParams['api_token'] = $session->getId();
|
||||
}
|
||||
if (isset($this->session->data['user_token'])) {
|
||||
$getParams['api_token'] = $this->session->data['user_token'];
|
||||
} else {
|
||||
$session = $this->registry->get('session');
|
||||
$session->start();
|
||||
$getParams['api_token'] = $session->getId();
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +142,7 @@ class OpencartApiClient {
|
||||
|
||||
/**
|
||||
* Get delivery types
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDeliveryTypes()
|
||||
@ -153,10 +152,10 @@ class OpencartApiClient {
|
||||
|
||||
/**
|
||||
* Add history order
|
||||
*
|
||||
*
|
||||
* @param int $order_id
|
||||
* @param int $order_status_id
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addHistory($order_id, $order_status_id)
|
||||
@ -166,7 +165,7 @@ class OpencartApiClient {
|
||||
|
||||
/**
|
||||
* Get module name
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getModuleTitle()
|
@ -6,37 +6,43 @@
|
||||
*/
|
||||
class RetailcrmProxy
|
||||
{
|
||||
|
||||
private $api;
|
||||
private $log;
|
||||
private $debug;
|
||||
|
||||
public function __construct($url, $key, $log, $version = null)
|
||||
{
|
||||
public function __construct($url, $key, $log, $version = null, $debug = false)
|
||||
{
|
||||
switch ($version) {
|
||||
case 'v5':
|
||||
$this->api = new RetailcrmApiClient5($url, $key, $version);
|
||||
break;
|
||||
case 'v4':
|
||||
$this->api = new RetailcrmApiClient4($url, $key, $version);
|
||||
break;
|
||||
case 'v3':
|
||||
$this->api = new RetailcrmApiClient3($url, $key, $version);
|
||||
break;
|
||||
case null:
|
||||
$this->api = new RetailcrmApiClient3($url, $key, $version);
|
||||
|
||||
default:
|
||||
$this->api = new RetailcrmApiClient5($url, $key, $version);
|
||||
break;
|
||||
}
|
||||
|
||||
$this->log = $log;
|
||||
$this->debug = $debug;
|
||||
}
|
||||
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
{
|
||||
$date = date('[Y-m-d H:i:s]');
|
||||
|
||||
|
||||
try {
|
||||
$response = call_user_func_array(array($this->api, $method), $arguments);
|
||||
|
||||
if ($this->debug) {
|
||||
$logger = new Log($method);
|
||||
$logger->write(
|
||||
array(
|
||||
'data' => $arguments,
|
||||
'response' => $response
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (!$response->isSuccessful()) {
|
||||
error_log($date . " [$method] " . $response->getErrorMsg() . "\n", 3, $this->log);
|
||||
if (isset($response['errors'])) {
|
213
src/upload/system/library/retailcrm/base.php
Normal file
213
src/upload/system/library/retailcrm/base.php
Normal file
@ -0,0 +1,213 @@
|
||||
<?php
|
||||
|
||||
namespace Retailcrm;
|
||||
|
||||
abstract class Base
|
||||
{
|
||||
protected $registry;
|
||||
protected $data = array();
|
||||
|
||||
/**
|
||||
* Send to crm
|
||||
*
|
||||
* @param $retailcrm_api_client
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function create($retailcrm_api_client);
|
||||
|
||||
/**
|
||||
* Edit in crm
|
||||
*
|
||||
* @param $retailcrm_api_client
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function edit($retailcrm_api_client);
|
||||
|
||||
/**
|
||||
* Base constructor.
|
||||
*
|
||||
* @param $registry
|
||||
*/
|
||||
public function __construct($registry)
|
||||
{
|
||||
$this->registry = $registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($name) {
|
||||
return $this->registry->get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getData() {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $field
|
||||
* @param $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function setField($field, $value) {
|
||||
if (!array_key_exists($field, $this->data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->data[$field] = $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $fields
|
||||
*/
|
||||
public function setFields($fields) {
|
||||
foreach ($fields as $field => $value) {
|
||||
$this->setField($field, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param $element
|
||||
*/
|
||||
public function setDataArray($data, $element) {
|
||||
if (is_array($data)) {
|
||||
$this->setField($element, $data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare data array
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function prepare($data)
|
||||
{
|
||||
unset($data);
|
||||
$this->data = Retailcrm::filterRecursive($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload to CRM
|
||||
*
|
||||
* @param $retailcrm_api_client
|
||||
* @param array $data
|
||||
* @param string $method
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function upload($retailcrm_api_client, $data = array(), $method = 'orders')
|
||||
{
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$upload = array();
|
||||
$countOrders = count($data);
|
||||
$countIterations = (int) ($countOrders / 50);
|
||||
|
||||
foreach ($data as $key => $entity) {
|
||||
$this->prepare($entity);
|
||||
$upload[] = $this->data;
|
||||
$this->resetData();
|
||||
|
||||
if ($countIterations > 0) {
|
||||
unset($data[$key]);
|
||||
}
|
||||
|
||||
if (($countIterations == 0 && count($data) == count($upload))
|
||||
|| count($upload) == 50
|
||||
) {
|
||||
/** @var \RetailcrmApiClient5 $retailcrm_api_client */
|
||||
$retailcrm_api_client->{$method . 'Upload'}($upload);
|
||||
$upload = array();
|
||||
$countIterations--;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $custom_fields
|
||||
* @param array $setting
|
||||
* @param string $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareCustomFields($custom_fields, $setting, $prefix) {
|
||||
$result = array();
|
||||
|
||||
if (!$custom_fields || empty($custom_fields)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
foreach ($custom_fields as $loc => $custom_field) {
|
||||
if (\is_int($loc)) {
|
||||
$result = $this->getCustomFields($custom_field, $setting, $prefix);
|
||||
} elseif (\is_string($loc)) {
|
||||
foreach ($custom_field as $field) {
|
||||
if (!$field) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result = $this->getCustomFields($field, $setting, $prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $custom_fields
|
||||
* @param array $setting
|
||||
* @param string $prefix
|
||||
*
|
||||
* @return array $result
|
||||
*/
|
||||
private function getCustomFields($custom_fields, $setting, $prefix) {
|
||||
$result = array();
|
||||
|
||||
foreach ($custom_fields as $key => $field) {
|
||||
if (isset($setting[\Retailcrm\Retailcrm::MODULE. '_custom_field'][$prefix . $key])) {
|
||||
$result[$setting[\Retailcrm\Retailcrm::MODULE. '_custom_field'][$prefix . $key]] = $field;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset data on default
|
||||
*/
|
||||
private function resetData()
|
||||
{
|
||||
$numericValues = array(
|
||||
'externalId',
|
||||
'discountManualAmount'
|
||||
);
|
||||
|
||||
foreach ($this->data as $field => $value) {
|
||||
if (in_array($field, $numericValues)) {
|
||||
$this->data[$field] = 0;
|
||||
} elseif (is_array($value)) {
|
||||
$this->data[$field] = array();
|
||||
} else {
|
||||
$this->data[$field] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
src/upload/system/library/retailcrm/custom/Base.php
Normal file
13
src/upload/system/library/retailcrm/custom/Base.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Retailcrm\Custom;
|
||||
|
||||
interface Base
|
||||
{
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function prepare(array $data);
|
||||
}
|
93
src/upload/system/library/retailcrm/customer.php
Normal file
93
src/upload/system/library/retailcrm/customer.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Retailcrm;
|
||||
|
||||
class Customer extends Base
|
||||
{
|
||||
protected $registry;
|
||||
protected $data = array(
|
||||
'externalId' => 0,
|
||||
'createdAt' => null,
|
||||
'firstName' => null,
|
||||
'lastName' => null,
|
||||
'patronymic' => null,
|
||||
'email' => null,
|
||||
'phones' => array(),
|
||||
'address' => array(),
|
||||
'customFields' => array()
|
||||
);
|
||||
|
||||
public function prepare($customer) {
|
||||
if (file_exists(DIR_SYSTEM . 'library/retailcrm/custom/customer.php')) {
|
||||
$custom = new \Retailcrm\Custom\Customer($this->registry);
|
||||
$this->data = $custom->prepare($customer);
|
||||
} else {
|
||||
$this->load->model('setting/setting');
|
||||
$setting = $this->model_setting_setting->getSetting(\Retailcrm\Retailcrm::MODULE);
|
||||
|
||||
if (isset($customer['firstname']) && $customer['firstname']) {
|
||||
$this->setField('firstName', $customer['firstname']);
|
||||
}
|
||||
|
||||
if (isset($customer['lastname']) && $customer['lastname']) {
|
||||
$this->setField('lastName', $customer['lastname']);
|
||||
}
|
||||
|
||||
if (isset($customer['telephone']) && $customer['telephone']) {
|
||||
$phones = array(
|
||||
array(
|
||||
'number' => $customer['telephone']
|
||||
)
|
||||
);
|
||||
$this->setDataArray($phones, 'phones');
|
||||
}
|
||||
|
||||
$this->setField('email', $customer['email']);
|
||||
$this->setField('createdAt', date('Y-m-d H:i:s'));
|
||||
|
||||
if (isset($customer['customer_id']) && !$this->data['externalId']) {
|
||||
$this->setField('externalId', $customer['customer_id']);
|
||||
}
|
||||
|
||||
if (isset($settings[\Retailcrm\Retailcrm::MODULE . '_custom_field']) && $customer['custom_field']) {
|
||||
$custom_fields = $this->prepareCustomFields($customer['custom_field'], $setting, 'c_');
|
||||
|
||||
if ($custom_fields) {
|
||||
$this->setDataArray($custom_fields, 'customFields');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parent::prepare($customer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $retailcrm_api_client
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function create($retailcrm_api_client) {
|
||||
if ($retailcrm_api_client === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$response = $retailcrm_api_client->customersCreate($this->data);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $retailcrm_api_client
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function edit($retailcrm_api_client) {
|
||||
if ($retailcrm_api_client === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$response = $retailcrm_api_client->customersEdit($this->data);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
388
src/upload/system/library/retailcrm/order.php
Normal file
388
src/upload/system/library/retailcrm/order.php
Normal file
@ -0,0 +1,388 @@
|
||||
<?php
|
||||
|
||||
namespace Retailcrm;
|
||||
|
||||
class Order extends Base
|
||||
{
|
||||
protected $registry;
|
||||
protected $data = array(
|
||||
'number' => 0,
|
||||
'createdAt' => null,
|
||||
'countryIso' => null,
|
||||
'externalId' => 0,
|
||||
'customer' => array(),
|
||||
'status' => null,
|
||||
'firstName' => null,
|
||||
'lastName' => null,
|
||||
'patronymic' => null,
|
||||
'email' => null,
|
||||
'phone' => null,
|
||||
'discountManualAmount' => 0,
|
||||
'customerComment' => null,
|
||||
'items' => array(),
|
||||
'delivery' => array(),
|
||||
'customFields' => array(),
|
||||
'payments' => array()
|
||||
);
|
||||
|
||||
public function prepare($order) {
|
||||
if (file_exists(DIR_SYSTEM . 'library/retailcrm/custom/order.php')) {
|
||||
$custom = new \Retailcrm\Custom\Order($this->registry);
|
||||
$this->data = $custom->prepare($order);
|
||||
} else {
|
||||
$this->load->model('setting/setting');
|
||||
$this->load->model('catalog/product');
|
||||
$this->load->model('extension/retailcrm/products');
|
||||
|
||||
$settings = $this->model_setting_setting->getSetting(\Retailcrm\Retailcrm::MODULE);
|
||||
$delivery_settings = isset($settings[\Retailcrm\Retailcrm::MODULE . '_delivery'])
|
||||
? $settings[\Retailcrm\Retailcrm::MODULE . '_delivery']
|
||||
: array();
|
||||
$payments_settings = isset($settings[\Retailcrm\Retailcrm::MODULE . '_payment'])
|
||||
? $settings[\Retailcrm\Retailcrm::MODULE . '_payment']
|
||||
: array();
|
||||
$status_settings = isset($settings[\Retailcrm\Retailcrm::MODULE . '_status'])
|
||||
? $settings[\Retailcrm\Retailcrm::MODULE . '_status']
|
||||
: array();
|
||||
|
||||
$totals = $this->explodeTotals($order['totals']);
|
||||
$coupon_total = 0;
|
||||
$delivery_cost = 0;
|
||||
|
||||
if (isset($totals['shipping'])) {
|
||||
$delivery_cost = $totals['shipping'];
|
||||
}
|
||||
|
||||
if (isset($totals['coupon'])) {
|
||||
$coupon_total += abs($totals['coupon']);
|
||||
}
|
||||
|
||||
if (isset($totals['reward'])) {
|
||||
$coupon_total += abs($totals['reward']);
|
||||
}
|
||||
|
||||
if (isset($order['order_status_id']) && $order['order_status_id'] > 0) {
|
||||
$status = $status_settings[$order['order_status_id']];
|
||||
} elseif (!isset($order['order_status_id'])) {
|
||||
$status = $settings[\Retailcrm\Retailcrm::MODULE . '_missing_status'];
|
||||
}
|
||||
|
||||
if (isset($settings[\Retailcrm\Retailcrm::MODULE . '_order_number'])
|
||||
&& $settings[\Retailcrm\Retailcrm::MODULE . '_order_number'] == 1
|
||||
) {
|
||||
$this->setField('number', $order['order_id']);
|
||||
}
|
||||
|
||||
$fields = array(
|
||||
'firstName' => $order['firstname'],
|
||||
'lastName' => $order['lastname'],
|
||||
'email' => $order['email'],
|
||||
'phone' => $order['telephone'],
|
||||
'customerComment' => $order['comment'],
|
||||
'createdAt' => isset($order['date_added']) ? $order['date_added'] : date('Y-m-d H:i:s'),
|
||||
'discountManualAmount' => $coupon_total,
|
||||
'status' => $status
|
||||
);
|
||||
|
||||
if (isset($order['order_id']) && !$this->data['externalId']) {
|
||||
$fields['externalId'] = $order['order_id'];
|
||||
}
|
||||
|
||||
$this->setFields($fields);
|
||||
|
||||
if (isset($order['shipping_code'])) {
|
||||
$delivery_code = $this->getDeliveryMethod($order['shipping_code'], $delivery_settings);
|
||||
}
|
||||
|
||||
$delivery = array(
|
||||
'address' => array(
|
||||
'index' => isset($order['shipping_postcode']) ? $order['shipping_postcode'] : '',
|
||||
'city' => isset($order['shipping_city']) ? $order['shipping_city'] : '',
|
||||
'region' => isset($order['shipping_zone']) ? $order['shipping_zone'] : '',
|
||||
'text' => implode(', ', array(
|
||||
isset($order['shipping_postcode']) ? $order['shipping_postcode'] : '',
|
||||
isset($order['shipping_country']) ? $order['shipping_country'] : '',
|
||||
isset($order['shipping_city']) ? $order['shipping_city'] : '',
|
||||
isset($order['shipping_address_1']) ? $order['shipping_address_1'] : '',
|
||||
isset($order['shipping_address_2']) ? $order['shipping_address_2'] : ''
|
||||
))
|
||||
)
|
||||
);
|
||||
|
||||
if (isset($delivery_code)) {
|
||||
$delivery['code'] = $delivery_code;
|
||||
}
|
||||
|
||||
if ($delivery_cost) {
|
||||
$delivery['cost'] = $delivery_cost;
|
||||
}
|
||||
|
||||
$this->setDataArray($delivery, 'delivery');
|
||||
$this->setOrderProducts($order['products']);
|
||||
$payments = array();
|
||||
|
||||
if (isset($payments_settings[$order['payment_code']])) {
|
||||
$payment = array(
|
||||
'order' => array(
|
||||
'externalId' => $order['order_id']
|
||||
),
|
||||
'externalId' => $order['order_id'],
|
||||
'type' => $payments_settings[$order['payment_code']],
|
||||
'amount' => $order['total']
|
||||
);
|
||||
|
||||
$payments[] = $payment;
|
||||
}
|
||||
|
||||
$this->setDataArray($payments, 'payments');
|
||||
|
||||
if (isset($settings[\Retailcrm\Retailcrm::MODULE . '_custom_field']) && $order['custom_field']) {
|
||||
$custom_fields = $this->prepareCustomFields($order['custom_field'], $settings, 'o_');
|
||||
|
||||
if ($custom_fields) {
|
||||
$this->setDataArray($custom_fields, 'customFields');
|
||||
}
|
||||
}
|
||||
|
||||
if ($order['customer_id']) {
|
||||
$this->setDataArray(
|
||||
array(
|
||||
'externalId' => $order['customer_id']
|
||||
),
|
||||
'customer'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
parent::prepare($order);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $retailcrm_api_client
|
||||
*
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function create($retailcrm_api_client) {
|
||||
if ($retailcrm_api_client === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$this->data['customer']) {
|
||||
$customer = $this->searchCustomer($this->data['phone'], $this->data['email'], $retailcrm_api_client);
|
||||
|
||||
if ($customer) {
|
||||
$this->setDataArray(
|
||||
array(
|
||||
'id' => $customer['id']
|
||||
),
|
||||
'customer'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$response = $retailcrm_api_client->ordersCreate($this->data);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $retailcrm_api_client
|
||||
*
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function edit($retailcrm_api_client) {
|
||||
if ($retailcrm_api_client === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$order_payment = reset($this->data['payments']);
|
||||
unset($this->data['payments']);
|
||||
|
||||
$response = $retailcrm_api_client->ordersEdit($this->data);
|
||||
|
||||
if ($response->isSuccessful()) {
|
||||
$this->updatePayment($order_payment, $this->data['externalId'], $retailcrm_api_client);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update payment in CRM
|
||||
*
|
||||
* @param array $order_payment
|
||||
* @param int $order_id
|
||||
* @param \RetailcrmProxy $retailcrm_api_client
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function updatePayment($order_payment, $order_id, $retailcrm_api_client) {
|
||||
$response_order = $retailcrm_api_client->ordersGet($order_id);
|
||||
|
||||
if (!$response_order->isSuccessful()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$order_info = $response_order['order'];
|
||||
|
||||
foreach ($order_info['payments'] as $payment_data) {
|
||||
if (isset($payment_data['externalId']) && $payment_data['externalId'] == $order_id) {
|
||||
$payment = $payment_data;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($payment) && $payment['type'] != $order_payment['type']) {
|
||||
$response = $retailcrm_api_client->ordersPaymentDelete($payment['id']);
|
||||
if ($response->isSuccessful()) {
|
||||
$retailcrm_api_client->ordersPaymentCreate($order_payment);
|
||||
}
|
||||
} elseif (isset($payment) && $payment['type'] == $order_payment['type']) {
|
||||
$retailcrm_api_client->ordersPaymentEdit($order_payment);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $phone
|
||||
* @param $email
|
||||
* @param $retailcrm_api_client
|
||||
*
|
||||
* @return array|mixed
|
||||
*/
|
||||
private function searchCustomer($phone, $email, $retailcrm_api_client) {
|
||||
$customer = array();
|
||||
$response = $retailcrm_api_client->customersList(
|
||||
array(
|
||||
'name' => $phone,
|
||||
'email' => $email
|
||||
),
|
||||
1,
|
||||
100
|
||||
);
|
||||
|
||||
if ($response->isSuccessful() && isset($response['customers'])) {
|
||||
$customers = $response['customers'];
|
||||
if ($customers) {
|
||||
$customer = end($customers);
|
||||
}
|
||||
}
|
||||
return $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $shipping_code
|
||||
* @param array $deliveries
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function getDeliveryMethod($shipping_code, $deliveries) {
|
||||
if (!empty($shipping_code)) {
|
||||
$shipping_code_array = explode('.', $shipping_code);
|
||||
$shipping_module = $shipping_code_array[0];
|
||||
|
||||
if (isset($deliveries[$shipping_code])) {
|
||||
$delivery_code = $deliveries[$shipping_code];
|
||||
} elseif (isset($deliveries[$shipping_module])) {
|
||||
$delivery_code = $deliveries[$shipping_module];
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($delivery_code) && isset($shipping_module) && $deliveries) {
|
||||
$delivery = '';
|
||||
|
||||
array_walk($deliveries, function ($item, $key) use ($shipping_module, &$delivery) {
|
||||
if (strripos($item, $shipping_module) !== false) {
|
||||
$delivery = $item;
|
||||
}
|
||||
});
|
||||
|
||||
$delivery_code = $deliveries[$delivery];
|
||||
}
|
||||
|
||||
return isset($delivery_code) ? $delivery_code : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $products
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function setOrderProducts($products) {
|
||||
$offer_options = array('select', 'radio');
|
||||
$items = array();
|
||||
|
||||
foreach ($products as $product) {
|
||||
if (!empty($product['option'])) {
|
||||
$offer_id = '';
|
||||
$options = array();
|
||||
$properties = array();
|
||||
|
||||
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'], $offer_options)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$productOptions = $this->model_extension_retailcrm_products->getProductOptions($product['product_id']);
|
||||
|
||||
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);
|
||||
|
||||
foreach ($options as $optionKey => $optionValue) {
|
||||
$offer_id .= $optionKey . '-' . $optionValue;
|
||||
}
|
||||
}
|
||||
|
||||
$item = array(
|
||||
'offer' => array(
|
||||
'externalId' => !empty($offer_id) ? $product['product_id'] . '#' . $offer_id : $product['product_id']
|
||||
),
|
||||
'productName' => $product['name'],
|
||||
'initialPrice' => $product['price'],
|
||||
'quantity' => $product['quantity'],
|
||||
);
|
||||
|
||||
if (!empty($properties)) {
|
||||
$item['properties'] = $properties;
|
||||
}
|
||||
|
||||
$items[] = $item;
|
||||
}
|
||||
|
||||
$this->setDataArray($items, 'items');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $totals
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function explodeTotals($totals)
|
||||
{
|
||||
$resultTotals = array();
|
||||
|
||||
foreach ($totals as $total) {
|
||||
$resultTotals[$total['code']] = $total['value'];
|
||||
}
|
||||
|
||||
return $resultTotals;
|
||||
}
|
||||
}
|
@ -1,13 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace retailcrm;
|
||||
namespace Retailcrm;
|
||||
|
||||
require_once 'bootstrap.php';
|
||||
require_once 'api/bootstrap.php';
|
||||
|
||||
class Retailcrm {
|
||||
protected $apiClient;
|
||||
protected $registry;
|
||||
|
||||
const MODULE = 'module_retailcrm';
|
||||
|
||||
public function __construct($registry)
|
||||
{
|
||||
$this->registry = $registry;
|
||||
@ -17,6 +18,10 @@ class Retailcrm {
|
||||
return $this->registry->get($name);
|
||||
}
|
||||
|
||||
public function createObject($object) {
|
||||
return new $object($this->registry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get api client object
|
||||
*
|
||||
@ -24,25 +29,31 @@ class Retailcrm {
|
||||
* @param string $apiKey (default = null)
|
||||
* @param string $apiVersion (default = null)
|
||||
*
|
||||
* @return mixed object | boolean
|
||||
* @return mixed object | boolean
|
||||
*/
|
||||
public function getApiClient($apiUrl = null, $apiKey = null, $apiVersion = null)
|
||||
{
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$setting = $this->model_setting_setting->getSetting($this->getModuleTitle());
|
||||
$setting = $this->model_setting_setting->getSetting(self::MODULE);
|
||||
|
||||
if ($apiUrl === null && $apiKey === null) {
|
||||
$apiUrl = isset($setting[$this->getModuleTitle() . '_url'])
|
||||
? $setting[$this->getModuleTitle() . '_url'] : '';
|
||||
$apiKey = isset($setting[$this->getModuleTitle() . '_apikey'])
|
||||
? $setting[$this->getModuleTitle() . '_apikey'] : '';
|
||||
$apiVersion = isset($setting[$this->getModuleTitle() . '_apiversion'])
|
||||
? $setting[$this->getModuleTitle() . '_apiversion'] : '';
|
||||
$apiUrl = isset($setting[self::MODULE . '_url'])
|
||||
? $setting[self::MODULE . '_url'] : '';
|
||||
$apiKey = isset($setting[self::MODULE . '_apikey'])
|
||||
? $setting[self::MODULE . '_apikey'] : '';
|
||||
$apiVersion = isset($setting[self::MODULE . '_apiversion'])
|
||||
? $setting[self::MODULE . '_apiversion'] : '';
|
||||
}
|
||||
|
||||
$debug = false;
|
||||
|
||||
if (isset($setting[self::MODULE . '_debug_mode']) && $setting[self::MODULE . '_debug_mode']) {
|
||||
$debug = true;
|
||||
}
|
||||
|
||||
if ($apiUrl && $apiKey) {
|
||||
return new \RetailcrmProxy($apiUrl, $apiKey, DIR_LOGS . 'retailcrm.log', $apiVersion);
|
||||
return new \RetailcrmProxy($apiUrl, $apiKey, DIR_LOGS . 'retailcrm.log', $apiVersion, $debug);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -60,48 +71,17 @@ class Retailcrm {
|
||||
return new \OpencartApiClient($registry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get module title for this version
|
||||
*
|
||||
* @return string $title
|
||||
*/
|
||||
public function getModuleTitle()
|
||||
{
|
||||
if (version_compare(VERSION, '3.0', '<')) {
|
||||
$title = 'retailcrm';
|
||||
} else {
|
||||
$title = 'module_retailcrm';
|
||||
}
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get token param name
|
||||
*
|
||||
* @return string $token
|
||||
*/
|
||||
public function getTokenTitle()
|
||||
{
|
||||
if (version_compare(VERSION, '3.0', '<')) {
|
||||
$token = 'token';
|
||||
} else {
|
||||
$token = 'user_token';
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
public function getOffers($product)
|
||||
{
|
||||
$this->load->model('extension/retailcrm/products');
|
||||
// Формируем офферы отнсительно доступных опций
|
||||
$options = $this->model_catalog_product->getProductOptions($product['product_id']);
|
||||
$options = $this->model_extension_retailcrm_products->getProductOptions($product['product_id']);
|
||||
$offerOptions = array('select', 'radio');
|
||||
$requiredOptions = array();
|
||||
$notRequiredOptions = array();
|
||||
// Оставляем опции связанные с вариациями товаров, сортируем по параметру обязательный или нет
|
||||
foreach($options as $option) {
|
||||
if(in_array($option['type'], $offerOptions)) {
|
||||
foreach ($options as $option) {
|
||||
if (in_array($option['type'], $offerOptions)) {
|
||||
if($option['required']) {
|
||||
$requiredOptions[] = $option;
|
||||
} else {
|
||||
@ -112,19 +92,19 @@ class Retailcrm {
|
||||
|
||||
$offers = array();
|
||||
// Сначала совмещаем все обязательные опции
|
||||
foreach($requiredOptions as $requiredOption) {
|
||||
foreach ($requiredOptions as $requiredOption) {
|
||||
// Если первая итерация
|
||||
if(empty($offers)) {
|
||||
foreach($requiredOption['product_option_value'] as $optionValue) {
|
||||
if (empty($offers)) {
|
||||
foreach ($requiredOption['product_option_value'] as $optionValue) {
|
||||
$offers[$requiredOption['product_option_id'].':'.$requiredOption['option_id'].'-'.$optionValue['option_value_id']] = array(
|
||||
'price' => (float)$optionValue['price'],
|
||||
'qty' => $optionValue['quantity']
|
||||
);
|
||||
}
|
||||
} else {
|
||||
foreach($offers as $optionKey => $optionAttr) {
|
||||
foreach ($offers as $optionKey => $optionAttr) {
|
||||
unset($offers[$optionKey]); // Работая в контексте обязательных опций не забываем удалять прошлые обязательные опции, т.к. они должны быть скомбинированы с другими обязательными опциями
|
||||
foreach($requiredOption['product_option_value'] as $optionValue) {
|
||||
foreach ($requiredOption['product_option_value'] as $optionValue) {
|
||||
$offers[$optionKey.'_'.$requiredOption['product_option_id'].':'.$requiredOption['option_id'].'-'.$optionValue['option_value_id']] = array(
|
||||
'price' => $optionAttr['price'] + (float)$optionValue['price'],
|
||||
'qty' => ($optionAttr['qty'] > $optionValue['quantity']) ?
|
||||
@ -134,21 +114,21 @@ class Retailcrm {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Совмещаем или добавляем необязательные опции, учитывая тот факт что обязательных опций может и не быть.
|
||||
foreach($notRequiredOptions as $notRequiredOption) {
|
||||
foreach ($notRequiredOptions as $notRequiredOption) {
|
||||
// Если обязательных опцией не оказалось и первая итерация
|
||||
if(empty($offers)) {
|
||||
if (empty($offers)) {
|
||||
$offers['0:0-0'] = 0; // В случае работы с необязательными опциями мы должны учитывать товарное предложение без опций, поэтому создадим "пустую" опцию
|
||||
foreach($notRequiredOption['product_option_value'] as $optionValue) {
|
||||
foreach ($notRequiredOption['product_option_value'] as $optionValue) {
|
||||
$offers[$notRequiredOption['product_option_id'].':'.$notRequiredOption['option_id'].'-'.$optionValue['option_value_id']] = array(
|
||||
'price' => (float)$optionValue['price'],
|
||||
'qty' => $optionValue['quantity']
|
||||
);
|
||||
}
|
||||
} else {
|
||||
foreach($offers as $optionKey => $optionAttr) {
|
||||
foreach($notRequiredOption['product_option_value'] as $optionValue) {
|
||||
foreach ($offers as $optionKey => $optionAttr) {
|
||||
foreach ($notRequiredOption['product_option_value'] as $optionValue) {
|
||||
$offers[$optionKey.'_'.$notRequiredOption['product_option_id'].':'.$notRequiredOption['option_id'].'-'.$optionValue['option_value_id']] = array(
|
||||
'price' => $optionAttr['price'] + (float)$optionValue['price'],
|
||||
'qty' => ($optionAttr['qty'] > $optionValue['quantity']) ?
|
||||
@ -159,10 +139,36 @@ class Retailcrm {
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($offers)) {
|
||||
if (empty($offers)) {
|
||||
$offers = array('0:0-0' => array('price' => '0', 'qty' => '0'));
|
||||
}
|
||||
|
||||
return $offers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter result array
|
||||
*
|
||||
* @param $haystack
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function filterRecursive($haystack)
|
||||
{
|
||||
foreach ($haystack as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$haystack[$key] = self::filterRecursive($haystack[$key]);
|
||||
}
|
||||
if (is_null($haystack[$key])
|
||||
|| $haystack[$key] === ''
|
||||
|| (is_array($haystack[$key]) && count($haystack[$key]) == 0)
|
||||
) {
|
||||
unset($haystack[$key]);
|
||||
} elseif (!is_array($value)) {
|
||||
$haystack[$key] = trim($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $haystack;
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
class ControllerRetailcrmAdminTest extends OpenCartTest
|
||||
{
|
||||
const MODULE_TITLE = 'retailcrm';
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$query = $this->db->query("SELECT permission from ".DB_PREFIX."user_group WHERE name = 'Administrator'");
|
||||
parent::setUp();
|
||||
|
||||
$query = $this->db->query("SELECT permission from " . DB_PREFIX . "user_group WHERE name = 'Administrator'");
|
||||
$permissions = json_decode($query->row['permission'],true);
|
||||
|
||||
if (!in_array('extension/module/retailcrm',$permissions['access'])) {
|
||||
if (!in_array('extension/module/retailcrm', $permissions['access'])) {
|
||||
$permissions['access'][] = 'extension/module/retailcrm';
|
||||
$this->db->query("UPDATE ".DB_PREFIX."user_group SET permission='".$this->db->escape(json_encode($permissions))."' WHERE name = 'Administrator'");
|
||||
}
|
||||
|
||||
$this->retailcrm = $this->getMockBuilder('\retailcrm\Retailcrm')
|
||||
$this->retailcrm = $this->getMockBuilder('\retailcrm\retailcrm')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
@ -22,36 +26,15 @@ class ControllerRetailcrmAdminTest extends OpenCartTest
|
||||
public function testIndex()
|
||||
{
|
||||
$this->login('admin', 'admin');
|
||||
|
||||
$response = $this->dispatchAction('extension/module/retailcrm');
|
||||
|
||||
$this->assertRegExp('/Connection settings/', $response->getOutput());
|
||||
}
|
||||
|
||||
public function testIcml()
|
||||
{
|
||||
$this->login('admin', 'admin');
|
||||
|
||||
$response = $this->dispatchAction('extension/module/retailcrm/icml');
|
||||
|
||||
$this->assertRegExp('/Connection settings/', $response->getOutput());
|
||||
$this->dispatchAction('extension/module/retailcrm/icml');
|
||||
$this->assertFileExists(DIR_SYSTEM . '../' . 'retailcrm.xml');
|
||||
}
|
||||
|
||||
public function testInstallCollector()
|
||||
{
|
||||
$this->login('admin', 'admin');
|
||||
|
||||
$response = $this->dispatchAction('extension/module/retailcrm/install_collector');
|
||||
|
||||
$this->assertRegExp('/Connection settings/', $response->getOutput());
|
||||
}
|
||||
|
||||
public function testUnnstallCollector()
|
||||
{
|
||||
$this->login('admin', 'admin');
|
||||
|
||||
$response = $this->dispatchAction('extension/module/retailcrm/uninstall_collector');
|
||||
|
||||
$this->assertRegExp('/Connection settings/', $response->getOutput());
|
||||
}
|
||||
}
|
||||
|
@ -1,187 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
class ModelRetailcrmOrderAdminTest extends OpenCartTest
|
||||
{
|
||||
private $orderModel;
|
||||
private $apiClientMock;
|
||||
private $settingModel;
|
||||
private $retailcrm;
|
||||
|
||||
const CUSTOMER_ID = 1;
|
||||
const ORDER_WITH_CUST_ID = 1;
|
||||
const ORDER_ID = 2;
|
||||
|
||||
public function setUp()
|
||||
public function testOrderModel()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->orderModel = $this->loadModel('extension/retailcrm/order');
|
||||
|
||||
$this->apiClientMock = $this->getMockBuilder(\RetailcrmProxy::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array(
|
||||
'ordersUpload',
|
||||
'customersList',
|
||||
'ordersCreate',
|
||||
'ordersPaymentCreate',
|
||||
'customersCreate'
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$this->settingModel = $this->loadModel('setting/setting');
|
||||
$this->retailcrm = new \retailcrm\Retailcrm(self::$registry);
|
||||
|
||||
$this->settingModel->editSetting(
|
||||
$this->retailcrm->getModuleTitle(),
|
||||
array(
|
||||
$this->retailcrm->getModuleTitle() . '_apiversion' => 'v5',
|
||||
$this->retailcrm->getModuleTitle() . '_order_number' => 1,
|
||||
$this->retailcrm->getModuleTitle() . '_status' => array(
|
||||
1 => 'new'
|
||||
),
|
||||
$this->retailcrm->getModuleTitle() . '_delivery' => array(
|
||||
'flat.flat' => 'flat'
|
||||
),
|
||||
$this->retailcrm->getModuleTitle() . '_payment' => array(
|
||||
'cod' => 'cod'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testUploadToCrm()
|
||||
{
|
||||
$saleOrderModel = $this->loadModel('sale/order');
|
||||
$orders = $saleOrderModel->getOrders();
|
||||
$fullOrders = array();
|
||||
|
||||
foreach ($orders as $order) {
|
||||
$fullOrder = $saleOrderModel->getOrder($order['order_id']);
|
||||
|
||||
$fullOrder['order_total'] = $saleOrderModel->getOrderTotals($order['order_id']);
|
||||
$fullOrder['products'] = $saleOrderModel->getOrderProducts($order['order_id']);
|
||||
|
||||
foreach($fullOrder['products'] as $key => $product) {
|
||||
$fullOrder['products'][$key]['option'] = $saleOrderModel->getOrderOptions($product['order_id'], $product['order_product_id']);
|
||||
}
|
||||
|
||||
$fullOrders[] = $fullOrder;
|
||||
}
|
||||
|
||||
$chunkedOrders = $this->orderModel->uploadToCrm($fullOrders, $this->apiClientMock);
|
||||
|
||||
$order = $chunkedOrders[0][0];
|
||||
|
||||
$this->assertInternalType('array', $chunkedOrders);
|
||||
$this->assertInternalType('array', $chunkedOrders[0]);
|
||||
$this->assertNotEmpty($chunkedOrders[0]);
|
||||
$this->assertArrayHasKey('externalId', $order);
|
||||
$this->assertArrayHasKey('number', $order);
|
||||
$this->assertArrayHasKey('firstName', $order);
|
||||
$this->assertArrayHasKey('lastName', $order);
|
||||
$this->assertArrayHasKey('email', $order);
|
||||
$this->assertArrayHasKey('phone', $order);
|
||||
$this->assertArrayHasKey('createdAt', $order);
|
||||
$this->assertArrayHasKey('delivery', $order);
|
||||
$this->assertArrayHasKey('status', $order);
|
||||
$this->assertArrayHasKey('items', $order);
|
||||
$this->assertArrayHasKey('payments', $order);
|
||||
$this->assertNotEmpty($order['payments']);
|
||||
}
|
||||
|
||||
public function testUploadWithCustomerTest()
|
||||
{
|
||||
$saleOrderModel = $this->loadModel('sale/order');
|
||||
$order = $saleOrderModel->getOrder(self::ORDER_WITH_CUST_ID);
|
||||
|
||||
$order['totals'] = $saleOrderModel->getOrderTotals($order['order_id']);
|
||||
$order['products'] = $saleOrderModel->getOrderProducts($order['order_id']);
|
||||
|
||||
foreach($order['products'] as $key => $product) {
|
||||
$order['products'][$key]['option'] = $saleOrderModel->getOrderOptions($product['order_id'], $product['order_product_id']);
|
||||
}
|
||||
|
||||
$response = new \RetailcrmApiResponse(
|
||||
201,
|
||||
json_encode(
|
||||
array(
|
||||
'success' => true,
|
||||
'id' => 1
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->apiClientMock->expects($this->any())->method('ordersCreate')->willReturn($response);
|
||||
$orderSend = $this->orderModel->uploadOrder($order, $this->apiClientMock);
|
||||
|
||||
$this->assertArrayHasKey('status', $orderSend);
|
||||
$this->assertEquals('new', $orderSend['status']);
|
||||
$this->assertArrayHasKey('externalId', $orderSend);
|
||||
$this->assertArrayHasKey('number', $orderSend);
|
||||
$this->assertArrayHasKey('firstName', $orderSend);
|
||||
$this->assertEquals('Test', $orderSend['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $orderSend);
|
||||
$this->assertEquals('Test', $orderSend['lastName']);
|
||||
$this->assertArrayHasKey('email', $orderSend);
|
||||
$this->assertEquals('test@mail.ru', $orderSend['email']);
|
||||
$this->assertArrayHasKey('phone', $orderSend);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $orderSend['phone']);
|
||||
$this->assertArrayHasKey('createdAt', $orderSend);
|
||||
$this->assertArrayHasKey('delivery', $orderSend);
|
||||
$this->assertInternalType('array', $orderSend['delivery']);
|
||||
$this->assertEquals('flat', $orderSend['delivery']['code']);
|
||||
$this->assertEquals('Test', $orderSend['delivery']['address']['city']);
|
||||
$this->assertEquals('Rostov-na-Donu', $orderSend['delivery']['address']['region']);
|
||||
$this->assertEquals('111111', $orderSend['delivery']['address']['index']);
|
||||
$this->assertArrayHasKey('items', $orderSend);
|
||||
$this->assertArrayHasKey('customerComment', $orderSend);
|
||||
$this->assertArrayHasKey('customer', $orderSend);
|
||||
$this->assertArrayHasKey('externalId', $orderSend['customer']);
|
||||
$this->assertEquals(self::CUSTOMER_ID, $orderSend['customer']['externalId']);
|
||||
$this->assertArrayHasKey('payments', $orderSend);
|
||||
$this->assertEquals('cod', $orderSend['payments'][0]['type']);
|
||||
$this->assertNotEmpty($orderSend['payments']);
|
||||
}
|
||||
|
||||
public function testUploadWithoutCustomerTest()
|
||||
{
|
||||
$saleOrderModel = $this->loadModel('sale/order');
|
||||
$order = $saleOrderModel->getOrder(self::ORDER_ID);
|
||||
|
||||
$order['totals'] = $saleOrderModel->getOrderTotals($order['order_id']);
|
||||
$order['products'] = $saleOrderModel->getOrderProducts($order['order_id']);
|
||||
|
||||
foreach($order['products'] as $key => $product) {
|
||||
$order['products'][$key]['option'] = $saleOrderModel->getOrderOptions($product['order_id'], $product['order_product_id']);
|
||||
}
|
||||
|
||||
$response = new \RetailcrmApiResponse(
|
||||
201,
|
||||
json_encode(
|
||||
array(
|
||||
'success' => true,
|
||||
'id' => 1
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->apiClientMock->expects($this->any())->method('ordersCreate')->willReturn($response);
|
||||
$orderSend = $this->orderModel->uploadOrder($order, $this->apiClientMock);
|
||||
|
||||
$this->assertArrayHasKey('status', $orderSend);
|
||||
$this->assertArrayHasKey('externalId', $orderSend);
|
||||
$this->assertArrayHasKey('number', $orderSend);
|
||||
$this->assertArrayHasKey('firstName', $orderSend);
|
||||
$this->assertArrayHasKey('lastName', $orderSend);
|
||||
$this->assertArrayHasKey('email', $orderSend);
|
||||
$this->assertArrayHasKey('phone', $orderSend);
|
||||
$this->assertArrayHasKey('createdAt', $orderSend);
|
||||
$this->assertArrayHasKey('delivery', $orderSend);
|
||||
$this->assertArrayHasKey('items', $orderSend);
|
||||
$this->assertContains('#', $orderSend['items'][0]['offer']['externalId']);
|
||||
$this->assertArrayHasKey('payments', $orderSend);
|
||||
$this->assertArrayHasKey('customerComment', $orderSend);
|
||||
$this->assertArrayNotHasKey('customer', $orderSend);
|
||||
$this->assertNotEmpty($orderSend['payments']);
|
||||
$this->assertTrue(true);
|
||||
// todo test
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
class ModelRetailcrmPricesAdminTest extends OpenCartTest
|
||||
{
|
||||
private $pricesModel;
|
||||
@ -22,22 +24,25 @@ class ModelRetailcrmPricesAdminTest extends OpenCartTest
|
||||
->getMock();
|
||||
|
||||
$this->settingModel = $this->loadModel('setting/setting');
|
||||
$this->retailcrm = new \retailcrm\Retailcrm(self::$registry);
|
||||
$this->retailcrm = new \Retailcrm\Retailcrm(self::$registry);
|
||||
|
||||
$this->settingModel->editSetting(
|
||||
$this->retailcrm->getModuleTitle(),
|
||||
\Retailcrm\Retailcrm::MODULE,
|
||||
array(
|
||||
$this->retailcrm->getModuleTitle() . '_apiversion' => 'v5',
|
||||
$this->retailcrm->getModuleTitle() . '_special' => 'special'
|
||||
\Retailcrm\Retailcrm::MODULE . '_apiversion' => 'v5',
|
||||
\Retailcrm\Retailcrm::MODULE . '_special' => 'special'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testUploadPrices()
|
||||
{
|
||||
$response = new \RetailcrmApiResponse(200, json_encode($this->getSites()));
|
||||
$this->apiClientMock->expects($this->any())->method('sitesList')->willReturn($response);
|
||||
|
||||
$productModel = $this->loadModel('catalog/product');
|
||||
$products = $productModel->getProducts();
|
||||
$prices = $this->pricesModel->uploadPrices($products, $this->apiClientMock);
|
||||
$prices = $this->pricesModel->uploadPrices($products, $this->apiClientMock, $this->retailcrm);
|
||||
$price = $prices[0][0];
|
||||
|
||||
$this->assertInternalType('array', $prices);
|
||||
@ -45,7 +50,20 @@ class ModelRetailcrmPricesAdminTest extends OpenCartTest
|
||||
$this->assertInternalType('array', $price);
|
||||
$this->assertArrayHasKey('externalId', $price);
|
||||
$this->assertArrayHasKey('site', $price);
|
||||
$this->assertEquals('test_site', $price['site']);
|
||||
$this->assertArrayHasKey('prices', $price);
|
||||
$this->assertInternalType('array', $price['prices']);
|
||||
}
|
||||
|
||||
private function getSites()
|
||||
{
|
||||
return array(
|
||||
'success' => true,
|
||||
'sites' => array(
|
||||
array(
|
||||
'code' => 'test_site'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
14
tests/admin/ModelRetailcrmProductsAdminTest.php
Normal file
14
tests/admin/ModelRetailcrmProductsAdminTest.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
class ModelRetailcrmProductsAdminTest extends OpenCartTest
|
||||
{
|
||||
public function testGetProductOptions()
|
||||
{
|
||||
$model = $this->loadModel('extension/retailcrm/products');
|
||||
$options = $model->getProductOptions(42);
|
||||
|
||||
$this->assertNotEmpty($options);
|
||||
}
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
class ControllerRetailcrmApiCatalogTest extends OpenCartTest
|
||||
{
|
||||
private $apiKey;
|
||||
private $retailcrm;
|
||||
private $username;
|
||||
|
||||
const ORDER_ID = 1;
|
||||
|
||||
@ -14,12 +17,13 @@ class ControllerRetailcrmApiCatalogTest extends OpenCartTest
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api` WHERE api_id = 1");
|
||||
$api = $query->row;
|
||||
$this->apiKey = $api['key'];
|
||||
$this->retailcrm = new \retailcrm\Retailcrm(self::$registry);
|
||||
$this->username = $api['username'];
|
||||
$this->retailcrm = new \Retailcrm\Retailcrm(self::$registry);
|
||||
|
||||
$this->setSetting(
|
||||
$this->retailcrm->getModuleTitle(),
|
||||
\Retailcrm\Retailcrm::MODULE,
|
||||
array(
|
||||
$this->retailcrm->getModuleTitle() . '_country' => array(1),
|
||||
\Retailcrm\Retailcrm::MODULE . '_country' => array(1),
|
||||
)
|
||||
);
|
||||
|
||||
@ -36,6 +40,8 @@ class ControllerRetailcrmApiCatalogTest extends OpenCartTest
|
||||
$this->assertEquals('Not found api key', $data->error);
|
||||
|
||||
$this->request->get['key'] = $this->apiKey;
|
||||
$this->request->get['username'] = $this->username;
|
||||
|
||||
$response = $this->dispatchAction('api/retailcrm/getDeliveryTypes');
|
||||
$data = json_decode($response->getOutput());
|
||||
|
||||
@ -50,6 +56,7 @@ class ControllerRetailcrmApiCatalogTest extends OpenCartTest
|
||||
$this->assertEquals('Not found api key', $data->error);
|
||||
|
||||
$this->request->get['key'] = $this->apiKey;
|
||||
$this->request->get['username'] = $this->username;
|
||||
$response = $this->dispatchAction('api/retailcrm/addOrderHistory');
|
||||
$data = json_decode($response->getOutput());
|
||||
|
||||
|
@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ModelRetailcrmCustomerCatalogTest extends OpenCartTest
|
||||
{
|
||||
private $customerModel;
|
||||
private $apiClientMock;
|
||||
|
||||
const CUSTOMER_ID = 1;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->customerModel = $this->loadModel('extension/retailcrm/customer');
|
||||
|
||||
$this->apiClientMock = $this->getMockBuilder(\RetailcrmProxy::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array(
|
||||
'customersCreate',
|
||||
'customersEdit'
|
||||
))
|
||||
->getMock();
|
||||
}
|
||||
|
||||
public function testSendToCrm()
|
||||
{
|
||||
$customerModel = $this->loadModel('account/customer');
|
||||
$customer = $customerModel->getCustomer(self::CUSTOMER_ID);
|
||||
|
||||
$customerSend = $this->customerModel->sendToCrm($customer, $this->apiClientMock);
|
||||
|
||||
$this->assertArrayHasKey('externalId', $customerSend);
|
||||
$this->assertEquals(self::CUSTOMER_ID, $customerSend['externalId']);
|
||||
$this->assertArrayHasKey('firstName', $customerSend);
|
||||
$this->assertEquals('Test', $customerSend['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $customerSend);
|
||||
$this->assertEquals('Test', $customerSend['lastName']);
|
||||
$this->assertArrayHasKey('email', $customerSend);
|
||||
$this->assertEquals('test@mail.ru', $customerSend['email']);
|
||||
$this->assertArrayHasKey('phones', $customerSend);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $customerSend['phones'][0]['number']);
|
||||
}
|
||||
|
||||
public function testChangeInCrm()
|
||||
{
|
||||
$customerModel = $this->loadModel('account/customer');
|
||||
$customer = $customerModel->getCustomer(self::CUSTOMER_ID);
|
||||
|
||||
$customerSend = $this->customerModel->changeInCrm($customer, $this->apiClientMock);
|
||||
|
||||
$this->assertArrayHasKey('externalId', $customerSend);
|
||||
$this->assertEquals(self::CUSTOMER_ID, $customerSend['externalId']);
|
||||
$this->assertArrayHasKey('firstName', $customerSend);
|
||||
$this->assertEquals('Test', $customerSend['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $customerSend);
|
||||
$this->assertEquals('Test', $customerSend['lastName']);
|
||||
$this->assertArrayHasKey('email', $customerSend);
|
||||
$this->assertEquals('test@mail.ru', $customerSend['email']);
|
||||
$this->assertArrayHasKey('phones', $customerSend);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $customerSend['phones'][0]['number']);
|
||||
}
|
||||
}
|
@ -1,192 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
class ModelRetailcrmOrderCatalogTest extends OpenCartTest
|
||||
{
|
||||
private $orderModel;
|
||||
private $apiClientMock;
|
||||
private $retailcrm;
|
||||
|
||||
const CUSTOMER_ID = 1;
|
||||
const ORDER_WITH_CUST_ID = 1;
|
||||
const ORDER_ID = 2;
|
||||
|
||||
public function setUp()
|
||||
public function testGetOrderStatus()
|
||||
{
|
||||
parent::setUp();
|
||||
$model = $this->loadModel('extension/retailcrm/order');
|
||||
$status_id = $model->getOrderStatusId(1);
|
||||
|
||||
$this->orderModel = $this->loadModel('extension/retailcrm/order');
|
||||
|
||||
$this->apiClientMock = $this->getMockBuilder(\RetailcrmProxy::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array(
|
||||
'ordersCreate',
|
||||
'ordersEdit',
|
||||
'ordersGet',
|
||||
'ordersPaymentEdit',
|
||||
'customersList'
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$this->retailcrm = new \retailcrm\Retailcrm(self::$registry);
|
||||
|
||||
$this->setSetting(
|
||||
$this->retailcrm->getModuleTitle(),
|
||||
array(
|
||||
$this->retailcrm->getModuleTitle() . '_apiversion' => 'v5',
|
||||
$this->retailcrm->getModuleTitle() . '_order_number' => 1,
|
||||
$this->retailcrm->getModuleTitle() . '_status' => array(
|
||||
1 => 'new'
|
||||
),
|
||||
$this->retailcrm->getModuleTitle() . '_delivery' => array(
|
||||
'flat.flat' => 'flat'
|
||||
),
|
||||
$this->retailcrm->getModuleTitle() . '_payment' => array(
|
||||
'cod' => 'cod'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateOrderWithCustomer()
|
||||
{
|
||||
$orderCheckoutModel = $this->loadModel('checkout/order');
|
||||
$orderAccountModel = $this->loadModel('account/order');
|
||||
$order_id = self::ORDER_WITH_CUST_ID;
|
||||
$order = $orderCheckoutModel->getOrder($order_id);
|
||||
$order['products'] = $orderAccountModel->getOrderProducts($order_id);
|
||||
$order['totals'] = $orderAccountModel->getOrderTotals($order_id);
|
||||
|
||||
foreach ($order['products'] as $key => $product) {
|
||||
$productOptions = $orderAccountModel->getOrderOptions($order_id, $product['order_product_id']);
|
||||
|
||||
if (!empty($productOptions)) {
|
||||
$order['products'][$key]['option'] = $productOptions;
|
||||
}
|
||||
}
|
||||
|
||||
$orderProcess = $this->orderModel->processOrder($order);
|
||||
$orderSend = $this->orderModel->sendToCrm($orderProcess, $this->apiClientMock);
|
||||
|
||||
$this->assertArrayHasKey('status', $orderSend);
|
||||
$this->assertEquals('new', $orderSend['status']);
|
||||
$this->assertArrayHasKey('externalId', $orderSend);
|
||||
$this->assertArrayHasKey('number', $orderSend);
|
||||
$this->assertArrayHasKey('firstName', $orderSend);
|
||||
$this->assertEquals('Test', $orderSend['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $orderSend);
|
||||
$this->assertEquals('Test', $orderSend['lastName']);
|
||||
$this->assertArrayHasKey('email', $orderSend);
|
||||
$this->assertEquals('test@mail.ru', $orderSend['email']);
|
||||
$this->assertArrayHasKey('phone', $orderSend);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $orderSend['phone']);
|
||||
$this->assertArrayHasKey('createdAt', $orderSend);
|
||||
$this->assertArrayHasKey('delivery', $orderSend);
|
||||
$this->assertInternalType('array', $orderSend['delivery']);
|
||||
$this->assertEquals('flat', $orderSend['delivery']['code']);
|
||||
$this->assertEquals('Test', $orderSend['delivery']['address']['city']);
|
||||
$this->assertEquals('Rostov-na-Donu', $orderSend['delivery']['address']['region']);
|
||||
$this->assertEquals('111111', $orderSend['delivery']['address']['index']);
|
||||
$this->assertArrayHasKey('items', $orderSend);
|
||||
$this->assertArrayHasKey('customerComment', $orderSend);
|
||||
$this->assertArrayHasKey('customer', $orderSend);
|
||||
$this->assertArrayHasKey('externalId', $orderSend['customer']);
|
||||
$this->assertEquals(self::CUSTOMER_ID, $orderSend['customer']['externalId']);
|
||||
$this->assertArrayHasKey('payments', $orderSend);
|
||||
$this->assertEquals('cod', $orderSend['payments'][0]['type']);
|
||||
$this->assertNotEmpty($orderSend['payments']);
|
||||
}
|
||||
|
||||
public function testEditOrderWithCustomer()
|
||||
{
|
||||
$orderCheckoutModel = $this->loadModel('checkout/order');
|
||||
$orderAccountModel = $this->loadModel('account/order');
|
||||
$order_id = self::ORDER_WITH_CUST_ID;
|
||||
$order = $orderCheckoutModel->getOrder($order_id);
|
||||
$order['products'] = $orderAccountModel->getOrderProducts($order_id);
|
||||
$order['totals'] = $orderAccountModel->getOrderTotals($order_id);
|
||||
|
||||
foreach ($order['products'] as $key => $product) {
|
||||
$productOptions = $orderAccountModel->getOrderOptions($order_id, $product['order_product_id']);
|
||||
|
||||
if (!empty($productOptions)) {
|
||||
$order['products'][$key]['option'] = $productOptions;
|
||||
}
|
||||
}
|
||||
|
||||
$orderEditResponse = new \RetailcrmApiResponse(
|
||||
200,
|
||||
json_encode(
|
||||
array(
|
||||
'success' => true,
|
||||
'id' => 1
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$ordersGetResponse = new \RetailcrmApiResponse(
|
||||
200,
|
||||
json_encode(
|
||||
array(
|
||||
'success' => true,
|
||||
'order' => $this->getOrder($order_id)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->apiClientMock->expects($this->any())->method('ordersEdit')->willReturn($orderEditResponse);
|
||||
$this->apiClientMock->expects($this->any())->method('ordersGet')->willReturn($ordersGetResponse);
|
||||
$orderProcess = $this->orderModel->processOrder($order);
|
||||
$orderSend = $this->orderModel->sendToCrm($orderProcess, $this->apiClientMock, false);
|
||||
|
||||
$this->assertArrayHasKey('status', $orderSend);
|
||||
$this->assertEquals('new', $orderSend['status']);
|
||||
$this->assertArrayHasKey('externalId', $orderSend);
|
||||
$this->assertArrayHasKey('number', $orderSend);
|
||||
$this->assertArrayHasKey('firstName', $orderSend);
|
||||
$this->assertEquals('Test', $orderSend['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $orderSend);
|
||||
$this->assertEquals('Test', $orderSend['lastName']);
|
||||
$this->assertArrayHasKey('email', $orderSend);
|
||||
$this->assertEquals('test@mail.ru', $orderSend['email']);
|
||||
$this->assertArrayHasKey('phone', $orderSend);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $orderSend['phone']);
|
||||
$this->assertArrayHasKey('createdAt', $orderSend);
|
||||
$this->assertArrayHasKey('delivery', $orderSend);
|
||||
$this->assertInternalType('array', $orderSend['delivery']);
|
||||
$this->assertEquals('flat', $orderSend['delivery']['code']);
|
||||
$this->assertEquals('Test', $orderSend['delivery']['address']['city']);
|
||||
$this->assertEquals('Rostov-na-Donu', $orderSend['delivery']['address']['region']);
|
||||
$this->assertEquals('111111', $orderSend['delivery']['address']['index']);
|
||||
$this->assertArrayHasKey('items', $orderSend);
|
||||
$this->assertArrayHasKey('customerComment', $orderSend);
|
||||
}
|
||||
|
||||
protected function setSetting($code, $data, $store_id = 0) {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if (substr($key, 0, strlen($code)) == $code) {
|
||||
if (!is_array($value)) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape($value) . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape(json_encode($value, true)) . "', serialized = '1'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getOrder($id)
|
||||
{
|
||||
return array(
|
||||
'payments' => array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'status' => 'not-paid',
|
||||
'type' => 'cod',
|
||||
'externalId' => $id,
|
||||
'amount' => '100'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertNotEmpty($status_id);
|
||||
$this->assertNotNull($status_id);
|
||||
}
|
||||
}
|
||||
|
14
tests/catalog/ModelRetailcrmProductsCatalogTest.php
Normal file
14
tests/catalog/ModelRetailcrmProductsCatalogTest.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
class ModelRetailcrmProductsCatalogTest extends OpenCartTest
|
||||
{
|
||||
public function testGetProductOptions()
|
||||
{
|
||||
$model = $this->loadModel('extension/retailcrm/products');
|
||||
$options = $model->getProductOptions(42);
|
||||
|
||||
$this->assertNotEmpty($options);
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
class ModelRetailcrmCustomerAdminTest extends OpenCartTest
|
||||
namespace Tests;
|
||||
|
||||
class CustomerRetailcrmLibraryTest extends OpenCartTest
|
||||
{
|
||||
private $customerModel;
|
||||
private $customer;
|
||||
private $apiClientMock;
|
||||
|
||||
const CUSTOMER_ID = 1;
|
||||
@ -11,39 +13,25 @@ class ModelRetailcrmCustomerAdminTest extends OpenCartTest
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->customerModel = $this->loadModel('extension/retailcrm/customer');
|
||||
|
||||
$this->apiClientMock = $this->getMockBuilder(\RetailcrmProxy::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array(
|
||||
'customersUpload',
|
||||
'customersCreate',
|
||||
'customersEdit'
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$retailcrm = new \Retailcrm\Retailcrm(self::$registry);
|
||||
$this->customer = $retailcrm->createObject(\Retailcrm\Customer::class);
|
||||
}
|
||||
|
||||
public function testUploadToCrm()
|
||||
public function testPrepareCustomer()
|
||||
{
|
||||
$customerModel = $this->loadModel('customer/customer');
|
||||
$customers = $customerModel->getCustomers();
|
||||
|
||||
$customersSend = $this->customerModel->uploadToCrm($customers, $this->apiClientMock);
|
||||
$customer = $customersSend[0][0];
|
||||
|
||||
$this->assertInternalType('array', $customersSend);
|
||||
$this->assertInternalType('array', $customersSend[0]);
|
||||
$this->assertArrayHasKey('externalId', $customer);
|
||||
$this->assertArrayHasKey('firstName', $customer);
|
||||
$this->assertArrayHasKey('lastName', $customer);
|
||||
$this->assertArrayHasKey('email', $customer);
|
||||
}
|
||||
|
||||
public function testChangeInCrm()
|
||||
{
|
||||
$customerModel = $this->loadModel('customer/customer');
|
||||
$customerModel = $this->loadModel('account/customer');
|
||||
$customer = $customerModel->getCustomer(self::CUSTOMER_ID);
|
||||
|
||||
$customerSend = $this->customerModel->changeInCrm($customer, $this->apiClientMock);
|
||||
$this->customer->prepare($customer);
|
||||
$customerSend = $this->customer->getData();
|
||||
|
||||
$this->assertArrayHasKey('externalId', $customerSend);
|
||||
$this->assertEquals(self::CUSTOMER_ID, $customerSend['externalId']);
|
||||
@ -56,4 +44,4 @@ class ModelRetailcrmCustomerAdminTest extends OpenCartTest
|
||||
$this->assertArrayHasKey('phones', $customerSend);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $customerSend['phones'][0]['number']);
|
||||
}
|
||||
}
|
||||
}
|
306
tests/library/OrderRetailcrmLibraryTest.php
Normal file
306
tests/library/OrderRetailcrmLibraryTest.php
Normal file
@ -0,0 +1,306 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
class OrderRetailcrmLibraryTest extends OpenCartTest
|
||||
{
|
||||
private $order;
|
||||
private $apiClientMock;
|
||||
private $retailcrm;
|
||||
|
||||
const CUSTOMER_ID = 1;
|
||||
const ORDER_WITH_CUST_ID = 1;
|
||||
const ORDER_ID = 2;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->apiClientMock = $this->getMockBuilder(\RetailcrmProxy::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array(
|
||||
'ordersCreate',
|
||||
'ordersEdit',
|
||||
'ordersGet',
|
||||
'ordersPaymentEdit',
|
||||
'customersList'
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$this->retailcrm = new \Retailcrm\Retailcrm(self::$registry);
|
||||
|
||||
$this->order = $this->retailcrm->createObject(\Retailcrm\Order::class);
|
||||
|
||||
$this->setSetting(
|
||||
\Retailcrm\Retailcrm::MODULE,
|
||||
array(
|
||||
\Retailcrm\Retailcrm::MODULE . '_apiversion' => 'v5',
|
||||
\Retailcrm\Retailcrm::MODULE . '_order_number' => 1,
|
||||
\Retailcrm\Retailcrm::MODULE . '_status' => array(
|
||||
1 => 'new'
|
||||
),
|
||||
\Retailcrm\Retailcrm::MODULE . '_delivery' => array(
|
||||
'flat.flat' => 'flat'
|
||||
),
|
||||
\Retailcrm\Retailcrm::MODULE . '_payment' => array(
|
||||
'cod' => 'cod'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testPrepareCreateOrderWithCustomer()
|
||||
{
|
||||
$orderCheckoutModel = $this->loadModel('checkout/order');
|
||||
$orderAccountModel = $this->loadModel('account/order');
|
||||
$order_id = self::ORDER_WITH_CUST_ID;
|
||||
$order = $orderCheckoutModel->getOrder($order_id);
|
||||
$order['products'] = $orderAccountModel->getOrderProducts($order_id);
|
||||
$order['totals'] = $orderAccountModel->getOrderTotals($order_id);
|
||||
|
||||
foreach ($order['products'] as $key => $product) {
|
||||
$productOptions = $orderAccountModel->getOrderOptions($order_id, $product['order_product_id']);
|
||||
|
||||
if (!empty($productOptions)) {
|
||||
$order['products'][$key]['option'] = $productOptions;
|
||||
}
|
||||
}
|
||||
|
||||
$this->order->prepare($order);
|
||||
$orderPrepare = $this->order->getData();
|
||||
|
||||
$this->assertArrayHasKey('status', $orderPrepare);
|
||||
$this->assertEquals('new', $orderPrepare['status']);
|
||||
$this->assertArrayHasKey('externalId', $orderPrepare);
|
||||
$this->assertArrayHasKey('number', $orderPrepare);
|
||||
$this->assertArrayHasKey('firstName', $orderPrepare);
|
||||
$this->assertEquals('Test', $orderPrepare['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $orderPrepare);
|
||||
$this->assertEquals('Test', $orderPrepare['lastName']);
|
||||
$this->assertArrayHasKey('email', $orderPrepare);
|
||||
$this->assertEquals('test@mail.ru', $orderPrepare['email']);
|
||||
$this->assertArrayHasKey('phone', $orderPrepare);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $orderPrepare['phone']);
|
||||
$this->assertArrayHasKey('createdAt', $orderPrepare);
|
||||
$this->assertArrayHasKey('delivery', $orderPrepare);
|
||||
$this->assertInternalType('array', $orderPrepare['delivery']);
|
||||
$this->assertEquals('flat', $orderPrepare['delivery']['code']);
|
||||
$this->assertEquals('Test', $orderPrepare['delivery']['address']['city']);
|
||||
$this->assertEquals('Rostov-na-Donu', $orderPrepare['delivery']['address']['region']);
|
||||
$this->assertEquals('111111', $orderPrepare['delivery']['address']['index']);
|
||||
$this->assertArrayHasKey('items', $orderPrepare);
|
||||
$this->assertArrayHasKey('customer', $orderPrepare);
|
||||
$this->assertArrayHasKey('externalId', $orderPrepare['customer']);
|
||||
$this->assertEquals(self::CUSTOMER_ID, $orderPrepare['customer']['externalId']);
|
||||
$this->assertArrayHasKey('payments', $orderPrepare);
|
||||
$this->assertEquals('cod', $orderPrepare['payments'][0]['type']);
|
||||
$this->assertNotEmpty($orderPrepare['payments']);
|
||||
}
|
||||
|
||||
public function testPrepareEditOrderWithCustomer()
|
||||
{
|
||||
$orderCheckoutModel = $this->loadModel('checkout/order');
|
||||
$orderAccountModel = $this->loadModel('account/order');
|
||||
$order_id = self::ORDER_WITH_CUST_ID;
|
||||
$order = $orderCheckoutModel->getOrder($order_id);
|
||||
$order['products'] = $orderAccountModel->getOrderProducts($order_id);
|
||||
$order['totals'] = $orderAccountModel->getOrderTotals($order_id);
|
||||
|
||||
foreach ($order['products'] as $key => $product) {
|
||||
$productOptions = $orderAccountModel->getOrderOptions($order_id, $product['order_product_id']);
|
||||
|
||||
if (!empty($productOptions)) {
|
||||
$order['products'][$key]['option'] = $productOptions;
|
||||
}
|
||||
}
|
||||
|
||||
$orderEditResponse = new \RetailcrmApiResponse(
|
||||
200,
|
||||
json_encode(
|
||||
array(
|
||||
'success' => true,
|
||||
'id' => 1
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$ordersGetResponse = new \RetailcrmApiResponse(
|
||||
200,
|
||||
json_encode(
|
||||
array(
|
||||
'success' => true,
|
||||
'order' => $this->getOrder($order_id)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->apiClientMock->expects($this->any())->method('ordersEdit')->willReturn($orderEditResponse);
|
||||
$this->apiClientMock->expects($this->any())->method('ordersGet')->willReturn($ordersGetResponse);
|
||||
$this->order->prepare($order);
|
||||
$orderPrepare = $this->order->getData();
|
||||
|
||||
$this->assertArrayHasKey('status', $orderPrepare);
|
||||
$this->assertEquals('new', $orderPrepare['status']);
|
||||
$this->assertArrayHasKey('externalId', $orderPrepare);
|
||||
$this->assertArrayHasKey('number', $orderPrepare);
|
||||
$this->assertArrayHasKey('firstName', $orderPrepare);
|
||||
$this->assertEquals('Test', $orderPrepare['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $orderPrepare);
|
||||
$this->assertEquals('Test', $orderPrepare['lastName']);
|
||||
$this->assertArrayHasKey('email', $orderPrepare);
|
||||
$this->assertEquals('test@mail.ru', $orderPrepare['email']);
|
||||
$this->assertArrayHasKey('phone', $orderPrepare);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $orderPrepare['phone']);
|
||||
$this->assertArrayHasKey('createdAt', $orderPrepare);
|
||||
$this->assertArrayHasKey('delivery', $orderPrepare);
|
||||
$this->assertInternalType('array', $orderPrepare['delivery']);
|
||||
$this->assertEquals('flat', $orderPrepare['delivery']['code']);
|
||||
$this->assertEquals('Test', $orderPrepare['delivery']['address']['city']);
|
||||
$this->assertEquals('Rostov-na-Donu', $orderPrepare['delivery']['address']['region']);
|
||||
$this->assertEquals('111111', $orderPrepare['delivery']['address']['index']);
|
||||
$this->assertArrayHasKey('items', $orderPrepare);
|
||||
$this->assertArrayHasKey('customer', $orderPrepare);
|
||||
$this->assertArrayHasKey('externalId', $orderPrepare['customer']);
|
||||
$this->assertEquals(self::CUSTOMER_ID, $orderPrepare['customer']['externalId']);
|
||||
}
|
||||
|
||||
public function testPrepareCreateOrderWithoutCustomer()
|
||||
{
|
||||
$orderCheckoutModel = $this->loadModel('checkout/order');
|
||||
$orderAccountModel = $this->loadModel('account/order');
|
||||
$order_id = self::ORDER_ID;
|
||||
$order = $orderCheckoutModel->getOrder($order_id);
|
||||
$order['products'] = $orderAccountModel->getOrderProducts($order_id);
|
||||
$order['totals'] = $orderAccountModel->getOrderTotals($order_id);
|
||||
|
||||
foreach ($order['products'] as $key => $product) {
|
||||
$productOptions = $orderAccountModel->getOrderOptions($order_id, $product['order_product_id']);
|
||||
|
||||
if (!empty($productOptions)) {
|
||||
$order['products'][$key]['option'] = $productOptions;
|
||||
}
|
||||
}
|
||||
|
||||
$this->order->prepare($order);
|
||||
$orderPrepare = $this->order->getData();
|
||||
|
||||
$this->assertArrayHasKey('status', $orderPrepare);
|
||||
$this->assertEquals('new', $orderPrepare['status']);
|
||||
$this->assertArrayHasKey('externalId', $orderPrepare);
|
||||
$this->assertArrayHasKey('number', $orderPrepare);
|
||||
$this->assertArrayHasKey('firstName', $orderPrepare);
|
||||
$this->assertEquals('Test', $orderPrepare['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $orderPrepare);
|
||||
$this->assertEquals('Test', $orderPrepare['lastName']);
|
||||
$this->assertArrayHasKey('email', $orderPrepare);
|
||||
$this->assertEquals('test@mail.ru', $orderPrepare['email']);
|
||||
$this->assertArrayHasKey('phone', $orderPrepare);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $orderPrepare['phone']);
|
||||
$this->assertArrayHasKey('createdAt', $orderPrepare);
|
||||
$this->assertArrayHasKey('delivery', $orderPrepare);
|
||||
$this->assertInternalType('array', $orderPrepare['delivery']);
|
||||
$this->assertEquals('flat', $orderPrepare['delivery']['code']);
|
||||
$this->assertEquals('Test', $orderPrepare['delivery']['address']['city']);
|
||||
$this->assertEquals('Rostov-na-Donu', $orderPrepare['delivery']['address']['region']);
|
||||
$this->assertEquals('111111', $orderPrepare['delivery']['address']['index']);
|
||||
$this->assertArrayHasKey('items', $orderPrepare);
|
||||
$this->assertArrayNotHasKey('customer', $orderPrepare);
|
||||
$this->assertArrayHasKey('payments', $orderPrepare);
|
||||
$this->assertEquals('cod', $orderPrepare['payments'][0]['type']);
|
||||
$this->assertNotEmpty($orderPrepare['payments']);
|
||||
}
|
||||
|
||||
public function testPrepareEditOrderWithoutCustomer()
|
||||
{
|
||||
$orderCheckoutModel = $this->loadModel('checkout/order');
|
||||
$orderAccountModel = $this->loadModel('account/order');
|
||||
$order_id = self::ORDER_ID;
|
||||
$order = $orderCheckoutModel->getOrder($order_id);
|
||||
$order['products'] = $orderAccountModel->getOrderProducts($order_id);
|
||||
$order['totals'] = $orderAccountModel->getOrderTotals($order_id);
|
||||
|
||||
foreach ($order['products'] as $key => $product) {
|
||||
$productOptions = $orderAccountModel->getOrderOptions($order_id, $product['order_product_id']);
|
||||
|
||||
if (!empty($productOptions)) {
|
||||
$order['products'][$key]['option'] = $productOptions;
|
||||
}
|
||||
}
|
||||
|
||||
$orderEditResponse = new \RetailcrmApiResponse(
|
||||
200,
|
||||
json_encode(
|
||||
array(
|
||||
'success' => true,
|
||||
'id' => 1
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$ordersGetResponse = new \RetailcrmApiResponse(
|
||||
200,
|
||||
json_encode(
|
||||
array(
|
||||
'success' => true,
|
||||
'order' => $this->getOrder($order_id)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->apiClientMock->expects($this->any())->method('ordersEdit')->willReturn($orderEditResponse);
|
||||
$this->apiClientMock->expects($this->any())->method('ordersGet')->willReturn($ordersGetResponse);
|
||||
$this->order->prepare($order);
|
||||
$orderPrepare = $this->order->getData();
|
||||
|
||||
$this->assertArrayHasKey('status', $orderPrepare);
|
||||
$this->assertEquals('new', $orderPrepare['status']);
|
||||
$this->assertArrayHasKey('externalId', $orderPrepare);
|
||||
$this->assertArrayHasKey('number', $orderPrepare);
|
||||
$this->assertArrayHasKey('firstName', $orderPrepare);
|
||||
$this->assertEquals('Test', $orderPrepare['firstName']);
|
||||
$this->assertArrayHasKey('lastName', $orderPrepare);
|
||||
$this->assertEquals('Test', $orderPrepare['lastName']);
|
||||
$this->assertArrayHasKey('email', $orderPrepare);
|
||||
$this->assertEquals('test@mail.ru', $orderPrepare['email']);
|
||||
$this->assertArrayHasKey('phone', $orderPrepare);
|
||||
$this->assertEquals('+7 (000) 000-00-00', $orderPrepare['phone']);
|
||||
$this->assertArrayHasKey('createdAt', $orderPrepare);
|
||||
$this->assertArrayHasKey('delivery', $orderPrepare);
|
||||
$this->assertInternalType('array', $orderPrepare['delivery']);
|
||||
$this->assertEquals('flat', $orderPrepare['delivery']['code']);
|
||||
$this->assertEquals('Test', $orderPrepare['delivery']['address']['city']);
|
||||
$this->assertEquals('Rostov-na-Donu', $orderPrepare['delivery']['address']['region']);
|
||||
$this->assertEquals('111111', $orderPrepare['delivery']['address']['index']);
|
||||
$this->assertArrayHasKey('items', $orderPrepare);
|
||||
$this->assertArrayNotHasKey('customer', $orderPrepare);
|
||||
}
|
||||
|
||||
protected function setSetting($code, $data, $store_id = 0) {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if (substr($key, 0, strlen($code)) == $code) {
|
||||
if (!is_array($value)) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape($value) . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape(json_encode($value, true)) . "', serialized = '1'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getOrder($id)
|
||||
{
|
||||
return array(
|
||||
'payments' => array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'status' => 'not-paid',
|
||||
'type' => 'cod',
|
||||
'externalId' => $id,
|
||||
'amount' => '100'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
TRUNCATE TABLE `oc_customer`;
|
||||
INSERT INTO `oc_customer` (`customer_id`, `customer_group_id`, `store_id`, `language_id`, `firstname`, `lastname`, `email`, `telephone`, `fax`, `password`, `salt`, `cart`, `wishlist`, `newsletter`, `address_id`, `custom_field`, `ip`, `status`, `approved`, `safe`, `token`, `code`, `date_added`) VALUES ('1', '1', '0', '1', 'Test', 'Test', 'test@mail.ru', '+7 (000) 000-00-00', '', 'ed3798da75d6cdd695e99e87a60d587a10aa95ff', '51TalnrgH', '', '', '0', '1', '', '172.21.0.1', '1', '1', '0', '', '', '2018-06-07 13:50:08');
|
||||
INSERT INTO `oc_customer` (`customer_id`, `customer_group_id`, `store_id`, `language_id`, `firstname`, `lastname`, `email`, `telephone`, `fax`, `password`, `salt`, `cart`, `wishlist`, `newsletter`, `address_id`, `custom_field`, `ip`, `status`, `safe`, `token`, `code`, `date_added`) VALUES ('1', '1', '0', '1', 'Test', 'Test', 'test@mail.ru', '+7 (000) 000-00-00', '', 'ed3798da75d6cdd695e99e87a60d587a10aa95ff', '51TalnrgH', '', '', '0', '1', '', '172.21.0.1', '1', '0', '', '', '2018-06-07 13:50:08');
|
||||
|
||||
TRUNCATE TABLE `oc_customer_activity`;
|
||||
TRUNCATE TABLE `oc_customer_group`;
|
||||
@ -23,7 +23,6 @@ TRUNCATE TABLE `oc_order`;
|
||||
INSERT INTO `oc_order` (`order_id`, `invoice_no`, `invoice_prefix`, `store_id`, `store_name`, `store_url`, `customer_id`, `customer_group_id`, `firstname`, `lastname`, `email`, `telephone`, `fax`, `custom_field`, `payment_firstname`, `payment_lastname`, `payment_company`, `payment_address_1`, `payment_address_2`, `payment_city`, `payment_postcode`, `payment_country`, `payment_country_id`, `payment_zone`, `payment_zone_id`, `payment_address_format`, `payment_custom_field`, `payment_method`, `payment_code`, `shipping_firstname`, `shipping_lastname`, `shipping_company`, `shipping_address_1`, `shipping_address_2`, `shipping_city`, `shipping_postcode`, `shipping_country`, `shipping_country_id`, `shipping_zone`, `shipping_zone_id`, `shipping_address_format`, `shipping_custom_field`, `shipping_method`, `shipping_code`, `comment`, `total`, `order_status_id`, `affiliate_id`, `commission`, `marketing_id`, `tracking`, `language_id`, `currency_id`, `currency_code`, `currency_value`, `ip`, `forwarded_ip`, `user_agent`, `accept_language`, `date_added`, `date_modified`) VALUES ('1', '0', 'INV-2016-00', '0', 'Opencart', 'http://localhost:8000/', '1', '1', 'Test', 'Test', 'test@mail.ru', '+7 (000) 000-00-00', '', '', 'Test', 'Test', '', 'Address', 'Address 2', 'Test', '111111', 'Russian Federation', '176', 'Rostov-na-Donu', '99', '', '[]', 'Cash on delivery', 'cod', 'Test', 'Test', '', 'Address', 'Address 2', 'Test', '111111', 'Russian Federation', '176', 'Rostov-na-Donu', '99', '', '[]', 'Flat Rate', 'flat.flat', '', '106.0000', '1', '0', '0.0000', '0', '', '1', '1', 'USD', '1.00000000', '172.21.0.1', '', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36', 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7', '2018-06-07 13:51:10', '2018-06-07 13:51:23');
|
||||
INSERT INTO `oc_order` (`order_id`, `invoice_no`, `invoice_prefix`, `store_id`, `store_name`, `store_url`, `customer_id`, `customer_group_id`, `firstname`, `lastname`, `email`, `telephone`, `fax`, `custom_field`, `payment_firstname`, `payment_lastname`, `payment_company`, `payment_address_1`, `payment_address_2`, `payment_city`, `payment_postcode`, `payment_country`, `payment_country_id`, `payment_zone`, `payment_zone_id`, `payment_address_format`, `payment_custom_field`, `payment_method`, `payment_code`, `shipping_firstname`, `shipping_lastname`, `shipping_company`, `shipping_address_1`, `shipping_address_2`, `shipping_city`, `shipping_postcode`, `shipping_country`, `shipping_country_id`, `shipping_zone`, `shipping_zone_id`, `shipping_address_format`, `shipping_custom_field`, `shipping_method`, `shipping_code`, `comment`, `total`, `order_status_id`, `affiliate_id`, `commission`, `marketing_id`, `tracking`, `language_id`, `currency_id`, `currency_code`, `currency_value`, `ip`, `forwarded_ip`, `user_agent`, `accept_language`, `date_added`, `date_modified`) VALUES ('2', '0', 'INV-2016-00', '0', 'Opencart', 'http://localhost:8000/', '0', '1', 'Test', 'Test', 'test@mail.ru', '+7 (000) 000-00-00', '', '[]', 'Test', 'Test', '', 'Address', 'Address 2', 'Test', '111111', 'Russian Federation', '176', 'Rostov-na-Donu', '99', '', '[]', 'Cash on delivery', 'cod', 'Test', 'Test', '', 'Address', 'Address 2', 'Test', '111111', 'Russian Federation', '176', 'Rostov-na-Donu', '99', '', '[]', 'Flat Rate', 'flat.flat', '', '85.0000', '1', '0', '0.0000', '0', '', '1', '1', 'USD', '1.00000000', '172.21.0.1', '', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36', 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7', '2018-06-07 13:53:50', '2018-06-07 13:54:00');
|
||||
|
||||
TRUNCATE TABLE `oc_order_custom_field`;
|
||||
TRUNCATE TABLE `oc_order_history`;
|
||||
INSERT INTO `oc_order_history` (`order_history_id`, `order_id`, `order_status_id`, `notify`, `comment`, `date_added`) VALUES ('19', '2', '1', '0', '', '2018-06-07 13:54:00');
|
||||
INSERT INTO `oc_order_history` (`order_history_id`, `order_id`, `order_status_id`, `notify`, `comment`, `date_added`) VALUES ('18', '1', '1', '0', '', '2018-06-07 13:51:23');
|
||||
|
70
tests/test-config.php
Normal file
70
tests/test-config.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
define('VERSION', '3.1.0.0_a1');
|
||||
|
||||
// Site
|
||||
$_['site_url'] = getenv('HTTP_SERVER');
|
||||
$_['site_ssl'] = false;
|
||||
|
||||
// Database
|
||||
$_['db_autostart'] = true;
|
||||
$_['db_type'] = DB_DRIVER; // mpdo, mssql, mysql, mysqli or postgre
|
||||
$_['db_hostname'] = DB_HOSTNAME;
|
||||
$_['db_username'] = DB_USERNAME;
|
||||
$_['db_password'] = DB_PASSWORD;
|
||||
$_['db_database'] = DB_DATABASE;
|
||||
$_['db_port'] = DB_PORT;
|
||||
|
||||
// Action Events
|
||||
$_['action_event'] = array(
|
||||
'controller/*/before' => array(
|
||||
'event/language/before'
|
||||
),
|
||||
'controller/*/after' => array(
|
||||
'event/language/after'
|
||||
),
|
||||
'view/*/before' => array(
|
||||
500 => 'event/theme/override',
|
||||
998 => 'event/language',
|
||||
1000 => 'event/theme'
|
||||
),
|
||||
'language/*/after' => array(
|
||||
'event/translation'
|
||||
),
|
||||
//'view/*/before' => array(
|
||||
// 1000 => 'event/debug/before'
|
||||
//),
|
||||
'controller/*/after' => array(
|
||||
'event/debug/after'
|
||||
)
|
||||
);
|
||||
|
||||
if (defined('HTTP_CATALOG')) { // is defined iff in catalog
|
||||
|
||||
// Actions
|
||||
$_['action_pre_action'] = array(
|
||||
'startup/startup',
|
||||
'startup/error',
|
||||
'startup/event',
|
||||
'startup/sass',
|
||||
'startup/login',
|
||||
'startup/permission'
|
||||
);
|
||||
} else { // admin
|
||||
// Actions
|
||||
$_['action_pre_action'] = array(
|
||||
'startup/startup',
|
||||
'startup/error',
|
||||
'startup/event',
|
||||
'startup/maintenance',
|
||||
'startup/seo_url'
|
||||
);
|
||||
}
|
||||
|
||||
// Test Settings
|
||||
$_['session_engine'] = 'test';
|
||||
$_['session_autostart'] = false;
|
||||
|
||||
$_['template_engine'] = 'twig';
|
||||
$_['template_directory'] = '';
|
||||
$_['template_cache'] = false;
|
Loading…
Reference in New Issue
Block a user