From 76e011a981d2ab38e6d23763e55dd53c2859fbcf Mon Sep 17 00:00:00 2001 From: Oleksandr Dubovyk Date: Mon, 22 Jun 2020 20:55:57 -0500 Subject: [PATCH] MC-31085: Add/Edit Product | Duplicating ".00" zeros on saves - fixed - modified test --- .../Magento/Framework/Locale/Format.php | 34 +++++++++++++++++++ .../Framework/Locale/Test/Unit/FormatTest.php | 2 ++ 2 files changed, 36 insertions(+) diff --git a/lib/internal/Magento/Framework/Locale/Format.php b/lib/internal/Magento/Framework/Locale/Format.php index 934c9638c7392..e332840327bf7 100644 --- a/lib/internal/Magento/Framework/Locale/Format.php +++ b/lib/internal/Magento/Framework/Locale/Format.php @@ -15,6 +15,17 @@ class Format implements \Magento\Framework\Locale\FormatInterface */ private const JAPAN_LOCALE_CODE = 'ja_JP'; + /** + * Arab locale code + */ + private const ARABIC_LOCALE_CODES = [ + 'ar_DZ', + 'ar_EG', + 'ar_KW', + 'ar_MA', + 'ar_SA', + ]; + /** * @var \Magento\Framework\App\ScopeResolverInterface */ @@ -73,6 +84,11 @@ public function getNumber($value) return (float)$value; } + /** Normalize for Arabic locale */ + if (in_array($this->_localeResolver->getLocale(), self::ARABIC_LOCALE_CODES)) { + $value = $this->normalizeArabicLocale($value); + } + //trim spaces and apostrophes $value = preg_replace('/[^0-9^\^.,-]/m', '', $value); @@ -163,4 +179,22 @@ public function getPriceFormat($localeCode = null, $currencyCode = null) return $result; } + + /** + * Normalizes the number of Arabic locale. + * + * Substitutes Arabic thousands grouping and Arabic decimal separator symbols (U+066C, U+066B) + * with common grouping and decimal separator + * + * @param string $value + * @return string + */ + private function normalizeArabicLocale($value): string + { + $arabicGroupSymbol = '٬'; + $arabicDecimalSymbol = '٫'; + $value = str_replace([$arabicGroupSymbol, $arabicDecimalSymbol], [',', '.'], $value); + + return $value; + } } diff --git a/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php b/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php index a204a733dc848..9c992ecff245c 100644 --- a/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php +++ b/lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php @@ -146,6 +146,8 @@ public function provideNumbers(): array ['2,054.00', 2054], ['4,000', 4000.0, 'ja_JP'], ['4,000', 4.0, 'en_US'], + ['2٬599٫50', 2599.50, 'ar_EG'], + ['2٬000٬000٫99', 2000000.99, 'ar_SA'], ]; } }