Skip to content

Commit 402fadb

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

File tree

4 files changed

+35
-22
lines changed

4 files changed

+35
-22
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,9 @@ protected function _formatPrice($value, $flag = true)
186186
}
187187
}
188188

189-
$context = [CustomOptionPriceInterface::CONFIGURATION_OPTION_FLAG => true];
190-
$optionAmount = !$isPercent
191-
? $customOptionPrice->getCustomAmount($value['pricing_value'], null, $context)
192-
: $customOptionPrice->getCustomRoundAmount($value['pricing_value'], $context);
189+
$context['should_not_be_converted'] = $isPercent;
190+
$context[CustomOptionPriceInterface::CONFIGURATION_OPTION_FLAG] = true;
191+
$optionAmount = $customOptionPrice->getCustomAmount($value['pricing_value'], null, $context);
193192
$priceStr .= $this->getLayout()->getBlock('product.price.render.default')->renderAmount(
194193
$optionAmount,
195194
$customOptionPrice,

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

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

1515
/**
1616
* Class OptionPrice
17-
*
1817
*/
1918
class CustomOptionPrice extends AbstractPrice implements CustomOptionPriceInterface
2019
{
@@ -124,7 +123,7 @@ public function getValue($priceCode = \Magento\Catalog\Pricing\Price\BasePrice::
124123
}
125124

126125
/**
127-
* Get Custom Amount object
126+
* Calculate Custom Amount
128127
*
129128
* @param float $amount
130129
* @param null|bool|string|array $exclude
@@ -134,7 +133,9 @@ public function getValue($priceCode = \Magento\Catalog\Pricing\Price\BasePrice::
134133
public function getCustomAmount($amount = null, $exclude = null, $context = [])
135134
{
136135
if (null !== $amount) {
137-
$amount = $this->priceCurrency->convertAndRound($amount);
136+
$amount = (isset($context['should_not_be_converted']) && $context['should_not_be_converted'])
137+
? $this->priceCurrency->roundPrice($amount)
138+
: $this->priceCurrency->convertAndRound($amount);
138139
} else {
139140
$amount = $this->getValue();
140141
}
@@ -163,19 +164,6 @@ public function getCustomOptionRange($getMin, $priceCode = \Magento\Catalog\Pric
163164
return $this->priceCurrency->convertAndRound($optionValue);
164165
}
165166

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-
179167
/**
180168
* Return price for select custom options
181169
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="StorefrontAssertCustomOptionCheckboxByPriceActionGroup">
12+
<annotations>
13+
<description>Validates that the provided price for Custom Option Checkbox is present on the Storefront Product page.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="optionTitle" type="string" defaultValue="{{ProductOptionCheckbox.title}}"/>
17+
<argument name="price" type="string"/>
18+
</arguments>
19+
20+
<seeElement selector="{{StorefrontProductInfoMainSection.productAttributeOptionsCheckbox(optionTitle, price)}}" stepKey="checkPriceProductOptionCheckbox"/>
21+
</actionGroup>
22+
</actionGroups>

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@
3838
<actionGroup ref="StorefrontOpenProductEntityPageActionGroup" stepKey="openProductPageOnStorefront">
3939
<argument name="product" value="$createProduct$"/>
4040
</actionGroup>
41-
<seeElement selector="{{StorefrontProductInfoMainSection.productAttributeOptionsCheckbox(ProductOptionCheckbox.title, '12.3')}}" stepKey="checkPriceProductOptionUSD"/>
41+
<actionGroup ref="StorefrontAssertCustomOptionCheckboxByPriceActionGroup" stepKey="checkPriceProductOptionUSD">
42+
<argument name="price" value="12.3"/>
43+
</actionGroup>
4244
<actionGroup ref="StorefrontSwitchCurrencyActionGroup" stepKey="switchEURCurrency">
4345
<argument name="currency" value="EUR"/>
4446
</actionGroup>
45-
<seeElement selector="{{StorefrontProductInfoMainSection.productAttributeOptionsCheckbox(ProductOptionCheckbox.title, '8.7')}}" stepKey="checkPriceProductOptionEUR"/>
47+
<actionGroup ref="StorefrontAssertCustomOptionCheckboxByPriceActionGroup" stepKey="checkPriceProductOptionEUR">
48+
<argument name="price" value="8.7"/>
49+
</actionGroup>
4650
</test>
4751
</tests>

0 commit comments

Comments
 (0)