Skip to content

Commit 6e41d20

Browse files
committed
MC-30626: Custom Option with Percent price is converted to a currency twice
1 parent 6bc8dc4 commit 6e41d20

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
namespace Magento\Catalog\Block\Product\View\Options;
1414

15-
use Magento\Catalog\Pricing\Price\BasePrice;
1615
use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule;
1716
use Magento\Catalog\Pricing\Price\CustomOptionPriceInterface;
1817
use Magento\Framework\App\ObjectManager;
18+
use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
1919

2020
/**
2121
* Product options section abstract block.
@@ -55,24 +55,33 @@ abstract class AbstractOptions extends \Magento\Framework\View\Element\Template
5555
*/
5656
private $calculateCustomOptionCatalogRule;
5757

58+
/**
59+
* @var CalculatorInterface
60+
*/
61+
protected $calculator;
62+
5863
/**
5964
* @param \Magento\Framework\View\Element\Template\Context $context
6065
* @param \Magento\Framework\Pricing\Helper\Data $pricingHelper
6166
* @param \Magento\Catalog\Helper\Data $catalogData
6267
* @param array $data
6368
* @param CalculateCustomOptionCatalogRule|null $calculateCustomOptionCatalogRule
69+
* @param CalculatorInterface|null $calculator
6470
*/
6571
public function __construct(
6672
\Magento\Framework\View\Element\Template\Context $context,
6773
\Magento\Framework\Pricing\Helper\Data $pricingHelper,
6874
\Magento\Catalog\Helper\Data $catalogData,
6975
array $data = [],
70-
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null
76+
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null,
77+
CalculatorInterface $calculator = null
7178
) {
7279
$this->pricingHelper = $pricingHelper;
7380
$this->_catalogHelper = $catalogData;
7481
$this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule
7582
?? ObjectManager::getInstance()->get(CalculateCustomOptionCatalogRule::class);
83+
$this->calculator = $calculator
84+
?? ObjectManager::getInstance()->get(CalculatorInterface::class);
7685
parent::__construct($context, $data);
7786
}
7887

@@ -188,7 +197,9 @@ protected function _formatPrice($value, $flag = true)
188197
}
189198

190199
$context = [CustomOptionPriceInterface::CONFIGURATION_OPTION_FLAG => true];
191-
$optionAmount = $customOptionPrice->getCustomAmount($value['pricing_value'], null, $context);
200+
$optionAmount = !$isPercent
201+
? $customOptionPrice->getCustomAmount($value['pricing_value'], null, $context)
202+
: $this->calculator->getAmount($value['pricing_value'], $this->getProduct(), null, $context);
192203
$priceStr .= $this->getLayout()->getBlock('product.price.render.default')->renderAmount(
193204
$optionAmount,
194205
$customOptionPrice,

app/code/Magento/Catalog/Test/Mftf/Data/ProductData.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,10 @@
577577
<var key="sku" entityType="product" entityKey="sku" />
578578
<requiredEntity type="product_option">ProductOptionDropDownWithLongValuesTitle</requiredEntity>
579579
</entity>
580+
<entity name="productWithCheckbox" type="product">
581+
<var key="sku" entityType="product" entityKey="sku" />
582+
<requiredEntity type="product_option">ProductOptionCheckbox</requiredEntity>
583+
</entity>
580584
<entity name="productWithDropdownOption" type="product">
581585
<var key="sku" entityType="product" entityKey="sku" />
582586
<requiredEntity type="product_option">ProductOptionValueDropdown</requiredEntity>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="StorefrontCheckCustomOptionPriceDifferentCurrencyTest">
11+
<annotations>
12+
<features value="Catalog"/>
13+
<stories value="Custom options"/>
14+
<title value="Check custom option price with different currency"/>
15+
<description value="Check custom option price with different currency on the product page"/>
16+
<severity value="CRITICAL"/>
17+
<testCaseId value="MC-38926"/>
18+
<useCaseId value="MC-30626"/>
19+
<group value="catalog"/>
20+
</annotations>
21+
<before>
22+
<magentoCLI command="config:set currency/options/allow EUR,USD" stepKey="setCurrencyAllow"/>
23+
<createData entity="SimpleProduct2" stepKey="createProduct">
24+
<field key="price">10</field>
25+
</createData>
26+
<updateData createDataKey="createProduct" entity="productWithCheckbox" stepKey="updateProductWithOptions"/>
27+
</before>
28+
<after>
29+
<magentoCLI command="config:set currency/options/allow USD" stepKey="setCurrencyAllow"/>
30+
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
31+
</after>
32+
<actionGroup ref="StorefrontOpenProductEntityPageActionGroup" stepKey="openProductPageOnStorefront">
33+
<argument name="product" value="$createProduct$"/>
34+
</actionGroup>
35+
<seeElement selector="{{StorefrontProductInfoMainSection.productAttributeOptionsCheckbox(ProductOptionCheckbox.title, '12.3')}}" stepKey="checkPriceProductOptionUSD"/>
36+
<actionGroup ref="StorefrontSwitchCurrencyActionGroup" stepKey="switchEURCurrency">
37+
<argument name="currency" value="EUR"/>
38+
</actionGroup>
39+
<seeElement selector="{{StorefrontProductInfoMainSection.productAttributeOptionsCheckbox(ProductOptionCheckbox.title, '8.6961')}}" stepKey="checkPriceProductOptionEUR"/>
40+
</test>
41+
</tests>

0 commit comments

Comments
 (0)