Fixes #21. Исправлена склейка типов доставки

This commit is contained in:
Akolzin Dmitry 2018-12-05 10:34:19 +03:00
parent 6ba09d3ac5
commit 8f216b0210

View File

@ -1,7 +1,7 @@
<?php <?php
class ControllerApiRetailcrm extends Controller class ControllerApiRetailcrm extends Controller
{ {
public function getDeliveryTypes() public function getDeliveryTypes()
{ {
$api = $this->auth(); $api = $this->auth();
@ -11,11 +11,13 @@ class ControllerApiRetailcrm extends Controller
} else { } else {
$this->load->model('localisation/country'); $this->load->model('localisation/country');
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$countries = $this->model_setting_setting->getSetting('retailcrm')['retailcrm_country']; $setting = $this->model_setting_setting->getSetting('retailcrm');
$response = array(); $response = array();
foreach ($countries as $country) { if (isset($setting['retailcrm_country']) && $setting['retailcrm_country']) {
$response = array_merge($response, $this->getDeliveryTypesByZones($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) protected function getDeliveryTypesByZones($country_id)
{ {
$this->load->model('extension/extension'); $this->load->model('extension/extension');
$this->load->model('localisation/zone'); $this->load->model('localisation/zone');
$this->load->model('localisation/country'); $this->load->model('localisation/country');
@ -76,7 +78,7 @@ class ControllerApiRetailcrm extends Controller
'postcode' => '', 'postcode' => '',
'city' => '' 'city' => ''
); );
foreach ($shippingModules as $shippingModule) { foreach ($shippingModules as $shippingModule) {
$this->load->model('shipping/' . $shippingModule['code']); $this->load->model('shipping/' . $shippingModule['code']);
@ -88,7 +90,7 @@ class ControllerApiRetailcrm extends Controller
$this->config->set('free_total', 0); $this->config->set('free_total', 0);
} }
} }
if($this->{'model_shipping_' . $shippingModule['code']}->getQuote($address)) { if($this->{'model_shipping_' . $shippingModule['code']}->getQuote($address)) {
$quote_data[] = $this->{'model_shipping_' . $shippingModule['code']}->getQuote($address); $quote_data[] = $this->{'model_shipping_' . $shippingModule['code']}->getQuote($address);
} else { } else {
@ -121,6 +123,18 @@ class ControllerApiRetailcrm extends Controller
return $deliveryTypes; 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() private function auth()
{ {
if (version_compare(VERSION, '2.1.0', '>=')) { if (version_compare(VERSION, '2.1.0', '>=')) {