56 private $optionAmount = [];
61 private $selectionPriceListProvider;
81 $this->selectionFactory = $bundleSelectionFactory;
84 $this->selectionPriceListProvider = $selectionPriceListProvider;
156 $useRegularPrice =
false 158 $cacheKey = implode(
'-', [$saleableItem->
getId(), $exclude, $searchMin,
$baseAmount, $useRegularPrice]);
159 if (!isset($this->optionAmount[$cacheKey])) {
168 return $this->optionAmount[$cacheKey];
197 return $this->getSelectionPriceListProvider()->getPriceList(
$bundleProduct, $searchMin, $useRegularPrice);
204 private function getSelectionPriceListProvider()
206 if (
null === $this->selectionPriceListProvider) {
208 ->get(SelectionPriceListProviderInterface::class);
211 return $this->selectionPriceListProvider;
224 return !
$option->getSelections() || ($canSkipRequiredOption && !
$option->getRequired());
239 return $item->getRequired();
252 protected function getBundleOptions(
Product $saleableItem)
256 \
Magento\Bundle\Pricing\
Price\BundleOptionPrice::PRICE_CODE
258 return $bundlePrice->getOptions();
273 return $this->calculateFixedBundleAmount($basePriceValue,
$bundleProduct, $selectionPriceList, $exclude);
275 return $this->calculateDynamicBundleAmount($basePriceValue,
$bundleProduct, $selectionPriceList, $exclude);
287 protected function calculateFixedBundleAmount($basePriceValue,
$bundleProduct, $selectionPriceList, $exclude)
289 $fullAmount = $basePriceValue;
291 foreach ($selectionPriceList as $selectionPrice) {
292 $fullAmount += ($selectionPrice->getValue() * $selectionPrice->getQuantity());
294 return $this->calculator->getAmount($fullAmount,
$bundleProduct, $exclude);
307 protected function calculateDynamicBundleAmount($basePriceValue,
$bundleProduct, $selectionPriceList, $exclude)
313 $amountList[
$i][
'amount'] = $this->calculator->getAmount($basePriceValue,
$bundleProduct, $exclude);
314 $amountList[
$i][
'quantity'] = 1;
316 foreach ($selectionPriceList as $selectionPrice) {
318 if ($selectionPrice) {
319 $amountList[
$i][
'amount'] = $selectionPrice->getAmount();
321 $amountList[
$i][
'quantity'] = $selectionPrice->getQuantity();
327 $roundingMethod = $this->taxHelper->getCalculationAlgorithm(
$store);
328 foreach ($amountList as $amountInfo) {
330 $itemAmount = $amountInfo[
'amount'];
331 $qty = $amountInfo[
'quantity'];
335 $fullAmount += ($this->priceCurrency->round($itemAmount->getValue()) * $qty);
336 foreach ($itemAmount->getAdjustmentAmounts() as
$code => $adjustment) {
337 $adjustment = $this->priceCurrency->round($adjustment) * $qty;
338 $adjustments[
$code] = isset($adjustments[
$code]) ? $adjustments[
$code] + $adjustment : $adjustment;
341 $fullAmount += ($itemAmount->getValue() * $qty);
342 foreach ($itemAmount->getAdjustmentAmounts() as
$code => $adjustment) {
343 $adjustment = $adjustment * $qty;
344 $adjustments[
$code] = isset($adjustments[
$code]) ? $adjustments[
$code] + $adjustment : $adjustment;
348 if (is_array($exclude) ==
false) {
349 if ($exclude && isset($adjustments[$exclude])) {
350 $fullAmount -= $adjustments[$exclude];
351 unset($adjustments[$exclude]);
354 foreach ($exclude as $oneExclusion) {
355 if ($oneExclusion && isset($adjustments[$oneExclusion])) {
356 $fullAmount -= $adjustments[$oneExclusion];
357 unset($adjustments[$oneExclusion]);
361 return $this->amountFactory->create($fullAmount, $adjustments);
375 $selections =
$option->getSelections();
376 if ($selections ===
null) {
380 foreach ($selections as $selection) {
381 if (!$selection->isSalable()) {
385 $priceList[] = $this->selectionFactory->create(
388 $selection->getSelectionQty(),
390 'useRegularPrice' => $useRegularPrice,
409 foreach ($selectionPriceList as $current) {
410 $qty = $current->getQuantity();
411 $currentValue = $current->getAmount()->getValue() * $qty;
415 $lastSelectionPrice = end(
$result);
416 $lastValue = $lastSelectionPrice->getAmount()->getValue() * $lastSelectionPrice->getQuantity();
417 if ($searchMin && $lastValue > $currentValue) {
422 && !
$option->isMultiSelection()
423 && $lastValue < $currentValue
getMinRegularAmount($amount, Product $saleableItem, $exclude=null)
__construct(CalculatorBase $calculator, AmountFactory $amountFactory, BundleSelectionFactory $bundleSelectionFactory, TaxHelper $taxHelper, PriceCurrencyInterface $priceCurrency, SelectionPriceListProviderInterface $selectionPriceListProvider=null)
elseif(isset( $params[ 'redirect_parent']))
getSelectionAmounts(Product $bundleProduct, $searchMin, $useRegularPrice=false)
createSelectionPriceList($option, $bundleProduct, $useRegularPrice=false)
getMaxRegularAmount($amount, Product $saleableItem, $exclude=null)
getMaxAmount($amount, Product $saleableItem, $exclude=null)
hasRequiredOption($bundleProduct)
getAmountWithoutOption($amount, Product $saleableItem)
processOptions($option, $selectionPriceList, $searchMin=true)
calculateBundleAmount($basePriceValue, $bundleProduct, $selectionPriceList, $exclude=null)
getAmount($amount, SaleableInterface $saleableItem, $exclude=null, $context=[])
canSkipOption($option, $canSkipRequiredOption)
getOptionsAmount(Product $saleableItem, $exclude=null, $searchMin=true, $baseAmount=0., $useRegularPrice=false)