Skip to content

Commit 3001fc9

Browse files
committed
MCP-288: [Load Cart Section] Replace Zend_Currency component with Intl NumberFormatter
- Remove nbsp for no symbol currency; - Fix unit test;
1 parent 1ac65dc commit 3001fc9

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ private function formatCurrency(string $price, array $options): string
419419
$formattedCurrency = preg_replace('/ /u', '', $formattedCurrency, 1);
420420
}
421421

422+
if ((array_key_exists(LocaleCurrency::CURRENCY_OPTION_DISPLAY, $options)
423+
&& $options[LocaleCurrency::CURRENCY_OPTION_DISPLAY] === \Magento\Framework\Currency::NO_SYMBOL)) {
424+
$formattedCurrency = str_replace(' ', '', $formattedCurrency);
425+
}
426+
422427
return preg_replace('/^\s+|\s+$/u', '', $formattedCurrency);
423428
}
424429

app/code/Magento/Directory/Test/Unit/Model/CurrencyTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function testGetOutputFormat($expected, $locale): void
9696
$this->numberFormatterFactory
9797
->method('create')
9898
->with(['locale' => $locale, 'style' => 2])
99-
->willReturn(new \NumberFormatter($locale, 2));
99+
->willReturn(new \Magento\Framework\NumberFormatter($locale, 2));
100100
self::assertEquals($expected, $this->currency->getOutputFormat());
101101
}
102102

@@ -132,12 +132,12 @@ public function testFormatTxtWithNumberFormatter(
132132
string $locale,
133133
string $expected
134134
): void {
135-
$this->localeResolver->expects(self::once())->method('getLocale')->willReturn($locale);
135+
$this->localeResolver->expects(self::exactly(2))->method('getLocale')->willReturn($locale);
136136
$this->numberFormatterFactory
137137
->expects(self::once())
138138
->method('create')
139139
->with(['locale' => $locale, 'style' => 2])
140-
->willReturn(new \NumberFormatter($locale, 2));
140+
->willReturn(new \Magento\Framework\NumberFormatter($locale, 2));
141141

142142
self::assertEquals($expected, $this->currency->formatTxt($price, $options));
143143
}
@@ -153,6 +153,7 @@ public function getFormatTxtNumberFormatterDataProvider(): array
153153
['9999', [], 'en_US', '$9,999.00'],
154154
['9999', ['display' => \Magento\Framework\Currency::NO_SYMBOL, 'precision' => 2], 'en_US', '9,999.00'],
155155
['9999', ['display' => \Magento\Framework\Currency::NO_SYMBOL], 'en_US', '9,999.00'],
156+
[' 9999', ['display' => \Magento\Framework\Currency::NO_SYMBOL], 'en_US', '9,999.00'],
156157
['9999', ['precision' => 1], 'en_US', '$9,999.0'],
157158
['9999', ['precision' => 2, 'symbol' => '#'], 'en_US', '#9,999.00'],
158159
[

0 commit comments

Comments
 (0)