From 707e818aacaaba585cef693ab3c33520fae06c4c Mon Sep 17 00:00:00 2001 From: iyzoer Date: Fri, 2 Jun 2017 15:53:04 +0300 Subject: [PATCH 1/2] fix quantity offers in icml (#32) * fix quantity offers in icml * fix icml --- admin/model/retailcrm/icml.php | 45 ++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/admin/model/retailcrm/icml.php b/admin/model/retailcrm/icml.php index 2d6b5c5..31febd1 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,17 @@ class ModelRetailcrmIcml extends Model } $offerId = implode('_', $offerId); $e = $this->eOffers->appendChild($this->dd->createElement('offer')); - if(!empty($offerId)) + if(!empty($offerId)) { $e->setAttribute('id', $product['product_id'].'#'.$offerId); - else + $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']); + $e->setAttribute('productId', $product['product_id']); + $e->setAttribute('quantity', $product['quantity']); + } + /** * Offer activity */ @@ -220,7 +239,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 3a28b7c94d5a864974ed046f4e3ee1e396c7c0de Mon Sep 17 00:00:00 2001 From: iyzoer Date: Wed, 7 Jun 2017 16:25:56 +0300 Subject: [PATCH 2/2] V2.2 (#34) * fix quantity offers in icml --- 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; + } }