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']) !empty($this->data['saved_settings']['retailcrm_apikey'])
) { ) {
$this->retailcrm = new ApiHelper( $this->retailcrm = new ApiHelper($this->data['saved_settings']);
$this->data['saved_settings']['retailcrm_url'],
$this->data['saved_settings']['retailcrm_apikey']
);
$this->data['delivery'] = $this->model_retailcrm_references $this->data['delivery'] = $this->model_retailcrm_references
->getDeliveryTypes(); ->getDeliveryTypes();

View File

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

View File

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

View File

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