Skip to content

Commit 947418c

Browse files
committed
ACP2E-457: Arabic (Saudi Arabia) locale breaks the product detail page
- fix - modify test
1 parent 54dee2c commit 947418c

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ class Currency extends \Magento\Framework\Model\AbstractModel
2828
/**
2929
* CONFIG path constants
3030
*/
31-
const XML_PATH_CURRENCY_ALLOW = 'currency/options/allow';
31+
public const XML_PATH_CURRENCY_ALLOW = 'currency/options/allow';
3232

33-
const XML_PATH_CURRENCY_DEFAULT = 'currency/options/default';
33+
public const XML_PATH_CURRENCY_DEFAULT = 'currency/options/default';
3434

35-
const XML_PATH_CURRENCY_BASE = 'currency/options/base';
35+
public const XML_PATH_CURRENCY_BASE = 'currency/options/base';
3636

3737
/**
3838
* @var Filter
@@ -439,7 +439,13 @@ private function formatCurrency(string $price, array $options): string
439439

440440
if ((array_key_exists(LocaleCurrency::CURRENCY_OPTION_DISPLAY, $options)
441441
&& $options[LocaleCurrency::CURRENCY_OPTION_DISPLAY] === \Magento\Framework\Currency::NO_SYMBOL)) {
442-
$formattedCurrency = preg_replace(['/[^0-9.,۰٫]+/', '/ /'], '', $formattedCurrency);
442+
if ($this->isArabicSymbols($formattedCurrency)) {
443+
/* Workaround. We need to provide Arabic symbols range and Unicode modifier into expression
444+
to bypass issue when preg_replace with Arabic symbol return corrupted result */
445+
$formattedCurrency = preg_replace(['/[^0-9\x{0600}-\x{06FF}.,۰٫]+/u', '/ /'], '', $formattedCurrency);
446+
} else {
447+
$formattedCurrency = preg_replace(['/[^0-9.,۰٫]+/', '/ /'], '', $formattedCurrency);
448+
}
443449
}
444450

445451
return preg_replace('/^\s+|\s+$/u', '', $formattedCurrency);
@@ -597,4 +603,15 @@ private function trimUnicodeDirectionMark($string)
597603
}
598604
return $string;
599605
}
606+
607+
/**
608+
* Checks if given string is of Arabic symbols
609+
*
610+
* @param string $string
611+
* @return bool
612+
*/
613+
private function isArabicSymbols(string $string): bool
614+
{
615+
return preg_match('/[\p{Arabic}]/u', $string) > 0;
616+
}
600617
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,18 @@ public function getOutputFormatDataProvider(): array
128128
'expected' => '$%s',
129129
'locale' => 'en_US'
130130
],
131-
'arabic_unicode' => [
131+
'arabic_ar_SA' => [
132+
'expected' => '%s' . json_decode('"\u00A0"') . 'US$',
133+
'locale' => 'ar_SA'
134+
],
135+
'arabic_fa_IR' => [
132136
'expected' => json_decode('"\u200E"') . '$%s',
133137
'locale' => 'fa_IR'
134-
]
138+
],
139+
'arabic_ar_KW' => [
140+
'expected' => '%s' . json_decode('"\u00A0"') . 'US$',
141+
'locale' => 'ar_KW'
142+
],
135143
];
136144
}
137145

0 commit comments

Comments
 (0)