2017-03-22 11:52:11 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php';
|
|
|
|
|
|
|
|
class ModelExtensionRetailcrmReferences extends Model
|
|
|
|
{
|
|
|
|
protected $retailcrm;
|
2017-03-27 16:09:27 +03:00
|
|
|
private $opencartApiClient;
|
|
|
|
|
|
|
|
public function getOpercartDeliveryTypes()
|
|
|
|
{
|
|
|
|
$this->load->model('user/api');
|
|
|
|
$this->opencartApiClient = new OpencartApiClient($this->registry);
|
|
|
|
|
|
|
|
return $this->opencartApiClient->request('retailcrm/getDeliveryTypes', array(), array());
|
|
|
|
}
|
2017-03-22 11:52:11 +03:00
|
|
|
|
|
|
|
public function getDeliveryTypes()
|
|
|
|
{
|
2017-03-27 16:09:27 +03:00
|
|
|
$this->load->model('setting/store');
|
2017-09-21 10:09:26 +03:00
|
|
|
|
2017-03-22 11:52:11 +03:00
|
|
|
return array(
|
|
|
|
'opencart' => $this->getOpercartDeliveryTypes(),
|
|
|
|
'retailcrm' => $this->getApiDeliveryTypes()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOrderStatuses()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'opencart' => $this->getOpercartOrderStatuses(),
|
|
|
|
'retailcrm' => $this->getApiOrderStatuses()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPaymentTypes()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'opencart' => $this->getOpercartPaymentTypes(),
|
|
|
|
'retailcrm' => $this->getApiPaymentTypes()
|
|
|
|
);
|
|
|
|
}
|
2017-09-21 10:09:26 +03:00
|
|
|
|
2017-09-15 15:47:38 +03:00
|
|
|
public function getCustomFields()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'opencart' => $this->getOpencartCustomFields(),
|
2017-09-21 10:09:26 +03:00
|
|
|
'retailcrm' => $this->getApiCustomFields()
|
2017-09-15 15:47:38 +03:00
|
|
|
);
|
|
|
|
}
|
2017-09-21 10:09:26 +03:00
|
|
|
|
2017-03-22 11:52:11 +03:00
|
|
|
public function getOpercartOrderStatuses()
|
|
|
|
{
|
|
|
|
$this->load->model('localisation/order_status');
|
|
|
|
|
|
|
|
return $this->model_localisation_order_status
|
|
|
|
->getOrderStatuses(array());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOpercartPaymentTypes()
|
|
|
|
{
|
|
|
|
$paymentTypes = array();
|
|
|
|
$files = glob(DIR_APPLICATION . 'controller/extension/payment/*.php');
|
|
|
|
|
|
|
|
if ($files) {
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$extension = basename($file, '.php');
|
|
|
|
|
|
|
|
$this->load->language('extension/payment/' . $extension);
|
2017-07-11 17:39:48 +03:00
|
|
|
|
|
|
|
if (version_compare(VERSION, '3.0', '<')) {
|
|
|
|
$configStatus = $extension . '_status';
|
|
|
|
} else {
|
|
|
|
$configStatus = 'payment_' . $extension . '_status';
|
|
|
|
}
|
2017-03-22 11:52:11 +03:00
|
|
|
|
2017-07-11 17:39:48 +03:00
|
|
|
if ($this->config->get($configStatus)) {
|
2017-03-22 11:52:11 +03:00
|
|
|
$paymentTypes[$extension] = strip_tags(
|
|
|
|
$this->language->get('heading_title')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $paymentTypes;
|
|
|
|
}
|
2017-09-15 15:47:38 +03:00
|
|
|
|
|
|
|
public function getOpencartCustomFields()
|
|
|
|
{
|
|
|
|
$this->load->model('customer/custom_field');
|
|
|
|
|
|
|
|
return $this->model_customer_custom_field->getCustomFields();
|
|
|
|
}
|
|
|
|
|
2017-03-22 11:52:11 +03:00
|
|
|
public function getApiDeliveryTypes()
|
2017-07-11 17:39:48 +03:00
|
|
|
{
|
|
|
|
$this->initApi();
|
|
|
|
|
|
|
|
$response = $this->retailcrm->deliveryTypesList();
|
2017-03-22 11:52:11 +03:00
|
|
|
|
2017-08-29 17:18:04 +03:00
|
|
|
return (!$response->isSuccessful()) ? array() : $response->deliveryTypes;
|
2017-03-22 11:52:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getApiOrderStatuses()
|
|
|
|
{
|
2017-07-11 17:39:48 +03:00
|
|
|
$this->initApi();
|
2017-03-22 11:52:11 +03:00
|
|
|
|
2017-07-11 17:39:48 +03:00
|
|
|
$response = $this->retailcrm->statusesList();
|
2017-03-22 11:52:11 +03:00
|
|
|
|
2017-08-29 17:18:04 +03:00
|
|
|
return (!$response->isSuccessful()) ? array() : $response->statuses;
|
2017-03-22 11:52:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getApiPaymentTypes()
|
2017-07-11 17:39:48 +03:00
|
|
|
{
|
|
|
|
$this->initApi();
|
|
|
|
|
|
|
|
$response = $this->retailcrm->paymentTypesList();
|
|
|
|
|
2017-08-29 17:18:04 +03:00
|
|
|
return (!$response->isSuccessful()) ? array() : $response->paymentTypes;
|
2017-07-11 17:39:48 +03:00
|
|
|
}
|
2017-09-15 15:47:38 +03:00
|
|
|
|
2017-09-21 10:09:26 +03:00
|
|
|
public function getApiCustomFields()
|
2017-09-15 15:47:38 +03:00
|
|
|
{
|
|
|
|
$this->initApi();
|
2017-09-21 10:09:26 +03:00
|
|
|
|
|
|
|
$customers = $this->retailcrm->customFieldsList(array('entity' => 'customer'));
|
|
|
|
$orders = $this->retailcrm->customFieldsList(array('entity' => 'order'));
|
|
|
|
|
|
|
|
$customFieldsCustomers = (!$customers->isSuccessful()) ? array() : $customers->customFields;
|
|
|
|
$customFieldsOrders = (!$orders->isSuccessful()) ? array() : $orders->customFields;
|
|
|
|
|
|
|
|
if (!$customFieldsCustomers && !$customFieldsOrders) {
|
|
|
|
return array();
|
|
|
|
}
|
2017-09-15 15:47:38 +03:00
|
|
|
|
2017-09-21 10:09:26 +03:00
|
|
|
return array('customers' => $customFieldsCustomers, 'orders' => $customFieldsOrders);
|
2017-09-15 15:47:38 +03:00
|
|
|
}
|
2017-07-11 17:39:48 +03:00
|
|
|
|
|
|
|
protected function initApi()
|
2017-03-22 11:52:11 +03:00
|
|
|
{
|
2017-07-11 17:39:48 +03:00
|
|
|
$moduleTitle = $this->getModuleTitle();
|
2017-03-22 11:52:11 +03:00
|
|
|
$this->load->model('setting/setting');
|
2017-07-11 17:39:48 +03:00
|
|
|
$settings = $this->model_setting_setting->getSetting($moduleTitle);
|
2017-03-22 11:52:11 +03:00
|
|
|
|
2017-07-11 17:39:48 +03:00
|
|
|
if(!empty($settings[$moduleTitle . '_url']) && !empty($settings[$moduleTitle . '_apikey'])) {
|
2017-03-22 11:52:11 +03:00
|
|
|
$this->retailcrm = new RetailcrmProxy(
|
2017-07-11 17:39:48 +03:00
|
|
|
$settings[$moduleTitle . '_url'],
|
|
|
|
$settings[$moduleTitle . '_apikey'],
|
|
|
|
DIR_SYSTEM . 'storage/logs/retailcrm.log',
|
|
|
|
$settings[$moduleTitle . '_apiversion']
|
2017-03-22 11:52:11 +03:00
|
|
|
);
|
2017-07-11 17:39:48 +03:00
|
|
|
}
|
|
|
|
}
|
2017-03-22 11:52:11 +03:00
|
|
|
|
2017-07-11 17:39:48 +03:00
|
|
|
private function getModuleTitle()
|
|
|
|
{
|
|
|
|
if (version_compare(VERSION, '3.0', '<')) {
|
|
|
|
$title = 'retailcrm';
|
|
|
|
} else {
|
|
|
|
$title = 'module_retailcrm';
|
2017-03-22 11:52:11 +03:00
|
|
|
}
|
2017-07-11 17:39:48 +03:00
|
|
|
|
|
|
|
return $title;
|
2017-03-22 11:52:11 +03:00
|
|
|
}
|
|
|
|
}
|