示例#1
0
 /**
  * Find minimal or maximal price for existing options
  *
  * @param \Magento\Bundle\Model\Option $option
  * @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList
  * @param bool $searchMin
  * @return \Magento\Bundle\Pricing\Price\BundleSelectionPrice[]
  */
 public function processOptions($option, $selectionPriceList, $searchMin = true)
 {
     $result = [];
     foreach ($selectionPriceList as $current) {
         $currentValue = $current->getAmount()->getValue();
         if (empty($result)) {
             $result = [$current];
         } elseif ($searchMin && end($result)->getAmount()->getValue() > $currentValue) {
             $result = [$current];
         } elseif (!$searchMin && $option->isMultiSelection()) {
             $result[] = $current;
         } elseif (!$searchMin && !$option->isMultiSelection() && end($result)->getAmount()->getValue() < $currentValue) {
             $result = [$current];
         }
     }
     return $result;
 }
示例#2
0
 /**
  * @param string $type
  * @param bool $expectedValue
  * @dataProvider dataProviderForIsMultiSelection
  */
 public function testIsMultiSelection($type, $expectedValue)
 {
     $this->model->setType($type);
     $this->assertEquals($expectedValue, $this->model->isMultiSelection());
 }
示例#3
0
 /**
  * Find minimal or maximal price for existing options
  *
  * @param \Magento\Bundle\Model\Option $option
  * @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList
  * @param bool $searchMin
  * @return \Magento\Bundle\Pricing\Price\BundleSelectionPrice[]
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function processOptions($option, $selectionPriceList, $searchMin = true)
 {
     $result = [];
     foreach ($selectionPriceList as $current) {
         $qty = $current->getQuantity();
         $currentValue = $current->getAmount()->getValue() * $qty;
         if (empty($result)) {
             $result = [$current];
         } else {
             $lastSelectionPrice = end($result);
             $lastValue = $lastSelectionPrice->getAmount()->getValue() * $lastSelectionPrice->getQuantity();
             if ($searchMin && $lastValue > $currentValue) {
                 $result = [$current];
             } elseif (!$searchMin && $option->isMultiSelection()) {
                 $result[] = $current;
             } elseif (!$searchMin && !$option->isMultiSelection() && $lastValue < $currentValue) {
                 $result = [$current];
             }
         }
     }
     return $result;
 }