From 2d79091a9de74d5e0624f034b47b554ed9e9ebcd Mon Sep 17 00:00:00 2001 From: iyzoer Date: Fri, 2 Jun 2017 15:43:28 +0300 Subject: [PATCH 1/6] fix quantity offers in icml --- admin/model/retailcrm/icml.php | 46 +++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/admin/model/retailcrm/icml.php b/admin/model/retailcrm/icml.php index 2d6b5c5..4f71ebf 100644 --- a/admin/model/retailcrm/icml.php +++ b/admin/model/retailcrm/icml.php @@ -121,13 +121,20 @@ class ModelRetailcrmIcml extends Model // Если первая итерация if(empty($offers)) { foreach($requiredOption['product_option_value'] as $optionValue) { - $offers[$requiredOption['product_option_id'].':'.$requiredOption['option_id'].'-'.$optionValue['option_value_id']] = (float)$optionValue['price']; + $offers[$requiredOption['product_option_id'].':'.$requiredOption['option_id'].'-'.$optionValue['option_value_id']] = array( + 'price' => (float)$optionValue['price'], + 'qty' => $optionValue['quantity'] + ); } } else { - foreach($offers as $optionKey => $optionCost) { + foreach($offers as $optionKey => $optionAttr) { unset($offers[$optionKey]); // Работая в контексте обязательных опций не забываем удалять прошлые обязательные опции, т.к. они должны быть скомбинированы с другими обязательными опциями foreach($requiredOption['product_option_value'] as $optionValue) { - $offers[$optionKey.'_'.$requiredOption['product_option_id'].':'.$requiredOption['option_id'].'-'.$optionValue['option_value_id']] = $optionCost + (float)$optionValue['price']; + $offers[$optionKey.'_'.$requiredOption['product_option_id'].':'.$requiredOption['option_id'].'-'.$optionValue['option_value_id']] = array( + 'price' => $optionAttr['price'] + (float)$optionValue['price'], + 'qty' => ($optionAttr['qty'] > $optionValue['quantity']) ? + $optionValue['quantity'] : $optionAttr['qty'] + ); } } } @@ -138,21 +145,28 @@ class ModelRetailcrmIcml extends Model if(empty($offers)) { $offers['0:0-0'] = 0; // В случае работы с необязательными опциями мы должны учитывать товарное предложение без опций, поэтому создадим "пустую" опцию foreach($notRequiredOption['product_option_value'] as $optionValue) { - $offers[$notRequiredOption['product_option_id'].':'.$notRequiredOption['option_id'].'-'.$optionValue['option_value_id']] = (float)$optionValue['price']; + $offers[$notRequiredOption['product_option_id'].':'.$notRequiredOption['option_id'].'-'.$optionValue['option_value_id']] = array( + 'price' => (float)$optionValue['price'], + 'qty' => $optionValue['quantity'] + ); } } else { - foreach($offers as $optionKey => $optionCost) { + foreach($offers as $optionKey => $optionAttr) { foreach($notRequiredOption['product_option_value'] as $optionValue) { - $offers[$optionKey.'_'.$notRequiredOption['product_option_id'].':'.$notRequiredOption['option_id'].'-'.$optionValue['option_value_id']] = $optionCost + (float)$optionValue['price']; + $offers[$optionKey.'_'.$notRequiredOption['product_option_id'].':'.$notRequiredOption['option_id'].'-'.$optionValue['option_value_id']] = array( + 'price' => $optionAttr['price'] + (float)$optionValue['price'], + 'qty' => ($optionAttr['qty'] > $optionValue['quantity']) ? + $optionValue['quantity'] : $optionAttr['qty'] + ); } } } } if(empty($offers)) { - $offers = array('0:0-0' => '0'); + $offers = array('0:0-0' => array('price' => '0', 'qty' => '0')); } - foreach($offers as $optionsString => $optionsTotalCost) { + foreach($offers as $optionsString => $optionsValues) { $optionsString = explode('_', $optionsString); $options = array(); foreach($optionsString as $optionString) { @@ -174,12 +188,16 @@ class ModelRetailcrmIcml extends Model } $offerId = implode('_', $offerId); $e = $this->eOffers->appendChild($this->dd->createElement('offer')); - if(!empty($offerId)) - $e->setAttribute('id', $product['product_id'].'#'.$offerId); - else - $e->setAttribute('id', $product['product_id']); $e->setAttribute('productId', $product['product_id']); - $e->setAttribute('quantity', $product['quantity']); + if(!empty($offerId)) { + $e->setAttribute('id', $product['product_id'].'#'.$offerId); + $e->setAttribute('quantity', $optionsValues['qty']); + } + else { + $e->setAttribute('id', $product['product_id']); + $e->setAttribute('quantity', $product['quantity']); + } + /** * Offer activity */ @@ -220,7 +238,7 @@ class ModelRetailcrmIcml extends Model ->appendChild($this->dd->createTextNode($product['name'])); } $e->appendChild($this->dd->createElement('price')) - ->appendChild($this->dd->createTextNode($product['price'] + $optionsTotalCost)); + ->appendChild($this->dd->createTextNode($product['price'] + $optionsValues['price'])); /** * Vendor */ From 364a715d1f56c63da002936af59641c947882067 Mon Sep 17 00:00:00 2001 From: iyzoer Date: Fri, 2 Jun 2017 15:51:04 +0300 Subject: [PATCH 2/6] fix icml --- admin/model/retailcrm/icml.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/admin/model/retailcrm/icml.php b/admin/model/retailcrm/icml.php index 4f71ebf..31febd1 100644 --- a/admin/model/retailcrm/icml.php +++ b/admin/model/retailcrm/icml.php @@ -188,13 +188,14 @@ class ModelRetailcrmIcml extends Model } $offerId = implode('_', $offerId); $e = $this->eOffers->appendChild($this->dd->createElement('offer')); - $e->setAttribute('productId', $product['product_id']); if(!empty($offerId)) { $e->setAttribute('id', $product['product_id'].'#'.$offerId); + $e->setAttribute('productId', $product['product_id']); $e->setAttribute('quantity', $optionsValues['qty']); } else { $e->setAttribute('id', $product['product_id']); + $e->setAttribute('productId', $product['product_id']); $e->setAttribute('quantity', $product['quantity']); } From d221554bce5ec8809ac058ef2f7ca8ae4ee0bf62 Mon Sep 17 00:00:00 2001 From: iyzoer Date: Wed, 7 Jun 2017 15:28:27 +0300 Subject: [PATCH 3/6] fix logs --- admin/controller/module/retailcrm.php | 13 ++++++++++++- admin/model/retailcrm/customer.php | 13 ++++++++++++- admin/model/retailcrm/history.php | 13 ++++++++++++- admin/model/retailcrm/order.php | 24 ++++++++++++++++++++++++ admin/model/retailcrm/references.php | 17 ++++++++++++++--- catalog/model/retailcrm/customer.php | 13 ++++++++++++- catalog/model/retailcrm/order.php | 15 +++++++++++++-- 7 files changed, 99 insertions(+), 9 deletions(-) diff --git a/admin/controller/module/retailcrm.php b/admin/controller/module/retailcrm.php index 3daf847..2576b1f 100644 --- a/admin/controller/module/retailcrm.php +++ b/admin/controller/module/retailcrm.php @@ -137,7 +137,7 @@ class ControllerModuleRetailcrm extends Controller $this->retailcrm = new RetailcrmProxy( $url, $key, - DIR_SYSTEM . 'logs/retailcrm.log' + $this->setLogs() ); $_data['delivery'] = $this->model_retailcrm_references @@ -338,4 +338,15 @@ class ControllerModuleRetailcrm extends Controller return false; } } + + private function setLogs() + { + if (version_compare(VERSION, '2.0', '>')) { + $logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; + } else { + $logs = DIR_SYSTEM . 'logs/ecomlogic.log'; + } + + return $logs; + } } diff --git a/admin/model/retailcrm/customer.php b/admin/model/retailcrm/customer.php index a18c6c8..77c347a 100644 --- a/admin/model/retailcrm/customer.php +++ b/admin/model/retailcrm/customer.php @@ -16,7 +16,7 @@ class ModelRetailcrmCustomer extends Model { $this->retailcrmApi = new RetailcrmProxy( $settings['retailcrm_url'], $settings['retailcrm_apikey'], - DIR_SYSTEM . 'logs/retailcrm.log' + $this->serLogs() ); $customersToCrm = array(); @@ -48,4 +48,15 @@ class ModelRetailcrmCustomer extends Model { return $customerToCrm; } + + private function setLogs() + { + if (version_compare(VERSION, '2.0', '>')) { + $logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; + } else { + $logs = DIR_SYSTEM . 'logs/ecomlogic.log'; + } + + return $logs; + } } diff --git a/admin/model/retailcrm/history.php b/admin/model/retailcrm/history.php index b984635..1ac2e42 100644 --- a/admin/model/retailcrm/history.php +++ b/admin/model/retailcrm/history.php @@ -41,7 +41,7 @@ class ModelRetailcrmHistory extends Model $crm = new RetailcrmProxy( $settings['retailcrm_url'], $settings['retailcrm_apikey'], - DIR_SYSTEM . 'logs/retailcrm.log' + $this->serLogs() ); $lastRun = !empty($history['retailcrm_history']) @@ -467,4 +467,15 @@ class ModelRetailcrmHistory extends Model return array('customers' => $customersIdsFix, 'orders' => $ordersIdsFix); } + + private function setLogs() + { + if (version_compare(VERSION, '2.0', '>')) { + $logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; + } else { + $logs = DIR_SYSTEM . 'logs/ecomlogic.log'; + } + + return $logs; + } } diff --git a/admin/model/retailcrm/order.php b/admin/model/retailcrm/order.php index c9cd423..89843af 100644 --- a/admin/model/retailcrm/order.php +++ b/admin/model/retailcrm/order.php @@ -7,6 +7,19 @@ class ModelRetailcrmOrder extends Model { $this->load->model('setting/setting'); $this->settings = $this->model_setting_setting->getSetting('retailcrm'); + if(empty($orders)) + return false; + if(empty($settings['retailcrm_url']) || empty($settings['retailcrm_apikey'])) + return false; + + require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php'; + + $this->retailcrmApi = new RetailcrmProxy( + $settings['retailcrm_url'], + $settings['retailcrm_apikey'], + $this->serLogs() + ); + $ordersToCrm = array(); foreach($orders as $order) { @@ -113,4 +126,15 @@ class ModelRetailcrmOrder extends Model { return $order; } + + private function setLogs() + { + if (version_compare(VERSION, '2.0', '>')) { + $logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; + } else { + $logs = DIR_SYSTEM . 'logs/ecomlogic.log'; + } + + return $logs; + } } diff --git a/admin/model/retailcrm/references.php b/admin/model/retailcrm/references.php index b5aef36..b1f3f00 100644 --- a/admin/model/retailcrm/references.php +++ b/admin/model/retailcrm/references.php @@ -91,7 +91,7 @@ class ModelRetailcrmReferences extends Model $this->retailcrm = new RetailcrmProxy( $settings['retailcrm_url'], $settings['retailcrm_apikey'], - DIR_SYSTEM . 'logs/retailcrm.log' + $this->setLogs() ); $response = $this->retailcrm->deliveryTypesList(); @@ -109,7 +109,7 @@ class ModelRetailcrmReferences extends Model $this->retailcrm = new RetailcrmProxy( $settings['retailcrm_url'], $settings['retailcrm_apikey'], - DIR_SYSTEM . 'logs/retailcrm.log' + $this->serLogs() ); $response = $this->retailcrm->statusesList(); @@ -127,7 +127,7 @@ class ModelRetailcrmReferences extends Model $this->retailcrm = new RetailcrmProxy( $settings['retailcrm_url'], $settings['retailcrm_apikey'], - DIR_SYSTEM . 'logs/retailcrm.log' + $this->setLogs() ); $response = $this->retailcrm->paymentTypesList(); @@ -135,4 +135,15 @@ class ModelRetailcrmReferences extends Model return ($response === false) ? array() : $response->paymentTypes; } } + + private function setLogs() + { + if (version_compare(VERSION, '2.0', '>')) { + $logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; + } else { + $logs = DIR_SYSTEM . 'logs/ecomlogic.log'; + } + + return $logs; + } } diff --git a/catalog/model/retailcrm/customer.php b/catalog/model/retailcrm/customer.php index 093a109..fc2d061 100644 --- a/catalog/model/retailcrm/customer.php +++ b/catalog/model/retailcrm/customer.php @@ -15,7 +15,7 @@ class ModelRetailcrmCustomer extends Model { $this->retailcrmApi = new RetailcrmProxy( $settings['retailcrm_url'], $settings['retailcrm_apikey'], - DIR_SYSTEM . 'logs/retailcrm.log' + $this->setLogs() ); $customerToCrm = $this->process($customer); @@ -39,4 +39,15 @@ class ModelRetailcrmCustomer extends Model { return $customerToCrm; } + + private function setLogs() + { + if (version_compare(VERSION, '2.0', '>')) { + $logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; + } else { + $logs = DIR_SYSTEM . 'logs/ecomlogic.log'; + } + + return $logs; + } } diff --git a/catalog/model/retailcrm/order.php b/catalog/model/retailcrm/order.php index f59f82d..f6ba894 100644 --- a/catalog/model/retailcrm/order.php +++ b/catalog/model/retailcrm/order.php @@ -17,7 +17,7 @@ class ModelRetailcrmOrder extends Model { $this->retailcrm = new RetailcrmProxy( $settings['retailcrm_url'], $settings['retailcrm_apikey'], - DIR_SYSTEM . 'logs/retailcrm.log' + $this->setLogs() ); $order = array(); @@ -157,7 +157,7 @@ class ModelRetailcrmOrder extends Model { $this->retailcrm = new RetailcrmProxy( $settings['retailcrm_url'], $settings['retailcrm_apikey'], - DIR_SYSTEM . 'logs/retailcrm.log' + $this->setLogs() ); $order = array(); @@ -257,4 +257,15 @@ class ModelRetailcrmOrder extends Model { $this->retailcrm->ordersEdit($order); } } + + private function setLogs() + { + if (version_compare(VERSION, '2.0', '>')) { + $logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; + } else { + $logs = DIR_SYSTEM . 'logs/ecomlogic.log'; + } + + return $logs; + } } From e6ce2cbb899a13f02a379a1136c6370e205b3d19 Mon Sep 17 00:00:00 2001 From: iyzoer Date: Mon, 19 Jun 2017 10:31:14 +0300 Subject: [PATCH 4/6] fix call setLogs method --- admin/model/retailcrm/references.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/model/retailcrm/references.php b/admin/model/retailcrm/references.php index b1f3f00..118ef6d 100644 --- a/admin/model/retailcrm/references.php +++ b/admin/model/retailcrm/references.php @@ -109,7 +109,7 @@ class ModelRetailcrmReferences extends Model $this->retailcrm = new RetailcrmProxy( $settings['retailcrm_url'], $settings['retailcrm_apikey'], - $this->serLogs() + $this->setLogs() ); $response = $this->retailcrm->statusesList(); From db00b14872f48da89cd43f76ce78a1075c7cf7ad Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Fri, 22 Sep 2017 11:24:35 +0300 Subject: [PATCH 5/6] fix getting shipping methods --- admin/controller/module/retailcrm.php | 13 ++- admin/language/english/module/retailcrm.php | 1 + admin/language/russian/module/retailcrm.php | 1 + admin/model/retailcrm/customer.php | 4 +- admin/model/retailcrm/history.php | 4 +- admin/model/retailcrm/order.php | 10 +-- admin/model/retailcrm/references.php | 37 +++------ admin/view/template/module/retailcrm.tpl | 40 ++++++--- catalog/controller/api/retailcrm.php | 81 +++++++++++++++++++ catalog/model/retailcrm/customer.php | 4 +- catalog/model/retailcrm/order.php | 4 +- .../library/retailcrm/OpencartApiClient.php | 6 ++ 12 files changed, 152 insertions(+), 53 deletions(-) create mode 100644 catalog/controller/api/retailcrm.php diff --git a/admin/controller/module/retailcrm.php b/admin/controller/module/retailcrm.php index 2576b1f..178e2fc 100644 --- a/admin/controller/module/retailcrm.php +++ b/admin/controller/module/retailcrm.php @@ -26,7 +26,10 @@ class ControllerModuleRetailcrm extends Controller { $this->load->model('setting/setting'); $this->model_setting_setting - ->editSetting('retailcrm', array('retailcrm_status' => 1)); + ->editSetting('retailcrm', array( + 'retailcrm_status' => 1, + 'retailcrm_country' => array($this->config->get('config_country_id')) + )); $this->load->model('extension/event'); @@ -78,6 +81,7 @@ class ControllerModuleRetailcrm extends Controller $this->load->model('setting/setting'); $this->load->model('extension/module'); $this->load->model('retailcrm/references'); + $this->load->model('localisation/country'); $this->load->language('module/retailcrm'); $this->document->setTitle($this->language->get('heading_title')); $this->document->addStyle('/admin/view/stylesheet/retailcrm.css'); @@ -112,6 +116,7 @@ class ControllerModuleRetailcrm extends Controller 'retailcrm_dict_delivery', 'retailcrm_dict_status', 'retailcrm_dict_payment', + 'retailcrm_countries_settings' ); $this->load->model('extension/extension'); @@ -216,7 +221,7 @@ class ControllerModuleRetailcrm extends Controller $this->load->model('design/layout'); $_data['layouts'] = $this->model_design_layout->getLayouts(); - + $_data['countries'] = $this->model_localisation_country->getCountries(); $_data['header'] = $this->load->controller('common/header'); $_data['column_left'] = $this->load->controller('common/column_left'); $_data['footer'] = $this->load->controller('common/footer'); @@ -342,9 +347,9 @@ class ControllerModuleRetailcrm extends Controller private function setLogs() { if (version_compare(VERSION, '2.0', '>')) { - $logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; + $logs = DIR_SYSTEM . 'storage/logs/retailcrm.log'; } else { - $logs = DIR_SYSTEM . 'logs/ecomlogic.log'; + $logs = DIR_SYSTEM . 'logs/retailcrm.log'; } return $logs; diff --git a/admin/language/english/module/retailcrm.php b/admin/language/english/module/retailcrm.php index f1baabb..b3e8e7e 100644 --- a/admin/language/english/module/retailcrm.php +++ b/admin/language/english/module/retailcrm.php @@ -10,6 +10,7 @@ $_['text_success'] = 'Setting saved'; $_['text_notice'] = 'Warning! Timezone in CRM & your shop must be equal, you must setup it here:'; $_['retailcrm_base_settings'] = 'Connection settings'; $_['retailcrm_dict_settings'] = 'Dictionary settings'; +$_['retailcrm_countries_settings'] = 'Trading zones setting'; $_['retailcrm_url'] = 'RetailCRM URL'; $_['retailcrm_apikey'] = 'RetailCRM API Key'; diff --git a/admin/language/russian/module/retailcrm.php b/admin/language/russian/module/retailcrm.php index b2062ff..892924d 100644 --- a/admin/language/russian/module/retailcrm.php +++ b/admin/language/russian/module/retailcrm.php @@ -10,6 +10,7 @@ $_['text_success'] = 'Настройки успешно сохра $_['text_notice'] = 'Внимание! Часовой пояс в CRM должен совпадать с часовым поясом в магазине, настроки часового пояса CRM можно задать по адресу:'; $_['retailcrm_base_settings'] = 'Настройки соединения'; $_['retailcrm_dict_settings'] = 'Настройки соответствия справочников'; +$_['retailcrm_countries_settings'] = 'Настройка торговых зон'; $_['retailcrm_url'] = 'Адрес RetailCRM'; $_['retailcrm_apikey'] = 'Api ключ RetailCRM'; diff --git a/admin/model/retailcrm/customer.php b/admin/model/retailcrm/customer.php index 77c347a..5f0036f 100644 --- a/admin/model/retailcrm/customer.php +++ b/admin/model/retailcrm/customer.php @@ -52,9 +52,9 @@ class ModelRetailcrmCustomer extends Model { private function setLogs() { if (version_compare(VERSION, '2.0', '>')) { - $logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; + $logs = DIR_SYSTEM . 'storage/logs/retailcrm.log'; } else { - $logs = DIR_SYSTEM . 'logs/ecomlogic.log'; + $logs = DIR_SYSTEM . 'logs/retailcrm.log'; } return $logs; diff --git a/admin/model/retailcrm/history.php b/admin/model/retailcrm/history.php index 1ac2e42..dcb7801 100644 --- a/admin/model/retailcrm/history.php +++ b/admin/model/retailcrm/history.php @@ -471,9 +471,9 @@ class ModelRetailcrmHistory extends Model private function setLogs() { if (version_compare(VERSION, '2.0', '>')) { - $logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; + $logs = DIR_SYSTEM . 'storage/logs/retailcrm.log'; } else { - $logs = DIR_SYSTEM . 'logs/ecomlogic.log'; + $logs = DIR_SYSTEM . 'logs/retailcrm.log'; } return $logs; diff --git a/admin/model/retailcrm/order.php b/admin/model/retailcrm/order.php index 89843af..91c6d7b 100644 --- a/admin/model/retailcrm/order.php +++ b/admin/model/retailcrm/order.php @@ -9,14 +9,14 @@ class ModelRetailcrmOrder extends Model { if(empty($orders)) return false; - if(empty($settings['retailcrm_url']) || empty($settings['retailcrm_apikey'])) + if(empty($this->settings['retailcrm_url']) || empty($this->settings['retailcrm_apikey'])) return false; require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php'; $this->retailcrmApi = new RetailcrmProxy( - $settings['retailcrm_url'], - $settings['retailcrm_apikey'], + $this->settings['retailcrm_url'], + $this->settings['retailcrm_apikey'], $this->serLogs() ); @@ -130,9 +130,9 @@ class ModelRetailcrmOrder extends Model { private function setLogs() { if (version_compare(VERSION, '2.0', '>')) { - $logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; + $logs = DIR_SYSTEM . 'storage/logs/retailcrm.log'; } else { - $logs = DIR_SYSTEM . 'logs/ecomlogic.log'; + $logs = DIR_SYSTEM . 'logs/retailcrm.log'; } return $logs; diff --git a/admin/model/retailcrm/references.php b/admin/model/retailcrm/references.php index 118ef6d..8c4a553 100644 --- a/admin/model/retailcrm/references.php +++ b/admin/model/retailcrm/references.php @@ -5,9 +5,20 @@ require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php'; class ModelRetailcrmReferences extends Model { protected $retailcrm; + private $opencartApiClient; + + public function getOpercartDeliveryTypes() + { + $this->load->model('user/api'); + $this->opencartApiClient = new OpencartApiClient($this->registry); + + return $this->opencartApiClient->getDeliveryTypes(); + } public function getDeliveryTypes() { + $this->load->model('setting/store'); + return array( 'opencart' => $this->getOpercartDeliveryTypes(), 'retailcrm' => $this->getApiDeliveryTypes() @@ -30,28 +41,6 @@ class ModelRetailcrmReferences extends Model ); } - public function getOpercartDeliveryTypes() - { - $deliveryMethods = array(); - $files = glob(DIR_APPLICATION . 'controller/shipping/*.php'); - - if ($files) { - foreach ($files as $file) { - $extension = basename($file, '.php'); - - $this->load->language('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'); @@ -139,9 +128,9 @@ class ModelRetailcrmReferences extends Model private function setLogs() { if (version_compare(VERSION, '2.0', '>')) { - $logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; + $logs = DIR_SYSTEM . 'storage/logs/retailcrm.log'; } else { - $logs = DIR_SYSTEM . 'logs/ecomlogic.log'; + $logs = DIR_SYSTEM . 'logs/retailcrm.log'; } return $logs; diff --git a/admin/view/template/module/retailcrm.tpl b/admin/view/template/module/retailcrm.tpl index 144f68b..cce16f4 100644 --- a/admin/view/template/module/retailcrm.tpl +++ b/admin/view/template/module/retailcrm.tpl @@ -45,7 +45,19 @@
- +

+
+
+ +
+ +
+ +
+
@@ -56,17 +68,21 @@

- $value): ?> -
- - -
+ +
+ + $val): ?> +
+ + +
+

diff --git a/catalog/controller/api/retailcrm.php b/catalog/controller/api/retailcrm.php new file mode 100644 index 0000000..13d8ba9 --- /dev/null +++ b/catalog/controller/api/retailcrm.php @@ -0,0 +1,81 @@ +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('extension/extension'); + $this->load->model('localisation/zone'); + $this->load->model('localisation/country'); + + $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('shipping/' . $shippingModule['code']); + + if ($this->config->get($shippingModule['code'] . '_status')) { + if ($shippingModule['code'] == 'free') { + $free_total = $this->config->get('free_total'); + + if ($free_total > 0) { + $this->config->set('free_total', 0); + } + } + + if($this->{'model_shipping_' . $shippingModule['code']}->getQuote($address)) { + $quote_data[] = $this->{'model_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; + } +} diff --git a/catalog/model/retailcrm/customer.php b/catalog/model/retailcrm/customer.php index fc2d061..80f9f7b 100644 --- a/catalog/model/retailcrm/customer.php +++ b/catalog/model/retailcrm/customer.php @@ -43,9 +43,9 @@ class ModelRetailcrmCustomer extends Model { private function setLogs() { if (version_compare(VERSION, '2.0', '>')) { - $logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; + $logs = DIR_SYSTEM . 'storage/logs/retailcrm.log'; } else { - $logs = DIR_SYSTEM . 'logs/ecomlogic.log'; + $logs = DIR_SYSTEM . 'logs/retailcrm.log'; } return $logs; diff --git a/catalog/model/retailcrm/order.php b/catalog/model/retailcrm/order.php index f6ba894..8a5d1b0 100644 --- a/catalog/model/retailcrm/order.php +++ b/catalog/model/retailcrm/order.php @@ -261,9 +261,9 @@ class ModelRetailcrmOrder extends Model { private function setLogs() { if (version_compare(VERSION, '2.0', '>')) { - $logs = DIR_SYSTEM . 'storage/logs/ecomlogic.log'; + $logs = DIR_SYSTEM . 'storage/logs/retailcrm.log'; } else { - $logs = DIR_SYSTEM . 'logs/ecomlogic.log'; + $logs = DIR_SYSTEM . 'logs/retailcrm.log'; } return $logs; diff --git a/system/library/retailcrm/OpencartApiClient.php b/system/library/retailcrm/OpencartApiClient.php index 9d1ed37..e21b1da 100644 --- a/system/library/retailcrm/OpencartApiClient.php +++ b/system/library/retailcrm/OpencartApiClient.php @@ -288,6 +288,12 @@ class OpencartApiClient { $this->request('order/add', array(), $order); } + public function getDeliveryTypes() { + $this->apiToken = $this->session->data['token']; + + return $this->request('retailcrm/getDeliveryTypes', array(), array()); + } + private function getInnerIpAddr() { $opencartStoreInfo = $this->model_setting_store->getStore($this->opencartStoreId); From 1ebc6e04f6f5dccc6b9b176d9cafcf5262084121 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Fri, 22 Sep 2017 17:34:40 +0300 Subject: [PATCH 6/6] edit changelog --- Changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changelog.md b/Changelog.md index 47bf1b0..a94a8af 100644 --- a/Changelog.md +++ b/Changelog.md @@ -37,3 +37,6 @@ Changelog * Реализована выгрузка каталога (cron only) * Реализовано получение данных о заказах, сделанных на стороне CRM (cron only) +####v.1.0 +* Доработана модель получения способов доставки +* Устранены ошибки пакетной выгрузки