Skip to content

Commit a029681

Browse files
committed
MC-30626: Custom Option with Percent price is converted to a currency twice
1 parent 9ffff32 commit a029681

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
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;
1918

2019
/**
2120
* Product options section abstract block.
@@ -55,33 +54,24 @@ abstract class AbstractOptions extends \Magento\Framework\View\Element\Template
5554
*/
5655
private $calculateCustomOptionCatalogRule;
5756

58-
/**
59-
* @var CalculatorInterface
60-
*/
61-
protected $calculator;
62-
6357
/**
6458
* @param \Magento\Framework\View\Element\Template\Context $context
6559
* @param \Magento\Framework\Pricing\Helper\Data $pricingHelper
6660
* @param \Magento\Catalog\Helper\Data $catalogData
6761
* @param array $data
6862
* @param CalculateCustomOptionCatalogRule|null $calculateCustomOptionCatalogRule
69-
* @param CalculatorInterface|null $calculator
7063
*/
7164
public function __construct(
7265
\Magento\Framework\View\Element\Template\Context $context,
7366
\Magento\Framework\Pricing\Helper\Data $pricingHelper,
7467
\Magento\Catalog\Helper\Data $catalogData,
7568
array $data = [],
76-
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null,
77-
CalculatorInterface $calculator = null
69+
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null
7870
) {
7971
$this->pricingHelper = $pricingHelper;
8072
$this->_catalogHelper = $catalogData;
8173
$this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule
8274
?? ObjectManager::getInstance()->get(CalculateCustomOptionCatalogRule::class);
83-
$this->calculator = $calculator
84-
?? ObjectManager::getInstance()->get(CalculatorInterface::class);
8575
parent::__construct($context, $data);
8676
}
8777

@@ -199,7 +189,7 @@ protected function _formatPrice($value, $flag = true)
199189
$context = [CustomOptionPriceInterface::CONFIGURATION_OPTION_FLAG => true];
200190
$optionAmount = !$isPercent
201191
? $customOptionPrice->getCustomAmount($value['pricing_value'], null, $context)
202-
: $this->calculator->getAmount($value['pricing_value'], $this->getProduct(), null, $context);
192+
: $customOptionPrice->getCustomRoundAmount($value['pricing_value'], $context);
203193
$priceStr .= $this->getLayout()->getBlock('product.price.render.default')->renderAmount(
204194
$optionAmount,
205195
$customOptionPrice,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ public function getValue($priceCode = \Magento\Catalog\Pricing\Price\BasePrice::
124124
}
125125

126126
/**
127+
* Get Custom Amount object
128+
*
127129
* @param float $amount
128130
* @param null|bool|string|array $exclude
129131
* @param null|array $context
@@ -161,6 +163,19 @@ public function getCustomOptionRange($getMin, $priceCode = \Magento\Catalog\Pric
161163
return $this->priceCurrency->convertAndRound($optionValue);
162164
}
163165

166+
/**
167+
* Get custom amount without currency convert
168+
*
169+
* @param float|string $amount
170+
* @param null|array $context
171+
* @return AmountInterface
172+
*/
173+
public function getCustomRoundAmount($amount, $context = [])
174+
{
175+
$amount = $this->priceCurrency->roundPrice($amount);
176+
return $this->calculator->getAmount($amount, $this->getProduct(), null, $context);
177+
}
178+
164179
/**
165180
* Return price for select custom options
166181
*

app/code/Magento/Catalog/Test/Mftf/Test/StorefrontCheckCustomOptionPriceDifferentCurrencyTest.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@
2020
</annotations>
2121
<before>
2222
<magentoCLI command="config:set currency/options/allow EUR,USD" stepKey="setCurrencyAllow"/>
23-
<createData entity="SimpleProduct2" stepKey="createProduct">
23+
<createData entity="_defaultCategory" stepKey="createCategory"/>
24+
<createData entity="_defaultProduct" stepKey="createProduct">
25+
<requiredEntity createDataKey="createCategory"/>
2426
<field key="price">10</field>
2527
</createData>
2628
<updateData createDataKey="createProduct" entity="productWithCheckbox" stepKey="updateProductWithOptions"/>
29+
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex">
30+
<argument name="indices" value=""/>
31+
</actionGroup>
2732
</before>
2833
<after>
2934
<magentoCLI command="config:set currency/options/allow USD" stepKey="setCurrencyAllow"/>
3035
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
36+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
3137
</after>
3238
<actionGroup ref="StorefrontOpenProductEntityPageActionGroup" stepKey="openProductPageOnStorefront">
3339
<argument name="product" value="$createProduct$"/>
@@ -36,6 +42,6 @@
3642
<actionGroup ref="StorefrontSwitchCurrencyActionGroup" stepKey="switchEURCurrency">
3743
<argument name="currency" value="EUR"/>
3844
</actionGroup>
39-
<seeElement selector="{{StorefrontProductInfoMainSection.productAttributeOptionsCheckbox(ProductOptionCheckbox.title, '8.6961')}}" stepKey="checkPriceProductOptionEUR"/>
45+
<seeElement selector="{{StorefrontProductInfoMainSection.productAttributeOptionsCheckbox(ProductOptionCheckbox.title, '8.7')}}" stepKey="checkPriceProductOptionEUR"/>
4046
</test>
4147
</tests>

0 commit comments

Comments
 (0)