|
15 | 15 | use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule;
|
16 | 16 | use Magento\Catalog\Pricing\Price\CustomOptionPriceInterface;
|
17 | 17 | use Magento\Framework\App\ObjectManager;
|
| 18 | +use Magento\Framework\Pricing\Adjustment\CalculatorInterface; |
| 19 | +use Magento\Framework\Pricing\PriceCurrencyInterface; |
18 | 20 |
|
19 | 21 | /**
|
20 | 22 | * Product options section abstract block.
|
@@ -54,24 +56,42 @@ abstract class AbstractOptions extends \Magento\Framework\View\Element\Template
|
54 | 56 | */
|
55 | 57 | private $calculateCustomOptionCatalogRule;
|
56 | 58 |
|
| 59 | + /** |
| 60 | + * @var CalculatorInterface |
| 61 | + */ |
| 62 | + private $calculator; |
| 63 | + |
| 64 | + /** |
| 65 | + * @var PriceCurrencyInterface |
| 66 | + */ |
| 67 | + private $priceCurrency; |
| 68 | + |
57 | 69 | /**
|
58 | 70 | * @param \Magento\Framework\View\Element\Template\Context $context
|
59 | 71 | * @param \Magento\Framework\Pricing\Helper\Data $pricingHelper
|
60 | 72 | * @param \Magento\Catalog\Helper\Data $catalogData
|
61 | 73 | * @param array $data
|
62 | 74 | * @param CalculateCustomOptionCatalogRule|null $calculateCustomOptionCatalogRule
|
| 75 | + * @param CalculatorInterface|null $calculator |
| 76 | + * @param PriceCurrencyInterface|null $priceCurrency |
63 | 77 | */
|
64 | 78 | public function __construct(
|
65 | 79 | \Magento\Framework\View\Element\Template\Context $context,
|
66 | 80 | \Magento\Framework\Pricing\Helper\Data $pricingHelper,
|
67 | 81 | \Magento\Catalog\Helper\Data $catalogData,
|
68 | 82 | array $data = [],
|
69 |
| - CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null |
| 83 | + CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null, |
| 84 | + CalculatorInterface $calculator = null, |
| 85 | + PriceCurrencyInterface $priceCurrency = null |
70 | 86 | ) {
|
71 | 87 | $this->pricingHelper = $pricingHelper;
|
72 | 88 | $this->_catalogHelper = $catalogData;
|
73 | 89 | $this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule
|
74 | 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); |
75 | 95 | parent::__construct($context, $data);
|
76 | 96 | }
|
77 | 97 |
|
@@ -186,9 +206,14 @@ protected function _formatPrice($value, $flag = true)
|
186 | 206 | }
|
187 | 207 | }
|
188 | 208 |
|
189 |
| - $context['should_not_be_converted'] = $isPercent; |
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