fix bugs after restruct

This commit is contained in:
Alex Lushpai 2015-07-23 18:21:04 +03:00
parent df9523f5b3
commit 75fbdef114
4 changed files with 79 additions and 56 deletions

View File

@ -84,10 +84,7 @@ class ControllerModuleRetailcrm extends Controller
!empty($this->data['saved_settings']['retailcrm_apikey'])
) {
$this->retailcrm = new ApiHelper(
$this->data['saved_settings']['retailcrm_url'],
$this->data['saved_settings']['retailcrm_apikey']
);
$this->retailcrm = new ApiHelper($this->data['saved_settings']);
$this->data['delivery'] = $this->model_retailcrm_references
->getDeliveryTypes();

View File

@ -5,10 +5,7 @@ class ModelRetailcrmOrder extends Model {
{
$this->load->model('setting/setting');
$settings = $this->model_setting_setting->getSetting('retailcrm');
$settings['domain'] = parse_url(HTTP_SERVER, PHP_URL_HOST);
$status = $this->model_setting_setting->getSetting('retailcrm');
$order['order_status'] = $status['retailcrm_status'][$order['order_status_id']];
$order['order_status'] = $settings['retailcrm_status'][$order['order_status_id']];
if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) {
require_once DIR_SYSTEM . 'library/retailcrm.php';

View File

@ -1,7 +1,10 @@
<?php
require_once DIR_SYSTEM . 'library/retailcrm.php';
class ModelRetailcrmReferences extends Model
{
protected $retailcrm;
public function getDeliveryTypes()
{
@ -81,40 +84,67 @@ class ModelRetailcrmReferences extends Model
protected function getApiDeliveryTypes()
{
try {
return $this->retailcrm->deliveryTypesList();
} catch (CurlException $e) {
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::deliveryTypesList::Curl:' . $e->getMessage());
} catch (InvalidJsonException $e) {
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::deliveryTypesList::JSON:' . $e->getMessage());
$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 {
return $this->retailcrm->api->deliveryTypesList();
} catch (CurlException $e) {
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::deliveryTypesList::Curl:' . $e->getMessage());
} catch (InvalidJsonException $e) {
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::deliveryTypesList::JSON:' . $e->getMessage());
}
} else {
return array();
}
}
protected function getApiOrderStatuses()
{
try {
return $this->retailcrm->orderStatusesList();
} catch (CurlException $e) {
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::orderStatusesList::Curl:' . $e->getMessage());
} catch (InvalidJsonException $e) {
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::orderStatusesList::JSON:' . $e->getMessage());
$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 {
return $this->retailcrm->api->statusesList();
} catch (CurlException $e) {
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::orderStatusesList::Curl:' . $e->getMessage());
} catch (InvalidJsonException $e) {
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::orderStatusesList::JSON:' . $e->getMessage());
}
} else {
return array();
}
}
protected function getApiPaymentTypes()
{
try {
return $this->retailcrm->paymentTypesList();
} catch (CurlException $e) {
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::paymentTypesList::Curl:' . $e->getMessage());
} catch (InvalidJsonException $e) {
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::paymentTypesList::JSON:' . $e->getMessage());
$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 {
return $this->retailcrm->api->paymentTypesList();
} catch (CurlException $e) {
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::paymentTypesList::Curl:' . $e->getMessage());
} catch (InvalidJsonException $e) {
$this->data['retailcrm_error'][] = $e->getMessage();
$this->log->addError('RestApi::paymentTypesList::JSON:' . $e->getMessage());
}
} else {
return array();
}
}
}

View File

@ -3,15 +3,14 @@
class ApiHelper
{
private $fileDate;
protected $api, $log, $settings;
protected $log, $settings;
public $api;
public function __construct($settings) {
$this->settings = $settings;
$this->domain = $settings['domain'];
$this->lastRun = $settings['retailcrm_history'];
$this->api = new Client(
$this->api = new ApiClient(
$settings['retailcrm_url'],
$settings['retailcrm_apikey']
);
@ -30,10 +29,10 @@ class ApiHelper
try {
$customers = $this->api->customers($data['telephone'], $data['email'], $data['lastname'], 200, 0);
} catch (CurlException $e) {
$this->log->addError('['.$this->domain.'] RestApi::customers:' . $e->getMessage());
$this->log->addError('['.$this->domain.'] RestApi::customers:' . json_encode($data));
$this->log->write('RestApi::customers:' . $e->getMessage());
$this->log->write('RestApi::customers:' . json_encode($data));
} catch (InvalidJsonException $e) {
$this->log->addError('['.$this->domain.'] RestApi::customers::Curl:' . $e->getMessage());
$this->log->write('RestApi::customers::Curl:' . $e->getMessage());
}
@ -62,11 +61,11 @@ class ApiHelper
$this->customer = $this->api->customersEdit($customer);
} catch (CurlException $e) {
$this->customer = $e->getMessage();
$this->log->addError('['.$this->domain.'] RestApi::orderCreate:' . $e->getMessage());
$this->log->addError('['.$this->domain.'] RestApi::orderCreate:' . json_encode($order));
$this->log->write('RestApi::orderCreate:' . $e->getMessage());
$this->log->write('RestApi::orderCreate:' . json_encode($order));
} catch (InvalidJsonException $e) {
$this->customer = $e->getMessage();
$this->log->addError('['.$this->domain.'] RestApi::orderCreate::Curl:' . $e->getMessage());
$this->log->write('RestApi::orderCreate::Curl:' . $e->getMessage());
}
}
@ -130,10 +129,10 @@ class ApiHelper
try {
$this->api->ordersEdit($order);
} catch (CurlException $e) {
$this->log->addError('['.$this->domain.'] RestApi::orderCreate:' . $e->getMessage());
$this->log->addError('['.$this->domain.'] RestApi::orderCreate:' . json_encode($order));
$this->log->write('RestApi::orderCreate:' . $e->getMessage());
$this->log->write('RestApi::orderCreate:' . json_encode($order));
} catch (InvalidJsonException $e) {
$this->log->addError('['.$this->domain.'] RestApi::orderCreate::Curl:' . $e->getMessage());
$this->log->write('RestApi::orderCreate::Curl:' . $e->getMessage());
}
}
@ -145,12 +144,12 @@ class ApiHelper
$orders = $this->api->ordersHistory($this->getDate());
$this->saveDate($this->api->getGeneratedAt()->format('Y-m-d H:i:s'));
} catch (CurlException $e) {
$this->log->addError('['.$this->domain.'] RestApi::orderHistory:' . $e->getMessage());
$this->log->addError('['.$this->domain.'] RestApi::orderHistory:' . json_encode($orders));
$this->log->write('RestApi::orderHistory:' . $e->getMessage());
$this->log->write('RestApi::orderHistory:' . json_encode($orders));
return false;
} catch (InvalidJsonException $e) {
$this->log->addError('['.$this->domain.'] RestApi::orderHistory::Curl:' . $e->getMessage());
$this->log->write('RestApi::orderHistory::Curl:' . $e->getMessage());
return false;
}
@ -163,12 +162,12 @@ class ApiHelper
try {
return $this->api->orderFixExternalIds($data);
} catch (CurlException $e) {
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds:' . $e->getMessage());
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds:' . json_encode($data));
$this->log->write('RestApi::orderFixExternalIds:' . $e->getMessage());
$this->log->write('RestApi::orderFixExternalIds:' . json_encode($data));
return false;
} catch (InvalidJsonException $e) {
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds::Curl:' . $e->getMessage());
$this->log->write('RestApi::orderFixExternalIds::Curl:' . $e->getMessage());
return false;
}
@ -179,12 +178,12 @@ class ApiHelper
try {
return $this->api->customerFixExternalIds($data);
} catch (CurlException $e) {
$this->log->addError('['.$this->domain.'] RestApi::customerFixExternalIds:' . $e->getMessage());
$this->log->addError('['.$this->domain.'] RestApi::customerFixExternalIds:' . json_encode($data));
$this->log->write('RestApi::customerFixExternalIds:' . $e->getMessage());
$this->log->write('RestApi::customerFixExternalIds:' . json_encode($data));
return false;
} catch (InvalidJsonException $e) {
$this->log->addError('['.$this->domain.'] RestApi::customerFixExternalIds::Curl:' . $e->getMessage());
$this->log->write('RestApi::customerFixExternalIds::Curl:' . $e->getMessage());
return false;
}
@ -195,10 +194,10 @@ class ApiHelper
try {
return $this->api->orderGet($order_id);
} catch (CurlException $e) {
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds:' . $e->getMessage());
$this->log->write('RestApi::orderFixExternalIds:' . $e->getMessage());
return false;
} catch (InvalidJsonException $e) {
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds::Curl:' . $e->getMessage());
$this->log->write('RestApi::orderFixExternalIds::Curl:' . $e->getMessage());
return false;
}