From 8f216b0210d2678a914d09f9b2d2a1d3ecb7d789 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Wed, 5 Dec 2018 10:34:19 +0300 Subject: [PATCH] =?UTF-8?q?Fixes=20#21.=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=81=D0=BA=D0=BB=D0=B5=D0=B9?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=82=D0=B8=D0=BF=D0=BE=D0=B2=20=D0=B4=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- catalog/controller/api/retailcrm.php | 30 ++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/catalog/controller/api/retailcrm.php b/catalog/controller/api/retailcrm.php index ee3fa27..9d8c15a 100644 --- a/catalog/controller/api/retailcrm.php +++ b/catalog/controller/api/retailcrm.php @@ -1,7 +1,7 @@ auth(); @@ -11,11 +11,13 @@ class ControllerApiRetailcrm extends Controller } else { $this->load->model('localisation/country'); $this->load->model('setting/setting'); - $countries = $this->model_setting_setting->getSetting('retailcrm')['retailcrm_country']; + $setting = $this->model_setting_setting->getSetting('retailcrm'); $response = array(); - foreach ($countries as $country) { - $response = array_merge($response, $this->getDeliveryTypesByZones($country)); + if (isset($setting['retailcrm_country']) && $setting['retailcrm_country']) { + foreach ($setting['retailcrm_country'] as $country) { + $response = $this->mergeDeliveryTypes($country, $response); + } } } @@ -56,7 +58,7 @@ class ControllerApiRetailcrm extends Controller } protected function getDeliveryTypesByZones($country_id) - { + { $this->load->model('extension/extension'); $this->load->model('localisation/zone'); $this->load->model('localisation/country'); @@ -76,7 +78,7 @@ class ControllerApiRetailcrm extends Controller 'postcode' => '', 'city' => '' ); - + foreach ($shippingModules as $shippingModule) { $this->load->model('shipping/' . $shippingModule['code']); @@ -88,7 +90,7 @@ class ControllerApiRetailcrm extends Controller $this->config->set('free_total', 0); } } - + if($this->{'model_shipping_' . $shippingModule['code']}->getQuote($address)) { $quote_data[] = $this->{'model_shipping_' . $shippingModule['code']}->getQuote($address); } else { @@ -121,6 +123,18 @@ class ControllerApiRetailcrm extends Controller return $deliveryTypes; } + private function mergeDeliveryTypes($country, $result) { + $delivery_types = $this->getDeliveryTypesByZones($country); + foreach ($delivery_types as $shipping_module => $shipping_type) { + if (isset($result[$shipping_module])) { + $result[$shipping_module] = array_merge($result[$shipping_module], $shipping_type); + } else { + $result[$shipping_module] = $shipping_type; + } + } + return $result; + } + private function auth() { if (version_compare(VERSION, '2.1.0', '>=')) {