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 */