|
12 | 12 |
|
13 | 13 | namespace Magento\Catalog\Block\Product\View\Options;
|
14 | 14 |
|
15 |
| -use Magento\Catalog\Pricing\Price\BasePrice; |
16 | 15 | use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule;
|
17 | 16 | use Magento\Catalog\Pricing\Price\CustomOptionPriceInterface;
|
18 | 17 | use Magento\Framework\App\ObjectManager;
|
| 18 | +use Magento\Framework\Pricing\Adjustment\CalculatorInterface; |
| 19 | +use Magento\Framework\Pricing\PriceCurrencyInterface; |
19 | 20 |
|
20 | 21 | /**
|
21 | 22 | * Product options section abstract block.
|
@@ -55,24 +56,42 @@ abstract class AbstractOptions extends \Magento\Framework\View\Element\Template
|
55 | 56 | */
|
56 | 57 | private $calculateCustomOptionCatalogRule;
|
57 | 58 |
|
| 59 | + /** |
| 60 | + * @var CalculatorInterface |
| 61 | + */ |
| 62 | + private $calculator; |
| 63 | + |
| 64 | + /** |
| 65 | + * @var PriceCurrencyInterface |
| 66 | + */ |
| 67 | + private $priceCurrency; |
| 68 | + |
58 | 69 | /**
|
59 | 70 | * @param \Magento\Framework\View\Element\Template\Context $context
|
60 | 71 | * @param \Magento\Framework\Pricing\Helper\Data $pricingHelper
|
61 | 72 | * @param \Magento\Catalog\Helper\Data $catalogData
|
62 | 73 | * @param array $data
|
63 | 74 | * @param CalculateCustomOptionCatalogRule|null $calculateCustomOptionCatalogRule
|
| 75 | + * @param CalculatorInterface|null $calculator |
| 76 | + * @param PriceCurrencyInterface|null $priceCurrency |
64 | 77 | */
|
65 | 78 | public function __construct(
|
66 | 79 | \Magento\Framework\View\Element\Template\Context $context,
|
67 | 80 | \Magento\Framework\Pricing\Helper\Data $pricingHelper,
|
68 | 81 | \Magento\Catalog\Helper\Data $catalogData,
|
69 | 82 | array $data = [],
|
70 |
| - CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null |
| 83 | + CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null, |
| 84 | + CalculatorInterface $calculator = null, |
| 85 | + PriceCurrencyInterface $priceCurrency = null |
71 | 86 | ) {
|
72 | 87 | $this->pricingHelper = $pricingHelper;
|
73 | 88 | $this->_catalogHelper = $catalogData;
|
74 | 89 | $this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule
|
75 | 90 | ?? ObjectManager::getInstance()->get(CalculateCustomOptionCatalogRule::class);
|
| 91 | + $this->calculator = $calculator |
| 92 | + ?? ObjectManager::getInstance()->get(CalculatorInterface::class); |
| 93 | + $this->priceCurrency = $priceCurrency |
| 94 | + ?? ObjectManager::getInstance()->get(PriceCurrencyInterface::class); |
76 | 95 | parent::__construct($context, $data);
|
77 | 96 | }
|
78 | 97 |
|
@@ -188,7 +207,13 @@ protected function _formatPrice($value, $flag = true)
|
188 | 207 | }
|
189 | 208 |
|
190 | 209 | $context = [CustomOptionPriceInterface::CONFIGURATION_OPTION_FLAG => true];
|
191 |
| - $optionAmount = $customOptionPrice->getCustomAmount($value['pricing_value'], null, $context); |
| 210 | + $optionAmount = $isPercent |
| 211 | + ? $this->calculator->getAmount( |
| 212 | + $this->priceCurrency->roundPrice($value['pricing_value']), |
| 213 | + $this->getProduct(), |
| 214 | + null, |
| 215 | + $context |
| 216 | + ) : $customOptionPrice->getCustomAmount($value['pricing_value'], null, $context); |
192 | 217 | $priceStr .= $this->getLayout()->getBlock('product.price.render.default')->renderAmount(
|
193 | 218 | $optionAmount,
|
194 | 219 | $customOptionPrice,
|
|
0 commit comments