Example #1
0
 /**
  * Append selection to options
  * stripBefore - indicates to reload
  * appendAll - indicates do we need to filter by saleable and required custom options
  *
  * @param \Magento\Bundle\Model\Resource\Selection\Collection $selectionsCollection
  * @param bool $stripBefore
  * @param bool $appendAll
  * @return \Magento\Framework\Object[]
  */
 public function appendSelections($selectionsCollection, $stripBefore = false, $appendAll = true)
 {
     if ($stripBefore) {
         $this->_stripSelections();
     }
     if (!$this->_selectionsAppended) {
         foreach ($selectionsCollection->getItems() as $key => $selection) {
             $option = $this->getItemById($selection->getOptionId());
             if ($option) {
                 if ($appendAll || $selection->isSalable() && !$selection->getRequiredOptions()) {
                     $selection->setOption($option);
                     $option->addSelection($selection);
                 } else {
                     $selectionsCollection->removeItemByKey($key);
                 }
             }
         }
         $this->_selectionsAppended = true;
     }
     return $this->getItems();
 }
Example #2
0
 /**
  * @param \Magento\Bundle\Model\Resource\Selection\Collection $selections
  * @param bool $skipSaleableCheck
  * @param \Magento\Bundle\Model\Resource\Option\Collection $optionsCollection
  * @param int[] $options
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function checkSelectionsIsSale($selections, $skipSaleableCheck, $optionsCollection, $options)
 {
     foreach ($selections->getItems() as $selection) {
         if (!$selection->isSalable() && !$skipSaleableCheck) {
             $_option = $optionsCollection->getItemById($selection->getOptionId());
             $optionId = $_option->getId();
             if (is_array($options[$optionId]) && count($options[$optionId]) > 1) {
                 $moreSelections = true;
             } else {
                 $moreSelections = false;
             }
             $isMultiSelection = $_option->isMultiSelection();
             if ($_option->getRequired() && (!$isMultiSelection || !$moreSelections)) {
                 throw new \Magento\Framework\Exception\LocalizedException(__('The required options you selected are not available.'));
             }
         }
     }
 }