Skip to content

Commit

Permalink
MAGETWO-60283: Prices of configurable product are incorrectly recalcu…
Browse files Browse the repository at this point in the history
…lated when display currency is changed
  • Loading branch information
vgoncharenko committed Nov 1, 2016
1 parent 8bde202 commit 1527713
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 18 deletions.
29 changes: 11 additions & 18 deletions app/code/Magento/Catalog/Block/Product/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\Product;

/**
* Product View block
Expand Down Expand Up @@ -225,40 +224,34 @@ public function getJsonConfig()
$config = [
'productId' => $product->getId(),
'priceFormat' => $this->_localeFormat->getPriceFormat()
];
];
return $this->_jsonEncoder->encode($config);
}

$tierPrices = [];
$tierPricesList = $product->getPriceInfo()->getPrice('tier_price')->getTierPriceList();
foreach ($tierPricesList as $tierPrice) {
$tierPrices[] = $this->priceCurrency->convert($tierPrice['price']->getValue());
$tierPrices[] = $tierPrice['price']->getValue();
}
$config = [
'productId' => $product->getId(),
'productId' => $product->getId(),
'priceFormat' => $this->_localeFormat->getPriceFormat(),
'prices' => [
'oldPrice' => [
'amount' => $this->priceCurrency->convert(
$product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue()
),
'prices' => [
'oldPrice' => [
'amount' => $product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(),
'adjustments' => []
],
'basePrice' => [
'amount' => $this->priceCurrency->convert(
$product->getPriceInfo()->getPrice('final_price')->getAmount()->getBaseAmount()
),
'basePrice' => [
'amount' => $product->getPriceInfo()->getPrice('final_price')->getAmount()->getBaseAmount(),
'adjustments' => []
],
'finalPrice' => [
'amount' => $this->priceCurrency->convert(
$product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue()
),
'amount' => $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(),
'adjustments' => []
]
],
'idSuffix' => '_clone',
'tierPrices' => $tierPrices
'idSuffix' => '_clone',
'tierPrices' => $tierPrices
];

$responseObject = new \Magento\Framework\DataObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,5 +358,22 @@
</item>
</field>
</dataset>

<dataset name="not_required_text_option">
<field name="0" xsi:type="array">
<item name="title" xsi:type="string">Test1 option %isolation%</item>
<item name="is_require" xsi:type="string">No</item>
<item name="type" xsi:type="string">Text/Field</item>
<item name="options" xsi:type="array">
<item name="0" xsi:type="array">
<item name="price" xsi:type="string">10</item>
<item name="price_type" xsi:type="string">Fixed</item>
<item name="sku" xsi:type="string">sku1_%isolation%</item>
<item name="max_characters" xsi:type="string">45</item>
</item>
</item>
</field>
</dataset>

</repository>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@
<item name="US Dollar" xsi:type="string">USD</item>
</item>
</field>
<field name="currency/options/base" xsi:type="array">
<item name="scope" xsi:type="string">currency</item>
<item name="label" xsi:type="string">US Dollar</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="value" xsi:type="string">USD</item>
</field>
<field name="currency/options/default" xsi:type="array">
<item name="scope" xsi:type="string">currency</item>
<item name="label" xsi:type="string">US Dollar</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="value" xsi:type="string">USD</item>
</field>
</dataset>

<dataset name="config_base_currency_ch">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Directory\Test\Constraint;

use Magento\Catalog\Test\Page\Product\CatalogProductView;
use Magento\Mtf\Client\BrowserInterface;
use Magento\Mtf\Constraint\AbstractConstraint;
use Magento\Mtf\Fixture\InjectableFixture;

/**
* Assert currency rate applied on product page.
*/
class AssertCurrencyRateAppliedOnProductPage extends AbstractConstraint
{
/**
* Assert currency rate applied on product page.
*
* @param BrowserInterface $browser
* @param InjectableFixture $product
* @param CatalogProductView $view
* @param string $basePrice
*/
public function processAssert(
BrowserInterface $browser,
InjectableFixture $product,
CatalogProductView $view,
$basePrice
) {
$browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');

\PHPUnit_Framework_Assert::assertEquals(
$basePrice,
$view->getViewBlock()->getPriceBlock()->getPrice(''),
'Wrong price is displayed on Product page.'
);
}

/**
* Returns a string representation of successful assertion.
*
* @return string
*/
public function toString()
{
return "Currency rate has been applied correctly on Product page.";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/Magento/Mtf/Repository/etc/repository.xsd">
<repository class="Magento\Config\Test\Repository\ConfigData">
<dataset name="config_base_currency_us_display_currency_uah">
<field name="currency/options/allow" xsi:type="array">
<item name="scope" xsi:type="string">currency</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="value" xsi:type="array">
<item name="Ukrainian Hryvnia" xsi:type="string">UAH</item>
</item>
</field>
<field name="currency/options/base" xsi:type="array">
<item name="scope" xsi:type="string">currency</item>
<item name="label" xsi:type="string">US Dollar</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="value" xsi:type="string">USD</item>
</field>
<field name="currency/options/default" xsi:type="array">
<item name="scope" xsi:type="string">currency</item>
<item name="label" xsi:type="string">Ukrainian Hryvnia</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="value" xsi:type="string">UAH</item>
</field>
</dataset>
</repository>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function test(CurrencyRate $currencyRate, CatalogProductSimple $product,

// Steps:
$this->currencyIndexPage->open();
$this->currencyIndexPage->getCurrencyRateForm()->clickImportButton();
$this->currencyIndexPage->getCurrencyRateForm()->fill($currencyRate);
$this->currencyIndexPage->getFormPageActions()->save();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,18 @@
<constraint name="Magento\Directory\Test\Constraint\AssertCurrencyRateSuccessSaveMessage" />
<constraint name="Magento\Directory\Test\Constraint\AssertCurrencyRateAppliedOnCatalogPage" />
</variation>
<variation name="CreateCurrencyRateTestVariation2">
<data name="currencyRate/data/currency_from" xsi:type="string">USD</data>
<data name="currencyRate/data/currency_to" xsi:type="string">UAH</data>
<data name="currencyRate/data/rate" xsi:type="number">2.000</data>
<data name="currencySymbol/dataSet" xsi:type="string">currency_symbols_uah</data>
<data name="product/dataset" xsi:type="string">simple_10_dollar</data>
<data name="product/data/custom_options/dataset" xsi:type="string">not_required_text_option</data>
<data name="config/dataset" xsi:type="string">config_base_currency_us_display_currency_uah</data>
<data name="basePrice" xsi:type="string">₴20.00</data>
<data name="tag" xsi:type="string">test_type:acceptance_test</data>
<constraint name="Magento\Directory\Test\Constraint\AssertCurrencyRateSuccessSaveMessage" />
<constraint name="Magento\Directory\Test\Constraint\AssertCurrencyRateAppliedOnProductPage" />
</variation>
</testCase>
</config>

0 comments on commit 1527713

Please sign in to comment.