item = $item; $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(JsonSerializer::class); $this->configuredPriceSelection = $configuredPriceSelection ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(ConfiguredPriceSelection::class); 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(); $bundleOptionsIds = []; if ($this->item !== null) { // get bundle options $optionsQuoteItemOption = $this->item->getOptionByCode('bundle_option_ids'); if ($optionsQuoteItemOption && $optionsQuoteItemOption->getValue()) { $bundleOptionsIds = $this->serializer->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 = $this->serializer->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 = $this->configuredPriceSelection->getSelectionPriceList($this); 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); } 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(); } }