2015-06-26 18:07:36 +03:00
|
|
|
<?php
|
|
|
|
|
2015-07-23 18:21:04 +03:00
|
|
|
require_once DIR_SYSTEM . 'library/retailcrm.php';
|
|
|
|
|
2015-07-23 00:27:20 +03:00
|
|
|
class ModelRetailcrmReferences extends Model
|
|
|
|
{
|
2015-07-23 18:21:04 +03:00
|
|
|
protected $retailcrm;
|
2015-06-26 18:07:36 +03:00
|
|
|
|
2015-07-23 13:14:23 +03:00
|
|
|
public function getDeliveryTypes()
|
|
|
|
{
|
|
|
|
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()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getOpercartDeliveryTypes()
|
2015-06-26 18:07:36 +03:00
|
|
|
{
|
|
|
|
$deliveryMethods = array();
|
|
|
|
$files = glob(DIR_APPLICATION . 'controller/shipping/*.php');
|
|
|
|
|
|
|
|
if ($files) {
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$extension = basename($file, '.php');
|
|
|
|
|
|
|
|
$this->load->language('shipping/' . $extension);
|
|
|
|
|
|
|
|
if ($this->config->get($extension . '_status')) {
|
|
|
|
$deliveryMethods[$extension.'.'.$extension] = strip_tags(
|
|
|
|
$this->language->get('heading_title')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $deliveryMethods;
|
|
|
|
}
|
|
|
|
|
2015-07-23 13:14:23 +03:00
|
|
|
protected function getOpercartOrderStatuses()
|
2015-06-26 18:07:36 +03:00
|
|
|
{
|
|
|
|
$this->load->model('localisation/order_status');
|
|
|
|
|
|
|
|
return $this->model_localisation_order_status
|
|
|
|
->getOrderStatuses(array());
|
|
|
|
}
|
|
|
|
|
2015-07-23 13:14:23 +03:00
|
|
|
protected function getOpercartPaymentTypes()
|
2015-06-26 18:07:36 +03:00
|
|
|
{
|
|
|
|
$paymentTypes = array();
|
|
|
|
$files = glob(DIR_APPLICATION . 'controller/payment/*.php');
|
|
|
|
|
|
|
|
if ($files) {
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$extension = basename($file, '.php');
|
|
|
|
|
|
|
|
$this->load->language('payment/' . $extension);
|
|
|
|
|
|
|
|
if ($this->config->get($extension . '_status')) {
|
|
|
|
$paymentTypes[$extension] = strip_tags(
|
|
|
|
$this->language->get('heading_title')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $paymentTypes;
|
|
|
|
}
|
2015-07-23 13:14:23 +03:00
|
|
|
|
|
|
|
protected function getApiDeliveryTypes()
|
|
|
|
{
|
2015-07-23 18:21:04 +03:00
|
|
|
$this->load->model('setting/setting');
|
|
|
|
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
|
|
|
|
|
|
|
if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) {
|
|
|
|
$this->retailcrm = new ApiHelper($settings);
|
|
|
|
|
|
|
|
try {
|
2015-07-27 18:07:33 +03:00
|
|
|
$response = $this->retailcrm->api->deliveryTypesList();
|
|
|
|
if ($response->isSuccessful() && $response->getStatusCode() == 200) {
|
|
|
|
return $response->deliveryTypes;
|
|
|
|
} else {
|
|
|
|
$this->log->write(
|
|
|
|
sprintf(
|
|
|
|
"RestApi::deliveryTypesList::Errors: [HTTP-status %s] %s",
|
|
|
|
$response->getStatusCode(),
|
|
|
|
$response->getErrorMsg()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (isset($response['errors'])) {
|
|
|
|
foreach ($response['errors'] as $error) {
|
|
|
|
$this->log->write(
|
|
|
|
sprintf(
|
|
|
|
"RestApi::deliveryTypesList::Errors: %s", $error
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return array();
|
|
|
|
}
|
2015-07-23 18:21:04 +03:00
|
|
|
} catch (CurlException $e) {
|
|
|
|
$this->data['retailcrm_error'][] = $e->getMessage();
|
2015-07-27 18:07:33 +03:00
|
|
|
$this->log->write('RestApi::deliveryTypesList::Curl:' . $e->getMessage());
|
2015-07-23 18:21:04 +03:00
|
|
|
} catch (InvalidJsonException $e) {
|
|
|
|
$this->data['retailcrm_error'][] = $e->getMessage();
|
2015-07-27 18:07:33 +03:00
|
|
|
$this->log->write('RestApi::deliveryTypesList::JSON:' . $e->getMessage());
|
2015-07-23 18:21:04 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return array();
|
2015-07-23 13:14:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getApiOrderStatuses()
|
|
|
|
{
|
2015-07-23 18:21:04 +03:00
|
|
|
$this->load->model('setting/setting');
|
|
|
|
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
|
|
|
|
|
|
|
if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) {
|
|
|
|
$this->retailcrm = new ApiHelper($settings);
|
|
|
|
|
|
|
|
try {
|
2015-07-27 18:07:33 +03:00
|
|
|
$response = $this->retailcrm->api->statusesList();
|
|
|
|
if ($response->isSuccessful() && $response->getStatusCode() == 200) {
|
|
|
|
return $response->statuses;
|
|
|
|
} else {
|
|
|
|
$this->log->write(
|
|
|
|
sprintf(
|
|
|
|
"RestApi::statusesList::Errors: [HTTP-status %s] %s",
|
|
|
|
$response->getStatusCode(),
|
|
|
|
$response->getErrorMsg()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (isset($response['errors'])) {
|
|
|
|
foreach ($response['errors'] as $error) {
|
|
|
|
$this->log->write(
|
|
|
|
sprintf(
|
|
|
|
"RestApi::statusesList::Errors: %s", $error
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return array();
|
|
|
|
}
|
2015-07-23 18:21:04 +03:00
|
|
|
} catch (CurlException $e) {
|
|
|
|
$this->data['retailcrm_error'][] = $e->getMessage();
|
2015-07-27 18:07:33 +03:00
|
|
|
$this->log->write('RestApi::orderStatusesList::Curl:' . $e->getMessage());
|
2015-07-23 18:21:04 +03:00
|
|
|
} catch (InvalidJsonException $e) {
|
|
|
|
$this->data['retailcrm_error'][] = $e->getMessage();
|
2015-07-27 18:07:33 +03:00
|
|
|
$this->log->write('RestApi::orderStatusesList::JSON:' . $e->getMessage());
|
2015-07-23 18:21:04 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return array();
|
2015-07-23 13:14:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getApiPaymentTypes()
|
|
|
|
{
|
2015-07-23 18:21:04 +03:00
|
|
|
$this->load->model('setting/setting');
|
|
|
|
$settings = $this->model_setting_setting->getSetting('retailcrm');
|
|
|
|
|
|
|
|
if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) {
|
|
|
|
$this->retailcrm = new ApiHelper($settings);
|
|
|
|
|
|
|
|
try {
|
2015-07-27 18:07:33 +03:00
|
|
|
$response = $this->retailcrm->api->paymentTypesList();
|
|
|
|
if ($response->isSuccessful() && $response->getStatusCode() == 200) {
|
|
|
|
return $response->paymentTypes;
|
|
|
|
} else {
|
|
|
|
$this->log->write(
|
|
|
|
sprintf(
|
|
|
|
"RestApi::paymentTypesList::Errors: [HTTP-status %s] %s",
|
|
|
|
$response->getStatusCode(),
|
|
|
|
$response->getErrorMsg()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (isset($response['errors'])) {
|
|
|
|
foreach ($response['errors'] as $error) {
|
|
|
|
$this->log->write(
|
|
|
|
sprintf(
|
|
|
|
"RestApi::paymentTypesList::Errors: %s", $error
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return array();
|
|
|
|
}
|
2015-07-23 18:21:04 +03:00
|
|
|
} catch (CurlException $e) {
|
|
|
|
$this->data['retailcrm_error'][] = $e->getMessage();
|
2015-07-27 18:07:33 +03:00
|
|
|
$this->log->write('RestApi::paymentTypesList::Curl:' . $e->getMessage());
|
2015-07-23 18:21:04 +03:00
|
|
|
} catch (InvalidJsonException $e) {
|
|
|
|
$this->data['retailcrm_error'][] = $e->getMessage();
|
2015-07-27 18:07:33 +03:00
|
|
|
$this->log->write('RestApi::paymentTypesList::JSON:' . $e->getMessage());
|
2015-07-23 18:21:04 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return array();
|
2015-07-23 13:14:23 +03:00
|
|
|
}
|
|
|
|
}
|
2015-06-26 18:07:36 +03:00
|
|
|
}
|