Skip to content

Commit 57b0fd3

Browse files
authored
Merge pull request #7423 from magento-l3/ACP2E-457
ACP2E-457: Arabic (Saudi Arabia) locale breaks the product detail page
2 parents f7724e6 + f5a43f9 commit 57b0fd3

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-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: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ class CurrencyTest extends TestCase
2323
*/
2424
protected $currency;
2525

26+
/**
27+
* @var string
28+
*/
29+
2630
protected $currencyCode = 'USD';
2731

2832
/**
@@ -128,10 +132,18 @@ public function getOutputFormatDataProvider(): array
128132
'expected' => '$%s',
129133
'locale' => 'en_US'
130134
],
131-
'arabic_unicode' => [
135+
'arabic_ar_SA' => [
136+
'expected' => '%s' . json_decode('"\u00A0"') . 'US$',
137+
'locale' => 'ar_SA'
138+
],
139+
'arabic_fa_IR' => [
132140
'expected' => json_decode('"\u200E"') . '$%s',
133141
'locale' => 'fa_IR'
134-
]
142+
],
143+
'arabic_ar_KW' => [
144+
'expected' => '%s' . json_decode('"\u00A0"') . 'US$',
145+
'locale' => 'ar_KW'
146+
],
135147
];
136148
}
137149

0 commit comments

Comments
 (0)