From 707e818aacaaba585cef693ab3c33520fae06c4c Mon Sep 17 00:00:00 2001 From: iyzoer Date: Fri, 2 Jun 2017 15:53:04 +0300 Subject: [PATCH] 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 */