Skip to content

Commit 58ade46

Browse files
committed
MCP-288: [Load Cart Section] Replace Zend_Currency component with Intl NumberFormatter
- Fix static, functional & integration tests;
1 parent 8bc822e commit 58ade46

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

app/code/Magento/Directory/Model/Currency.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Directory\Model\Currency\Filter;
1212
use Magento\Framework\Locale\Currency as LocaleCurrency;
1313
use Magento\Framework\Locale\ResolverInterface as LocalResolverInterface;
14+
use Magento\Framework\NumberFormatterFactory;
1415

1516
/**
1617
* Currency model
@@ -79,7 +80,7 @@ class Currency extends \Magento\Framework\Model\AbstractModel
7980
private $localeResolver;
8081

8182
/**
82-
* @var \Magento\Framework\NumberFormatterFactory
83+
* @var NumberFormatterFactory
8384
*/
8485
private $numberFormatterFactory;
8586

@@ -101,7 +102,7 @@ class Currency extends \Magento\Framework\Model\AbstractModel
101102
* @param array $data
102103
* @param CurrencyConfig|null $currencyConfig
103104
* @param LocalResolverInterface|null $localeResolver
104-
* @param \Magento\Framework\NumberFormatterFactory|null $numberFormatterFactory
105+
* @param NumberFormatterFactory|null $numberFormatterFactory
105106
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
106107
*/
107108
public function __construct(
@@ -133,7 +134,7 @@ public function __construct(
133134
$this->_localeCurrency = $localeCurrency;
134135
$this->currencyConfig = $currencyConfig ?: ObjectManager::getInstance()->get(CurrencyConfig::class);
135136
$this->localeResolver = $localeResolver ?: ObjectManager::getInstance()->get(LocalResolverInterface::class);
136-
$this->numberFormatterFactory = $numberFormatterFactory ?: ObjectManager::getInstance()->get(\Magento\Framework\NumberFormatterFactory::class);
137+
$this->numberFormatterFactory = $numberFormatterFactory ?: ObjectManager::getInstance()->get(NumberFormatterFactory::class);
137138
}
138139

139140
/**

dev/tests/integration/testsuite/Magento/Catalog/Block/Product/View/MultiStoreCurrencyTest.php

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

88
namespace Magento\Catalog\Block\Product\View;
99

10+
use Magento\Framework\Locale\ResolverInterface;
1011
use Magento\Store\Model\StoreManagerInterface;
1112

1213
/**
@@ -20,13 +21,17 @@ class MultiStoreCurrencyTest extends AbstractCurrencyTest
2021
/** @var StoreManagerInterface */
2122
private $storeManager;
2223

24+
/** @var ResolverInterface */
25+
private $localeResolver;
26+
2327
/**
2428
* @inheritdoc
2529
*/
2630
protected function setUp(): void
2731
{
2832
parent::setUp();
2933

34+
$this->localeResolver = $this->objectManager->get(ResolverInterface::class);
3035
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
3136
}
3237

@@ -46,9 +51,12 @@ protected function setUp(): void
4651
*/
4752
public function testMultiStoreRenderPrice(): void
4853
{
49-
$this->assertProductStorePrice('simple2', 'CN¥70.00');
54+
$this->localeResolver->setLocale('zh_CN');
55+
$this->assertProductStorePrice('simple2', '¥70.00');
56+
5057
$this->reloadProductPriceInfo();
51-
$this->assertProductStorePrice('simple2', '₴240.00', 'fixturestore');
58+
$this->localeResolver->setLocale('uk_UA');
59+
$this->assertProductStorePrice('simple2', '240,00 ₴', 'fixturestore');
5260
}
5361

5462
/**
@@ -67,9 +75,12 @@ public function testMultiStoreRenderPrice(): void
6775
*/
6876
public function testMultiStoreRenderSpecialPrice(): void
6977
{
70-
$this->assertProductStorePrice('simple', 'Special Price CN¥41.93 Regular Price CN¥70.00');
78+
$this->localeResolver->setLocale('zh_CN');
79+
$this->assertProductStorePrice('simple', 'Special Price ¥41.93 Regular Price ¥70.00');
80+
7181
$this->reloadProductPriceInfo();
72-
$this->assertProductStorePrice('simple', 'Special Price ₴143.76 Regular Price ₴240.00', 'fixturestore');
82+
$this->localeResolver->setLocale('uk_UA');
83+
$this->assertProductStorePrice('simple', 'Special Price 143,76 ₴ Regular Price 240,00 ₴', 'fixturestore');
7384
}
7485

7586
/**
@@ -88,16 +99,19 @@ public function testMultiStoreRenderSpecialPrice(): void
8899
*/
89100
public function testMultiStoreRenderTierPrice(): void
90101
{
102+
$this->localeResolver->setLocale('zh_CN');
91103
$this->assertProductStorePrice(
92104
'simple-product-tax-none',
93-
'Buy 2 for CN¥280.00 each and save 80%',
105+
'Buy 2 for 280.00 each and save 80%',
94106
'default',
95107
self::TIER_PRICE_BLOCK_NAME
96108
);
109+
97110
$this->reloadProductPriceInfo();
111+
$this->localeResolver->setLocale('uk_UA');
98112
$this->assertProductStorePrice(
99113
'simple-product-tax-none',
100-
'Buy 2 for 960.00 each and save 80%',
114+
'Buy 2 for 960,00 ₴ each and save 80%',
101115
'fixturestore',
102116
self::TIER_PRICE_BLOCK_NAME
103117
);
@@ -125,7 +139,7 @@ private function assertProductStorePrice(
125139
}
126140

127141
$actualData = $this->processPriceView($productSku, $priceBlockName);
128-
$this->assertEquals($expectedData, $actualData);
142+
self::assertEquals($expectedData, $actualData);
129143
} finally {
130144
if ($currentStore->getCode() !== $storeCode) {
131145
$this->storeManager->setCurrentStore($currentStore);
@@ -141,7 +155,16 @@ private function assertProductStorePrice(
141155
private function reloadProductPriceInfo(): void
142156
{
143157
$product = $this->registry->registry('product');
144-
$this->assertNotNull($product);
158+
self::assertNotNull($product);
145159
$product->reloadPriceInfo();
146160
}
161+
162+
/**
163+
* @inheritDoc
164+
*/
165+
protected function tearDown(): void
166+
{
167+
$this->localeResolver->setLocale(\Magento\Setup\Module\I18n\Locale::DEFAULT_SYSTEM_LOCALE);
168+
parent::tearDown();
169+
}
147170
}

0 commit comments

Comments
 (0)