Skip to content
Snippets Groups Projects
Commit 4b177e03 authored by Oleksandr Dubovyk's avatar Oleksandr Dubovyk
Browse files

Merge remote-tracking branch 'troll/MAGETWO-60283' into pull-primary

parents 1759088c d2303bd2
Branches
No related merge requests found
Showing
with 289 additions and 27 deletions
...@@ -7,7 +7,6 @@ namespace Magento\Catalog\Block\Product; ...@@ -7,7 +7,6 @@ namespace Magento\Catalog\Block\Product;
use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Category; use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\Product;
/** /**
* Product View block * Product View block
...@@ -29,6 +28,7 @@ class View extends AbstractProduct implements \Magento\Framework\DataObject\Iden ...@@ -29,6 +28,7 @@ class View extends AbstractProduct implements \Magento\Framework\DataObject\Iden
/** /**
* @var \Magento\Framework\Pricing\PriceCurrencyInterface * @var \Magento\Framework\Pricing\PriceCurrencyInterface
* @deprecated
*/ */
protected $priceCurrency; protected $priceCurrency;
...@@ -225,40 +225,34 @@ class View extends AbstractProduct implements \Magento\Framework\DataObject\Iden ...@@ -225,40 +225,34 @@ class View extends AbstractProduct implements \Magento\Framework\DataObject\Iden
$config = [ $config = [
'productId' => $product->getId(), 'productId' => $product->getId(),
'priceFormat' => $this->_localeFormat->getPriceFormat() 'priceFormat' => $this->_localeFormat->getPriceFormat()
]; ];
return $this->_jsonEncoder->encode($config); return $this->_jsonEncoder->encode($config);
} }
$tierPrices = []; $tierPrices = [];
$tierPricesList = $product->getPriceInfo()->getPrice('tier_price')->getTierPriceList(); $tierPricesList = $product->getPriceInfo()->getPrice('tier_price')->getTierPriceList();
foreach ($tierPricesList as $tierPrice) { foreach ($tierPricesList as $tierPrice) {
$tierPrices[] = $this->priceCurrency->convert($tierPrice['price']->getValue()); $tierPrices[] = $tierPrice['price']->getValue();
} }
$config = [ $config = [
'productId' => $product->getId(), 'productId' => $product->getId(),
'priceFormat' => $this->_localeFormat->getPriceFormat(), 'priceFormat' => $this->_localeFormat->getPriceFormat(),
'prices' => [ 'prices' => [
'oldPrice' => [ 'oldPrice' => [
'amount' => $this->priceCurrency->convert( 'amount' => $product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(),
$product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue()
),
'adjustments' => [] 'adjustments' => []
], ],
'basePrice' => [ 'basePrice' => [
'amount' => $this->priceCurrency->convert( 'amount' => $product->getPriceInfo()->getPrice('final_price')->getAmount()->getBaseAmount(),
$product->getPriceInfo()->getPrice('final_price')->getAmount()->getBaseAmount()
),
'adjustments' => [] 'adjustments' => []
], ],
'finalPrice' => [ 'finalPrice' => [
'amount' => $this->priceCurrency->convert( 'amount' => $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(),
$product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue()
),
'adjustments' => [] 'adjustments' => []
] ]
], ],
'idSuffix' => '_clone', 'idSuffix' => '_clone',
'tierPrices' => $tierPrices 'tierPrices' => $tierPrices
]; ];
$responseObject = new \Magento\Framework\DataObject(); $responseObject = new \Magento\Framework\DataObject();
......
...@@ -92,6 +92,18 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView ...@@ -92,6 +92,18 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView
); );
} }
/**
* Get cache key informative items.
*
* @return array
*/
public function getCacheKeyInfo()
{
$parentData = parent::getCacheKeyInfo();
$parentData[] = $this->priceCurrency->getCurrencySymbol();
return $parentData;
}
/** /**
* Get allowed attributes * Get allowed attributes
* *
......
...@@ -358,5 +358,22 @@ ...@@ -358,5 +358,22 @@
</item> </item>
</field> </field>
</dataset> </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> </repository>
</config> </config>
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Test\Constraint;
use Magento\Catalog\Test\Page\Product\CatalogProductView;
use Magento\Cms\Test\Page\CmsIndex;
use Magento\CurrencySymbol\Test\Fixture\CurrencySymbolEntity;
use Magento\Mtf\Client\BrowserInterface;
use Magento\Mtf\Constraint\AbstractConstraint;
use Magento\Mtf\Fixture\InjectableFixture;
/**
* Assert currency rate applied on configurable product page.
*/
class AssertCurrencyRateAppliedOnProductPage extends AbstractConstraint
{
/**
* Assert currency rate applied on configurable product page.
*
* @param BrowserInterface $browser
* @param InjectableFixture $product
* @param CatalogProductView $view
* @param CmsIndex $cmsIndex
* @param CurrencySymbolEntity $baseCurrency
* @param array $configuredPrices
* @param string $basePrice
*/
public function processAssert(
BrowserInterface $browser,
InjectableFixture $product,
CatalogProductView $view,
CmsIndex $cmsIndex,
CurrencySymbolEntity $baseCurrency,
array $configuredPrices,
$basePrice
) {
$browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
$this->assertPrice($view, $basePrice);
$view->getViewBlock()->configure($product);
$this->assertPrice($view, $configuredPrices['custom_currency']);
$cmsIndex->getCurrencyBlock()->switchCurrency($baseCurrency);
$view->getViewBlock()->configure($product);
$this->assertPrice($view, $configuredPrices['base_currency']);
}
/**
* Assert price.
*
* @param CatalogProductView $view
* @param string $price
* @param string $currency [optional]
*/
public function assertPrice(CatalogProductView $view, $price, $currency = '')
{
\PHPUnit_Framework_Assert::assertEquals(
$price,
$view->getViewBlock()->getPriceBlock()->getPrice($currency),
'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 Configurable Product page.";
}
}
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* 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/etc/variations.xsd">
<testCase name="Magento\Directory\Test\TestCase\CreateCurrencyRateTest" summary="Create Currency Rate" ticketId="MAGETWO-36824">
<variation name="CreateCurrencyRateTestVariation3">
<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" xsi:type="string">configurableProduct::default</data>
<data name="config/dataset" xsi:type="string">config_base_currency_us_display_currency_uah</data>
<data name="baseCurrency/data/code" xsi:type="string">USD</data>
<data name="basePrice" xsi:type="string">₴80.00</data>
<data name="configuredPrices" xsi:type="array">
<item name="custom_currency" xsi:type="string">₴80.00</item>
<item name="base_currency" xsi:type="string">$40.00</item>
</data>
<data name="tag" xsi:type="string">test_type:acceptance_test</data>
<constraint name="Magento\Directory\Test\Constraint\AssertCurrencyRateSuccessSaveMessage" />
<constraint name="Magento\ConfigurableProduct\Test\Constraint\AssertCurrencyRateAppliedOnProductPage" />
</variation>
</testCase>
</config>
...@@ -48,6 +48,18 @@ ...@@ -48,6 +48,18 @@
<item name="US Dollar" xsi:type="string">USD</item> <item name="US Dollar" xsi:type="string">USD</item>
</item> </item>
</field> </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>
<dataset name="config_base_currency_ch"> <dataset name="config_base_currency_ch">
......
<?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');
$this->assertPrice($view, $basePrice);
}
/**
* Assert price.
*
* @param CatalogProductView $view
* @param string $price
* @param string $currency [optional]
*/
public function assertPrice(CatalogProductView $view, $price, $currency = '')
{
\PHPUnit_Framework_Assert::assertEquals(
$price,
$view->getViewBlock()->getPriceBlock()->getPrice($currency),
'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.";
}
}
<?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 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">Ukrainian Hryvnia</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="value" xsi:type="string">UAH</item>
</field>
</dataset>
</repository>
</config>
...@@ -6,11 +6,12 @@ ...@@ -6,11 +6,12 @@
namespace Magento\Directory\Test\TestCase; namespace Magento\Directory\Test\TestCase;
use Magento\Catalog\Test\TestStep\CreateProductsStep;
use Magento\Config\Test\Fixture\ConfigData; use Magento\Config\Test\Fixture\ConfigData;
use Magento\Mtf\TestCase\Injectable; use Magento\Mtf\TestCase\Injectable;
use Magento\Directory\Test\Fixture\CurrencyRate; use Magento\Directory\Test\Fixture\CurrencyRate;
use Magento\Catalog\Test\Fixture\CatalogProductSimple;
use Magento\CurrencySymbol\Test\Page\Adminhtml\SystemCurrencyIndex; use Magento\CurrencySymbol\Test\Page\Adminhtml\SystemCurrencyIndex;
use Magento\Mtf\TestStep\TestStepFactory;
/** /**
* Preconditions: * Preconditions:
...@@ -41,35 +42,48 @@ class CreateCurrencyRateTest extends Injectable ...@@ -41,35 +42,48 @@ class CreateCurrencyRateTest extends Injectable
*/ */
protected $currencyIndexPage; protected $currencyIndexPage;
/**
* Test step factory.
*
* @var TestStepFactory
*/
private $stepFactory;
/** /**
* Inject data. * Inject data.
* *
* @param SystemCurrencyIndex $currencyIndexPage * @param SystemCurrencyIndex $currencyIndexPage
* @return void * @param TestStepFactory $stepFactory
*/ */
public function __inject(SystemCurrencyIndex $currencyIndexPage) public function __inject(SystemCurrencyIndex $currencyIndexPage, TestStepFactory $stepFactory)
{ {
$this->currencyIndexPage = $currencyIndexPage; $this->currencyIndexPage = $currencyIndexPage;
$this->stepFactory = $stepFactory;
} }
/** /**
* Create currency rate test. * Create currency rate test.
* *
* @param CurrencyRate $currencyRate * @param CurrencyRate $currencyRate
* @param CatalogProductSimple $product * @param ConfigData $config
* @param $config * @param string $product
* @return void * @param array $productData [optional]
* @return array
*/ */
public function test(CurrencyRate $currencyRate, CatalogProductSimple $product, ConfigData $config) public function test(CurrencyRate $currencyRate, ConfigData $config, $product, array $productData = [])
{ {
// Preconditions: // Preconditions:
$product->persist(); $product = $this->stepFactory
->create(CreateProductsStep::class, ['products' => [$product], 'data' => $productData])
->run()['products'][0];
$config->persist(); $config->persist();
// Steps: // Steps:
$this->currencyIndexPage->open(); $this->currencyIndexPage->open();
$this->currencyIndexPage->getCurrencyRateForm()->fill($currencyRate); $this->currencyIndexPage->getCurrencyRateForm()->fill($currencyRate);
$this->currencyIndexPage->getFormPageActions()->save(); $this->currencyIndexPage->getFormPageActions()->save();
return ['product' => $product];
} }
/** /**
......
...@@ -13,12 +13,25 @@ ...@@ -13,12 +13,25 @@
<data name="currencyRate/data/currency_to" xsi:type="string">EUR</data> <data name="currencyRate/data/currency_to" xsi:type="string">EUR</data>
<data name="currencyRate/data/rate" xsi:type="number">0.8</data> <data name="currencyRate/data/rate" xsi:type="number">0.8</data>
<data name="currencySymbol/dataset" xsi:type="string">currency_symbols_eur</data> <data name="currencySymbol/dataset" xsi:type="string">currency_symbols_eur</data>
<data name="product/dataset" xsi:type="string">simple_10_dollar</data> <data name="product" xsi:type="string">catalogProductSimple::simple_10_dollar</data>
<data name="config/dataset" xsi:type="string">config_currency_symbols_usd_and_eur</data> <data name="config/dataset" xsi:type="string">config_currency_symbols_usd_and_eur</data>
<data name="basePrice" xsi:type="string">$10.00</data> <data name="basePrice" xsi:type="string">$10.00</data>
<data name="convertedPrice" xsi:type="string">€8.00</data> <data name="convertedPrice" xsi:type="string">€8.00</data>
<constraint name="Magento\Directory\Test\Constraint\AssertCurrencyRateSuccessSaveMessage" /> <constraint name="Magento\Directory\Test\Constraint\AssertCurrencyRateSuccessSaveMessage" />
<constraint name="Magento\Directory\Test\Constraint\AssertCurrencyRateAppliedOnCatalogPage" /> <constraint name="Magento\Directory\Test\Constraint\AssertCurrencyRateAppliedOnCatalogPage" />
</variation> </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" xsi:type="string">catalogProductSimple::simple_10_dollar</data>
<data name="productData/0/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> </testCase>
</config> </config>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment