Skip to content

Commit 1527713

Browse files
committed
MAGETWO-60283: Prices of configurable product are incorrectly recalculated when display currency is changed
1 parent 8bde202 commit 1527713

File tree

7 files changed

+137
-18
lines changed

7 files changed

+137
-18
lines changed

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

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use Magento\Catalog\Api\ProductRepositoryInterface;
99
use Magento\Catalog\Model\Category;
10-
use Magento\Catalog\Model\Product;
1110

1211
/**
1312
* Product View block
@@ -225,40 +224,34 @@ public function getJsonConfig()
225224
$config = [
226225
'productId' => $product->getId(),
227226
'priceFormat' => $this->_localeFormat->getPriceFormat()
228-
];
227+
];
229228
return $this->_jsonEncoder->encode($config);
230229
}
231230

232231
$tierPrices = [];
233232
$tierPricesList = $product->getPriceInfo()->getPrice('tier_price')->getTierPriceList();
234233
foreach ($tierPricesList as $tierPrice) {
235-
$tierPrices[] = $this->priceCurrency->convert($tierPrice['price']->getValue());
234+
$tierPrices[] = $tierPrice['price']->getValue();
236235
}
237236
$config = [
238-
'productId' => $product->getId(),
237+
'productId' => $product->getId(),
239238
'priceFormat' => $this->_localeFormat->getPriceFormat(),
240-
'prices' => [
241-
'oldPrice' => [
242-
'amount' => $this->priceCurrency->convert(
243-
$product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue()
244-
),
239+
'prices' => [
240+
'oldPrice' => [
241+
'amount' => $product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(),
245242
'adjustments' => []
246243
],
247-
'basePrice' => [
248-
'amount' => $this->priceCurrency->convert(
249-
$product->getPriceInfo()->getPrice('final_price')->getAmount()->getBaseAmount()
250-
),
244+
'basePrice' => [
245+
'amount' => $product->getPriceInfo()->getPrice('final_price')->getAmount()->getBaseAmount(),
251246
'adjustments' => []
252247
],
253248
'finalPrice' => [
254-
'amount' => $this->priceCurrency->convert(
255-
$product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue()
256-
),
249+
'amount' => $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(),
257250
'adjustments' => []
258251
]
259252
],
260-
'idSuffix' => '_clone',
261-
'tierPrices' => $tierPrices
253+
'idSuffix' => '_clone',
254+
'tierPrices' => $tierPrices
262255
];
263256

264257
$responseObject = new \Magento\Framework\DataObject();

dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/Product/CustomOptions.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,5 +358,22 @@
358358
</item>
359359
</field>
360360
</dataset>
361+
362+
<dataset name="not_required_text_option">
363+
<field name="0" xsi:type="array">
364+
<item name="title" xsi:type="string">Test1 option %isolation%</item>
365+
<item name="is_require" xsi:type="string">No</item>
366+
<item name="type" xsi:type="string">Text/Field</item>
367+
<item name="options" xsi:type="array">
368+
<item name="0" xsi:type="array">
369+
<item name="price" xsi:type="string">10</item>
370+
<item name="price_type" xsi:type="string">Fixed</item>
371+
<item name="sku" xsi:type="string">sku1_%isolation%</item>
372+
<item name="max_characters" xsi:type="string">45</item>
373+
</item>
374+
</item>
375+
</field>
376+
</dataset>
377+
361378
</repository>
362379
</config>

dev/tests/functional/tests/app/Magento/CurrencySymbol/Test/Repository/ConfigData.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@
4848
<item name="US Dollar" xsi:type="string">USD</item>
4949
</item>
5050
</field>
51+
<field name="currency/options/base" xsi:type="array">
52+
<item name="scope" xsi:type="string">currency</item>
53+
<item name="label" xsi:type="string">US Dollar</item>
54+
<item name="scope_id" xsi:type="number">1</item>
55+
<item name="value" xsi:type="string">USD</item>
56+
</field>
57+
<field name="currency/options/default" xsi:type="array">
58+
<item name="scope" xsi:type="string">currency</item>
59+
<item name="label" xsi:type="string">US Dollar</item>
60+
<item name="scope_id" xsi:type="number">1</item>
61+
<item name="value" xsi:type="string">USD</item>
62+
</field>
5163
</dataset>
5264

5365
<dataset name="config_base_currency_ch">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Directory\Test\Constraint;
8+
9+
use Magento\Catalog\Test\Page\Product\CatalogProductView;
10+
use Magento\Mtf\Client\BrowserInterface;
11+
use Magento\Mtf\Constraint\AbstractConstraint;
12+
use Magento\Mtf\Fixture\InjectableFixture;
13+
14+
/**
15+
* Assert currency rate applied on product page.
16+
*/
17+
class AssertCurrencyRateAppliedOnProductPage extends AbstractConstraint
18+
{
19+
/**
20+
* Assert currency rate applied on product page.
21+
*
22+
* @param BrowserInterface $browser
23+
* @param InjectableFixture $product
24+
* @param CatalogProductView $view
25+
* @param string $basePrice
26+
*/
27+
public function processAssert(
28+
BrowserInterface $browser,
29+
InjectableFixture $product,
30+
CatalogProductView $view,
31+
$basePrice
32+
) {
33+
$browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
34+
35+
\PHPUnit_Framework_Assert::assertEquals(
36+
$basePrice,
37+
$view->getViewBlock()->getPriceBlock()->getPrice(''),
38+
'Wrong price is displayed on Product page.'
39+
);
40+
}
41+
42+
/**
43+
* Returns a string representation of successful assertion.
44+
*
45+
* @return string
46+
*/
47+
public function toString()
48+
{
49+
return "Currency rate has been applied correctly on Product page.";
50+
}
51+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/Magento/Mtf/Repository/etc/repository.xsd">
9+
<repository class="Magento\Config\Test\Repository\ConfigData">
10+
<dataset name="config_base_currency_us_display_currency_uah">
11+
<field name="currency/options/allow" xsi:type="array">
12+
<item name="scope" xsi:type="string">currency</item>
13+
<item name="scope_id" xsi:type="number">1</item>
14+
<item name="value" xsi:type="array">
15+
<item name="Ukrainian Hryvnia" xsi:type="string">UAH</item>
16+
</item>
17+
</field>
18+
<field name="currency/options/base" xsi:type="array">
19+
<item name="scope" xsi:type="string">currency</item>
20+
<item name="label" xsi:type="string">US Dollar</item>
21+
<item name="scope_id" xsi:type="number">1</item>
22+
<item name="value" xsi:type="string">USD</item>
23+
</field>
24+
<field name="currency/options/default" xsi:type="array">
25+
<item name="scope" xsi:type="string">currency</item>
26+
<item name="label" xsi:type="string">Ukrainian Hryvnia</item>
27+
<item name="scope_id" xsi:type="number">1</item>
28+
<item name="value" xsi:type="string">UAH</item>
29+
</field>
30+
</dataset>
31+
</repository>
32+
</config>

dev/tests/functional/tests/app/Magento/Directory/Test/TestCase/CreateCurrencyRateTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function test(CurrencyRate $currencyRate, CatalogProductSimple $product,
6868

6969
// Steps:
7070
$this->currencyIndexPage->open();
71+
$this->currencyIndexPage->getCurrencyRateForm()->clickImportButton();
7172
$this->currencyIndexPage->getCurrencyRateForm()->fill($currencyRate);
7273
$this->currencyIndexPage->getFormPageActions()->save();
7374
}

dev/tests/functional/tests/app/Magento/Directory/Test/TestCase/CreateCurrencyRateTest.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,18 @@
2020
<constraint name="Magento\Directory\Test\Constraint\AssertCurrencyRateSuccessSaveMessage" />
2121
<constraint name="Magento\Directory\Test\Constraint\AssertCurrencyRateAppliedOnCatalogPage" />
2222
</variation>
23+
<variation name="CreateCurrencyRateTestVariation2">
24+
<data name="currencyRate/data/currency_from" xsi:type="string">USD</data>
25+
<data name="currencyRate/data/currency_to" xsi:type="string">UAH</data>
26+
<data name="currencyRate/data/rate" xsi:type="number">2.000</data>
27+
<data name="currencySymbol/dataSet" xsi:type="string">currency_symbols_uah</data>
28+
<data name="product/dataset" xsi:type="string">simple_10_dollar</data>
29+
<data name="product/data/custom_options/dataset" xsi:type="string">not_required_text_option</data>
30+
<data name="config/dataset" xsi:type="string">config_base_currency_us_display_currency_uah</data>
31+
<data name="basePrice" xsi:type="string">₴20.00</data>
32+
<data name="tag" xsi:type="string">test_type:acceptance_test</data>
33+
<constraint name="Magento\Directory\Test\Constraint\AssertCurrencyRateSuccessSaveMessage" />
34+
<constraint name="Magento\Directory\Test\Constraint\AssertCurrencyRateAppliedOnProductPage" />
35+
</variation>
2336
</testCase>
2437
</config>

0 commit comments

Comments
 (0)