/** * Calculate amount for dynamic bundle product * * @param float $basePriceValue * @param Product $bundleProduct * @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList * @param null|string $exclude * @return \Magento\Framework\Pricing\Amount\AmountInterface */ protected function calculateDynamicBundleAmount($basePriceValue, $bundleProduct, $selectionPriceList, $exclude) { $fullAmount = 0.0; $adjustments = []; $amountList = [$this->calculator->getAmount($basePriceValue, $bundleProduct, $exclude)]; /** @var $option \Magento\Bundle\Model\Option */ foreach ($selectionPriceList as $selectionPrice) { $amountList[] = $selectionPrice->getAmount(); } /** @var Store $store */ $store = $bundleProduct->getStore(); $roundingMethod = $this->taxHelper->getCalculationAgorithm($store); /** @var \Magento\Framework\Pricing\Amount\AmountInterface $itemAmount */ foreach ($amountList as $itemAmount) { if ($roundingMethod != TaxCalculationServiceInterface::CALC_TOTAL_BASE) { //We need to round the individual selection first $fullAmount += $store->roundPrice($itemAmount->getValue()); foreach ($itemAmount->getAdjustmentAmounts() as $code => $adjustment) { $adjustment = $store->roundPrice($adjustment); $adjustments[$code] = isset($adjustments[$code]) ? $adjustments[$code] + $adjustment : $adjustment; } } else { $fullAmount += $itemAmount->getValue(); foreach ($itemAmount->getAdjustmentAmounts() as $code => $adjustment) { $adjustments[$code] = isset($adjustments[$code]) ? $adjustments[$code] + $adjustment : $adjustment; } } } if ($exclude && isset($adjustments[$exclude])) { $fullAmount -= $adjustments[$exclude]; unset($adjustments[$exclude]); } return $this->amountFactory->create($fullAmount, $adjustments); }