From 556edc9e00c2ddfd408beeda088660ca3dce67f0 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Mon, 27 Jul 2015 18:07:33 +0300 Subject: [PATCH] fix refs --- admin/model/retailcrm/references.php | 87 +++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 9 deletions(-) diff --git a/admin/model/retailcrm/references.php b/admin/model/retailcrm/references.php index 8ac2218..49924e9 100644 --- a/admin/model/retailcrm/references.php +++ b/admin/model/retailcrm/references.php @@ -91,13 +91,36 @@ class ModelRetailcrmReferences extends Model $this->retailcrm = new ApiHelper($settings); try { - return $this->retailcrm->api->deliveryTypesList(); + $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(); + } } catch (CurlException $e) { $this->data['retailcrm_error'][] = $e->getMessage(); - $this->log->addError('RestApi::deliveryTypesList::Curl:' . $e->getMessage()); + $this->log->write('RestApi::deliveryTypesList::Curl:' . $e->getMessage()); } catch (InvalidJsonException $e) { $this->data['retailcrm_error'][] = $e->getMessage(); - $this->log->addError('RestApi::deliveryTypesList::JSON:' . $e->getMessage()); + $this->log->write('RestApi::deliveryTypesList::JSON:' . $e->getMessage()); } } else { return array(); @@ -113,13 +136,36 @@ class ModelRetailcrmReferences extends Model $this->retailcrm = new ApiHelper($settings); try { - return $this->retailcrm->api->statusesList(); + $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(); + } } catch (CurlException $e) { $this->data['retailcrm_error'][] = $e->getMessage(); - $this->log->addError('RestApi::orderStatusesList::Curl:' . $e->getMessage()); + $this->log->write('RestApi::orderStatusesList::Curl:' . $e->getMessage()); } catch (InvalidJsonException $e) { $this->data['retailcrm_error'][] = $e->getMessage(); - $this->log->addError('RestApi::orderStatusesList::JSON:' . $e->getMessage()); + $this->log->write('RestApi::orderStatusesList::JSON:' . $e->getMessage()); } } else { return array(); @@ -135,13 +181,36 @@ class ModelRetailcrmReferences extends Model $this->retailcrm = new ApiHelper($settings); try { - return $this->retailcrm->api->paymentTypesList(); + $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(); + } } catch (CurlException $e) { $this->data['retailcrm_error'][] = $e->getMessage(); - $this->log->addError('RestApi::paymentTypesList::Curl:' . $e->getMessage()); + $this->log->write('RestApi::paymentTypesList::Curl:' . $e->getMessage()); } catch (InvalidJsonException $e) { $this->data['retailcrm_error'][] = $e->getMessage(); - $this->log->addError('RestApi::paymentTypesList::JSON:' . $e->getMessage()); + $this->log->write('RestApi::paymentTypesList::JSON:' . $e->getMessage()); } } else { return array();