Example #1
0
 /**
  * Create selection price list for the retrieved options
  *
  * @param \Magento\Bundle\Model\Option $option
  * @param Product $bundleProduct
  * @return \Magento\Bundle\Pricing\Price\BundleSelectionPrice[]
  */
 public function createSelectionPriceList($option, $bundleProduct)
 {
     $priceList = [];
     $selections = $option->getSelections();
     if ($selections === null) {
         return $priceList;
     }
     /* @var $selection \Magento\Bundle\Model\Selection|\Magento\Catalog\Model\Product */
     foreach ($selections as $selection) {
         if (!$selection->isSalable()) {
             // @todo CatalogInventory Show out of stock Products
             continue;
         }
         $priceList[] = $this->selectionFactory->create($bundleProduct, $selection, $selection->getSelectionQty());
     }
     return $priceList;
 }
Example #2
0
 /**
  * @covers \Magento\Bundle\Model\Option::addSelection
  */
 public function testAddSelection()
 {
     $this->model->addSelection($this->selectionFirst);
     $this->assertContains($this->selectionFirst, $this->model->getSelections());
 }
Example #3
0
 /**
  * Get formed data from selections of option
  *
  * @param Option $option
  * @param Product $product
  * @return array
  */
 private function getSelections(Option $option, Product $product)
 {
     $selections = [];
     $selectionCount = count($option->getSelections());
     foreach ($option->getSelections() as $selectionItem) {
         /* @var $selectionItem Product */
         $selectionId = $selectionItem->getSelectionId();
         $selections[$selectionId] = $this->getSelectionItemData($product, $selectionItem);
         if (($selectionItem->getIsDefault() || $selectionCount == 1 && $option->getRequired()) && $selectionItem->isSalable()) {
             $this->selectedOptions[$option->getId()][] = $selectionId;
         }
     }
     return $selections;
 }