Skip to content

Commit 5bc3136

Browse files
committed
MCP-288: [Load Cart Section] Replace Zend_Currency component with Intl NumberFormatter
- Fix custom currency symbol display;
1 parent dd7bb8c commit 5bc3136

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ private function formatCurrency(string $price, array $options): string
401401
'currency_display_options_forming',
402402
['currency_options' => $customerOptions, 'base_code' => $this->getCode()]
403403
);
404-
$options = array_merge($options, $customerOptions->toArray());
404+
$options += $customerOptions->toArray();
405405

406406
$this->numberFormatter = $this->numberFormatterFactory->create(
407407
['locale' => $this->localeResolver->getLocale(), 'style' => \NumberFormatter::CURRENCY]
@@ -413,8 +413,9 @@ private function formatCurrency(string $price, array $options): string
413413
$price, $this->getCode() ?? $this->numberFormatter->getTextAttribute(\NumberFormatter::CURRENCY_CODE)
414414
);
415415

416-
if (array_key_exists(LocaleCurrency::CURRENCY_OPTION_DISPLAY, $options)
417-
&& $options[LocaleCurrency::CURRENCY_OPTION_DISPLAY] === \Magento\Framework\Currency::NO_SYMBOL) {
416+
if ((array_key_exists(LocaleCurrency::CURRENCY_OPTION_DISPLAY, $options)
417+
&& $options[LocaleCurrency::CURRENCY_OPTION_DISPLAY] === \Magento\Framework\Currency::NO_SYMBOL)
418+
|| array_key_exists(LocaleCurrency::CURRENCY_OPTION_SYMBOL, $options)) {
418419
$formattedCurrency = str_replace(' ', '', $formattedCurrency);
419420
}
420421

@@ -429,18 +430,18 @@ private function formatCurrency(string $price, array $options): string
429430
*/
430431
private function setOptions(array $options): void
431432
{
433+
if (array_key_exists(LocaleCurrency::CURRENCY_OPTION_SYMBOL, $options)) {
434+
$this->numberFormatter->setSymbol(
435+
\NumberFormatter::CURRENCY_SYMBOL, $options[LocaleCurrency::CURRENCY_OPTION_SYMBOL]
436+
);
437+
}
432438
if (array_key_exists(LocaleCurrency::CURRENCY_OPTION_DISPLAY, $options)
433439
&& $options[LocaleCurrency::CURRENCY_OPTION_DISPLAY] === \Magento\Framework\Currency::NO_SYMBOL) {
434440
$this->numberFormatter->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, '');
435441
}
436442
if (array_key_exists('precision', $options)) {
437443
$this->numberFormatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $options['precision']);
438444
}
439-
if (array_key_exists(LocaleCurrency::CURRENCY_OPTION_SYMBOL, $options)) {
440-
$this->numberFormatter->setSymbol(
441-
\NumberFormatter::CURRENCY_SYMBOL, $options[LocaleCurrency::CURRENCY_OPTION_SYMBOL]
442-
);
443-
}
444445
}
445446

446447
/**

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,14 @@ 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', ['precision' => 1], 'en_US', '$9,999.0']
156+
['9999', ['precision' => 1], 'en_US', '$9,999.0'],
157+
['9999', ['precision' => 2, 'symbol' => '#'], 'en_US', '#9,999.00'],
158+
[
159+
'9999.99',
160+
['precision' => 2, 'symbol' => '#', 'display' => \Magento\Framework\Currency::NO_SYMBOL],
161+
'en_US',
162+
'9,999.99'
163+
],
157164
];
158165
}
159166

0 commit comments

Comments
 (0)