Skip to content

Commit f2e46ec

Browse files
committed
MC-30626: Custom Option with Percent price is converted to a currency twice
1 parent 402fadb commit f2e46ec

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

app/code/Magento/Catalog/Block/Product/View/Options/AbstractOptions.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule;
1616
use Magento\Catalog\Pricing\Price\CustomOptionPriceInterface;
1717
use Magento\Framework\App\ObjectManager;
18+
use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
19+
use Magento\Framework\Pricing\PriceCurrencyInterface;
1820

1921
/**
2022
* Product options section abstract block.
@@ -54,24 +56,42 @@ abstract class AbstractOptions extends \Magento\Framework\View\Element\Template
5456
*/
5557
private $calculateCustomOptionCatalogRule;
5658

59+
/**
60+
* @var CalculatorInterface
61+
*/
62+
private $calculator;
63+
64+
/**
65+
* @var PriceCurrencyInterface
66+
*/
67+
private $priceCurrency;
68+
5769
/**
5870
* @param \Magento\Framework\View\Element\Template\Context $context
5971
* @param \Magento\Framework\Pricing\Helper\Data $pricingHelper
6072
* @param \Magento\Catalog\Helper\Data $catalogData
6173
* @param array $data
6274
* @param CalculateCustomOptionCatalogRule|null $calculateCustomOptionCatalogRule
75+
* @param CalculatorInterface|null $calculator
76+
* @param PriceCurrencyInterface|null $priceCurrency
6377
*/
6478
public function __construct(
6579
\Magento\Framework\View\Element\Template\Context $context,
6680
\Magento\Framework\Pricing\Helper\Data $pricingHelper,
6781
\Magento\Catalog\Helper\Data $catalogData,
6882
array $data = [],
69-
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null
83+
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null,
84+
CalculatorInterface $calculator = null,
85+
PriceCurrencyInterface $priceCurrency = null
7086
) {
7187
$this->pricingHelper = $pricingHelper;
7288
$this->_catalogHelper = $catalogData;
7389
$this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule
7490
?? 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);
7595
parent::__construct($context, $data);
7696
}
7797

@@ -186,9 +206,14 @@ protected function _formatPrice($value, $flag = true)
186206
}
187207
}
188208

189-
$context['should_not_be_converted'] = $isPercent;
190209
$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);
192217
$priceStr .= $this->getLayout()->getBlock('product.price.render.default')->renderAmount(
193218
$optionAmount,
194219
$customOptionPrice,

app/code/Magento/Catalog/Pricing/Price/CustomOptionPrice.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
/**
1616
* Class OptionPrice
17+
*
1718
*/
1819
class CustomOptionPrice extends AbstractPrice implements CustomOptionPriceInterface
1920
{
@@ -123,8 +124,6 @@ public function getValue($priceCode = \Magento\Catalog\Pricing\Price\BasePrice::
123124
}
124125

125126
/**
126-
* Calculate Custom Amount
127-
*
128127
* @param float $amount
129128
* @param null|bool|string|array $exclude
130129
* @param null|array $context
@@ -133,9 +132,7 @@ public function getValue($priceCode = \Magento\Catalog\Pricing\Price\BasePrice::
133132
public function getCustomAmount($amount = null, $exclude = null, $context = [])
134133
{
135134
if (null !== $amount) {
136-
$amount = (isset($context['should_not_be_converted']) && $context['should_not_be_converted'])
137-
? $this->priceCurrency->roundPrice($amount)
138-
: $this->priceCurrency->convertAndRound($amount);
135+
$amount = $this->priceCurrency->convertAndRound($amount);
139136
} else {
140137
$amount = $this->getValue();
141138
}

0 commit comments

Comments
 (0)