Skip to content

Commit 6449686

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

File tree

8 files changed

+155
-13
lines changed

8 files changed

+155
-13
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class View extends AbstractProduct implements \Magento\Framework\DataObject\Iden
2828

2929
/**
3030
* @var \Magento\Framework\Pricing\PriceCurrencyInterface
31+
* @deprecated
3132
*/
3233
protected $priceCurrency;
3334

app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ public function __construct(
9292
);
9393
}
9494

95+
/**
96+
* Get cache key informative items.
97+
*
98+
* @return array
99+
*/
100+
public function getCacheKeyInfo()
101+
{
102+
$parentData = parent::getCacheKeyInfo();
103+
$parentData[] = $this->priceCurrency->getCurrencySymbol();
104+
return $parentData;
105+
}
106+
95107
/**
96108
* Get allowed attributes
97109
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\ConfigurableProduct\Test\Constraint;
8+
9+
use Magento\Catalog\Test\Page\Product\CatalogProductView;
10+
use Magento\Cms\Test\Page\CmsIndex;
11+
use Magento\CurrencySymbol\Test\Fixture\CurrencySymbolEntity;
12+
use Magento\Mtf\Client\BrowserInterface;
13+
use Magento\Mtf\Constraint\AbstractConstraint;
14+
use Magento\Mtf\Fixture\InjectableFixture;
15+
16+
/**
17+
* Assert currency rate applied on configurable product page.
18+
*/
19+
class AssertCurrencyRateAppliedOnProductPage extends AbstractConstraint
20+
{
21+
/**
22+
* Assert currency rate applied on configurable product page.
23+
*
24+
* @param BrowserInterface $browser
25+
* @param InjectableFixture $product
26+
* @param CatalogProductView $view
27+
* @param CmsIndex $cmsIndex
28+
* @param CurrencySymbolEntity $baseCurrency
29+
* @param array $configuredPrices
30+
* @param string $basePrice
31+
*/
32+
public function processAssert(
33+
BrowserInterface $browser,
34+
InjectableFixture $product,
35+
CatalogProductView $view,
36+
CmsIndex $cmsIndex,
37+
CurrencySymbolEntity $baseCurrency,
38+
array $configuredPrices,
39+
$basePrice
40+
) {
41+
$browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
42+
$this->assertPrice($view, $basePrice);
43+
44+
$view->getViewBlock()->configure($product);
45+
$this->assertPrice($view, $configuredPrices['custom_currency']);
46+
47+
$cmsIndex->getCurrencyBlock()->switchCurrency($baseCurrency);
48+
$view->getViewBlock()->configure($product);
49+
$this->assertPrice($view, $configuredPrices['base_currency']);
50+
}
51+
52+
/**
53+
* Assert price.
54+
*
55+
* @param CatalogProductView $view
56+
* @param string $price
57+
* @param string $currency [optional]
58+
*/
59+
public function assertPrice(CatalogProductView $view, $price, $currency = '') {
60+
\PHPUnit_Framework_Assert::assertEquals(
61+
$price,
62+
$view->getViewBlock()->getPriceBlock()->getPrice($currency),
63+
'Wrong price is displayed on Product page.'
64+
);
65+
}
66+
67+
/**
68+
* Returns a string representation of successful assertion.
69+
*
70+
* @return string
71+
*/
72+
public function toString()
73+
{
74+
return "Currency rate has been applied correctly on Configurable Product page.";
75+
}
76+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
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/etc/variations.xsd">
9+
<testCase name="Magento\Directory\Test\TestCase\CreateCurrencyRateTest" summary="Create Currency Rate" ticketId="MAGETWO-36824">
10+
<variation name="CreateCurrencyRateTestVariation3">
11+
<data name="currencyRate/data/currency_from" xsi:type="string">USD</data>
12+
<data name="currencyRate/data/currency_to" xsi:type="string">UAH</data>
13+
<data name="currencyRate/data/rate" xsi:type="number">2.000</data>
14+
<data name="currencySymbol/dataSet" xsi:type="string">currency_symbols_uah</data>
15+
<data name="product" xsi:type="string">configurableProduct::default</data>
16+
<data name="config/dataset" xsi:type="string">config_base_currency_us_display_currency_uah</data>
17+
<data name="baseCurrency/data/code" xsi:type="string">USD</data>
18+
<data name="basePrice" xsi:type="string">₴80.00</data>
19+
<data name="configuredPrices" xsi:type="array">
20+
<item name="custom_currency" xsi:type="string">₴80.00</item>
21+
<item name="base_currency" xsi:type="string">$40.00</item>
22+
</data>
23+
<data name="tag" xsi:type="string">test_type:acceptance_test</data>
24+
<constraint name="Magento\Directory\Test\Constraint\AssertCurrencyRateSuccessSaveMessage" />
25+
<constraint name="Magento\ConfigurableProduct\Test\Constraint\AssertCurrencyRateAppliedOnProductPage" />
26+
</variation>
27+
</testCase>
28+
</config>

dev/tests/functional/tests/app/Magento/Directory/Test/Constraint/AssertCurrencyRateAppliedOnProductPage.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,20 @@ public function processAssert(
3131
$basePrice
3232
) {
3333
$browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
34+
$this->assertPrice($view, $basePrice);
35+
}
3436

37+
/**
38+
* Assert price.
39+
*
40+
* @param CatalogProductView $view
41+
* @param string $price
42+
* @param string $currency [optional]
43+
*/
44+
public function assertPrice(CatalogProductView $view, $price, $currency = '') {
3545
\PHPUnit_Framework_Assert::assertEquals(
36-
$basePrice,
37-
$view->getViewBlock()->getPriceBlock()->getPrice(''),
46+
$price,
47+
$view->getViewBlock()->getPriceBlock()->getPrice($currency),
3848
'Wrong price is displayed on Product page.'
3949
);
4050
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<item name="scope_id" xsi:type="number">1</item>
1414
<item name="value" xsi:type="array">
1515
<item name="Ukrainian Hryvnia" xsi:type="string">UAH</item>
16+
<item name="US Dollar" xsi:type="string">USD</item>
1617
</item>
1718
</field>
1819
<field name="currency/options/base" xsi:type="array">

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
namespace Magento\Directory\Test\TestCase;
88

9+
use Magento\Catalog\Test\TestStep\CreateProductsStep;
910
use Magento\Config\Test\Fixture\ConfigData;
1011
use Magento\Mtf\TestCase\Injectable;
1112
use Magento\Directory\Test\Fixture\CurrencyRate;
12-
use Magento\Catalog\Test\Fixture\CatalogProductSimple;
1313
use Magento\CurrencySymbol\Test\Page\Adminhtml\SystemCurrencyIndex;
14+
use Magento\Mtf\TestStep\TestStepFactory;
1415

1516
/**
1617
* Preconditions:
@@ -41,36 +42,49 @@ class CreateCurrencyRateTest extends Injectable
4142
*/
4243
protected $currencyIndexPage;
4344

45+
/**
46+
* Test step factory.
47+
*
48+
* @var TestStepFactory
49+
*/
50+
private $stepFactory;
51+
4452
/**
4553
* Inject data.
4654
*
4755
* @param SystemCurrencyIndex $currencyIndexPage
48-
* @return void
56+
* @param TestStepFactory $stepFactory
4957
*/
50-
public function __inject(SystemCurrencyIndex $currencyIndexPage)
58+
public function __inject(SystemCurrencyIndex $currencyIndexPage, TestStepFactory $stepFactory)
5159
{
5260
$this->currencyIndexPage = $currencyIndexPage;
61+
$this->stepFactory = $stepFactory;
5362
}
5463

5564
/**
5665
* Create currency rate test.
5766
*
5867
* @param CurrencyRate $currencyRate
59-
* @param CatalogProductSimple $product
60-
* @param $config
61-
* @return void
68+
* @param ConfigData $config
69+
* @param string $product
70+
* @param array $productData [optional]
71+
* @return array
6272
*/
63-
public function test(CurrencyRate $currencyRate, CatalogProductSimple $product, ConfigData $config)
73+
public function test(CurrencyRate $currencyRate, ConfigData $config, $product, array $productData = [])
6474
{
6575
// Preconditions:
66-
$product->persist();
76+
$product = $this->stepFactory
77+
->create(CreateProductsStep::class, ['products' => [$product], 'data' => $productData])
78+
->run()['products'][0];
6779
$config->persist();
6880

6981
// Steps:
7082
$this->currencyIndexPage->open();
7183
$this->currencyIndexPage->getCurrencyRateForm()->clickImportButton();
7284
$this->currencyIndexPage->getCurrencyRateForm()->fill($currencyRate);
7385
$this->currencyIndexPage->getFormPageActions()->save();
86+
87+
return ['product' => $product];
7488
}
7589

7690
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<data name="currencyRate/data/currency_to" xsi:type="string">EUR</data>
1414
<data name="currencyRate/data/rate" xsi:type="number">0.8</data>
1515
<data name="currencySymbol/dataset" xsi:type="string">currency_symbols_eur</data>
16-
<data name="product/dataset" xsi:type="string">simple_10_dollar</data>
16+
<data name="product" xsi:type="string">catalogProductSimple::simple_10_dollar</data>
1717
<data name="config/dataset" xsi:type="string">config_currency_symbols_usd_and_eur</data>
1818
<data name="basePrice" xsi:type="string">$10.00</data>
1919
<data name="convertedPrice" xsi:type="string">€8.00</data>
@@ -25,8 +25,8 @@
2525
<data name="currencyRate/data/currency_to" xsi:type="string">UAH</data>
2626
<data name="currencyRate/data/rate" xsi:type="number">2.000</data>
2727
<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>
28+
<data name="product" xsi:type="string">catalogProductSimple::simple_10_dollar</data>
29+
<data name="productData/0/custom_options/dataset" xsi:type="string">not_required_text_option</data>
3030
<data name="config/dataset" xsi:type="string">config_base_currency_us_display_currency_uah</data>
3131
<data name="basePrice" xsi:type="string">₴20.00</data>
3232
<data name="tag" xsi:type="string">test_type:acceptance_test</data>

0 commit comments

Comments
 (0)