item = $item; parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency); } /** * @param ItemInterface $item * @return $this */ public function setItem(ItemInterface $item) { $this->item = $item; return $this; } /** * Get Options with attached Selections collection * * @return array|\Magento\Bundle\Model\ResourceModel\Option\Collection */ public function getOptions() { $bundleProduct = $this->product; $bundleOptions = []; /** @var \Magento\Bundle\Model\Product\Type $typeInstance */ $typeInstance = $bundleProduct->getTypeInstance(); // get bundle options $optionsQuoteItemOption = $this->item->getOptionByCode('bundle_option_ids'); $bundleOptionsIds = $optionsQuoteItemOption ? unserialize($optionsQuoteItemOption->getValue()) : []; if ($bundleOptionsIds) { /** @var \Magento\Bundle\Model\ResourceModel\Option\Collection $optionsCollection */ $optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $bundleProduct); // get and add bundle selections collection $selectionsQuoteItemOption = $this->item->getOptionByCode('bundle_selection_ids'); $bundleSelectionIds = unserialize($selectionsQuoteItemOption->getValue()); if ($bundleSelectionIds) { $selectionsCollection = $typeInstance->getSelectionsByIds($bundleSelectionIds, $bundleProduct); $bundleOptions = $optionsCollection->appendSelections($selectionsCollection, true); } } return $bundleOptions; } /** * Option amount calculation for bundle product * * @param float $baseValue * @return \Magento\Framework\Pricing\Amount\AmountInterface */ public function getConfiguredAmount($baseValue = 0.) { $selectionPriceList = []; foreach ($this->getOptions() as $option) { $selectionPriceList = array_merge( $selectionPriceList, $this->calculator->createSelectionPriceList($option, $this->product) ); } return $this->calculator->calculateBundleAmount( $baseValue, $this->product, $selectionPriceList ); } /** * Get price value * * @return float */ public function getValue() { if ($this->item) { $configuredOptionsAmount = $this->getConfiguredAmount()->getBaseAmount(); return parent::getValue() + $this->priceInfo ->getPrice(BundleDiscountPrice::PRICE_CODE) ->calculateDiscount($configuredOptionsAmount); } else { return parent::getValue(); } } /** * Get Amount for configured price which is included amount for all selected options * * @return \Magento\Framework\Pricing\Amount\AmountInterface */ public function getAmount() { return $this->item ? $this->getConfiguredAmount($this->getBasePrice()->getValue()) : parent::getAmount(); } }