diff --git a/admin/controller/extension/module/retailcrm.php b/admin/controller/extension/module/retailcrm.php index fc5500f..24c26dd 100644 --- a/admin/controller/extension/module/retailcrm.php +++ b/admin/controller/extension/module/retailcrm.php @@ -81,7 +81,7 @@ class ControllerExtensionModuleRetailcrm extends Controller */ public function index() { - + $this->load->model('localisation/country'); $this->load->model('setting/setting'); $this->load->model('extension/module'); $this->load->model('extension/retailcrm/references'); @@ -231,7 +231,8 @@ class ControllerExtensionModuleRetailcrm extends Controller $_data['header'] = $this->load->controller('common/header'); $_data['column_left'] = $this->load->controller('common/column_left'); $_data['footer'] = $this->load->controller('common/footer'); - + $_data['countries'] = $this->model_localisation_country->getCountries(); + $this->response->setOutput( $this->load->view('extension/module/retailcrm.tpl', $_data) ); diff --git a/admin/model/extension/retailcrm/references.php b/admin/model/extension/retailcrm/references.php index b764c55..79d7564 100644 --- a/admin/model/extension/retailcrm/references.php +++ b/admin/model/extension/retailcrm/references.php @@ -5,9 +5,20 @@ require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php'; class ModelExtensionRetailcrmReferences extends Model { protected $retailcrm; + private $opencartApiClient; + + public function getOpercartDeliveryTypes() + { + $this->load->model('user/api'); + $this->opencartApiClient = new OpencartApiClient($this->registry); + + return $this->opencartApiClient->request('retailcrm/getDeliveryTypes', array(), array()); + } public function getDeliveryTypes() { + $this->load->model('setting/store'); + return array( 'opencart' => $this->getOpercartDeliveryTypes(), 'retailcrm' => $this->getApiDeliveryTypes() @@ -30,28 +41,6 @@ class ModelExtensionRetailcrmReferences extends Model ); } - public function getOpercartDeliveryTypes() - { - $deliveryMethods = array(); - $files = glob(DIR_APPLICATION . 'controller/extension/shipping/*.php'); - - if ($files) { - foreach ($files as $file) { - $extension = basename($file, '.php'); - - $this->load->language('extension/shipping/' . $extension); - - if ($this->config->get($extension . '_status')) { - $deliveryMethods[$extension.'.'.$extension] = strip_tags( - $this->language->get('heading_title') - ); - } - } - } - - return $deliveryMethods; - } - public function getOpercartOrderStatuses() { $this->load->model('localisation/order_status'); diff --git a/admin/view/stylesheet/retailcrm.css b/admin/view/stylesheet/retailcrm.css index 43cbeb6..5c3b88f 100644 --- a/admin/view/stylesheet/retailcrm.css +++ b/admin/view/stylesheet/retailcrm.css @@ -1,2 +1,3 @@ .retailcrm_unit {margin-bottom: 10px;} .retailcrm_unit input {width: 30%;} +.checkbox input{width: auto;} diff --git a/admin/view/template/extension/module/retailcrm.tpl b/admin/view/template/extension/module/retailcrm.tpl index 144f68b..a77bb21 100644 --- a/admin/view/template/extension/module/retailcrm.tpl +++ b/admin/view/template/extension/module/retailcrm.tpl @@ -45,6 +45,19 @@
+

+
+
+ +
+ +
+ +
+
@@ -56,16 +69,21 @@

- $value): ?> -
- $v): ?> - + - + +
@@ -107,4 +125,4 @@ - + \ No newline at end of file diff --git a/catalog/controller/api/retailcrm.php b/catalog/controller/api/retailcrm.php new file mode 100644 index 0000000..00ad266 --- /dev/null +++ b/catalog/controller/api/retailcrm.php @@ -0,0 +1,74 @@ +load->model('localisation/country'); + $this->load->model('setting/setting'); + + $countries = $this->model_setting_setting->getSetting('retailcrm')['retailcrm_country']; + $deliveryTypes = array(); + + foreach ($countries as $country) { + $deliveryTypes = array_merge($deliveryTypes, $this->getDeliveryTypesByZones($country)); + } + + if (isset($this->request->server['HTTP_ORIGIN'])) { + $this->response->addHeader('Access-Control-Allow-Origin: ' . $this->request->server['HTTP_ORIGIN']); + $this->response->addHeader('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS'); + $this->response->addHeader('Access-Control-Max-Age: 1000'); + $this->response->addHeader('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($deliveryTypes)); + } + + protected function getDeliveryTypesByZones($country_id) + { + $this->load->model('localisation/zone'); + $this->load->model('localisation/country'); + $this->load->model('extension/extension'); + + $shippingModules = $this->model_extension_extension->getExtensions('shipping'); + $zones = $this->model_localisation_zone->getZonesByCountryId($country_id); + $country = $this->model_localisation_country->getCountry($country_id); + $quote_data = array(); + + foreach ($zones as $zone) { + $address = array( + 'country_id' => $country_id, + 'zone_id' => $zone['zone_id'], + 'iso_code_2' => $country['iso_code_2'], + 'iso_code_3' => $country['iso_code_3'], + 'zone_code' => $zone['code'], + 'postcode' => '', + 'city' => '' + ); + + foreach ($shippingModules as $shippingModule) { + + $this->load->model('extension/shipping/' . $shippingModule['code']); + + if ($this->config->get($shippingModule['code'] . '_status')) { + if($this->{'model_extension_shipping_' . $shippingModule['code']}->getQuote($address)) { + $quote_data[] = $this->{'model_extension_shipping_' . $shippingModule['code']}->getQuote($address); + } + } + } + } + + $deliveryTypes = array(); + + foreach ($quote_data as $shipping) { + + foreach ($shipping['quote'] as $shippingMethod) { + $deliveryTypes[$shipping['code']]['title'] = $shipping['title']; + $deliveryTypes[$shipping['code']][$shippingMethod['code']] = $shippingMethod; + } + + } + + return $deliveryTypes; + } +}