Skip to content

Commit 28f1139

Browse files
author
Mike Weis
committed
MAGETWO-51908: [GITHUB] Price on product view page becomes 0,00 when locale is changed to persian (iran) #4077
- updated per code review
1 parent ff76a05 commit 28f1139

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,8 @@ public function saveRates($rates)
411411
*/
412412
private function trimUnicodeDirectionMark($string)
413413
{
414-
if (preg_match('/^\x{200E}/u', $string)) {
415-
$string = preg_replace('/^\x{200E}/u', '', $string);
416-
} elseif (preg_match('/^\x{200F}/u', $string)) {
417-
$string = preg_replace('/^\x{200F}/u', '', $string);
414+
if (preg_match('/^(\x{200E}|\x{200F})/u', $string, $match)) {
415+
$string = preg_replace('/^'.$match[1].'/u', '', $string);
418416
}
419417
return $string;
420418
}

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,49 @@ public function testGetCurrencySymbol()
5252
->willReturn($currencyMock);
5353
$this->assertEquals($currencySymbol, $this->currency->getCurrencySymbol());
5454
}
55+
56+
/**
57+
* @dataProvider getOutputFormatDataProvider
58+
* @param $withCurrency
59+
* @param $noCurrency
60+
* @param $expected
61+
*/
62+
public function testGetOutputFormat($withCurrency, $noCurrency, $expected)
63+
{
64+
$currencyMock = $this->getMockBuilder('\Magento\Framework\Currency')
65+
->disableOriginalConstructor()
66+
->getMock();
67+
$currencyMock->expects($this->at(0))
68+
->method('toCurrency')
69+
->willReturn($withCurrency);
70+
$currencyMock->expects($this->at(1))
71+
->method('toCurrency')
72+
->willReturn($noCurrency);
73+
$this->localeCurrencyMock->expects($this->atLeastOnce())
74+
->method('getCurrency')
75+
->with($this->currencyCode)
76+
->willReturn($currencyMock);
77+
$this->assertEquals($expected, $this->currency->getOutputFormat());
78+
}
79+
80+
/**
81+
* Return data sets for testGetCurrencySymbol()
82+
*
83+
* @return array
84+
*/
85+
public function getOutputFormatDataProvider()
86+
{
87+
return [
88+
'no_unicode' => [
89+
'withCurrency' => '$0.00',
90+
'noCurrency' => '0.00',
91+
'expected' => '$%s',
92+
],
93+
'arabic_unicode' => [
94+
'withCurrency' => json_decode('"\u200E"') . '$0.00',
95+
'noCurrency' => json_decode('"\u200E"') . '0.00',
96+
'expected' => json_decode('"\u200E"') . '$%s',
97+
]
98+
];
99+
}
55100
}

lib/internal/Magento/Framework/Locale/Format.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99

1010
class Format implements \Magento\Framework\Locale\FormatInterface
1111
{
12-
const DEFAULT_NUMBER_SET = 'latn';
12+
/**
13+
* @var string
14+
*/
15+
private static $defaultNumberSet = 'latn';
1316

1417
/**
1518
* @var \Magento\Framework\App\ScopeResolverInterface
@@ -106,17 +109,17 @@ public function getPriceFormat($localeCode = null, $currencyCode = null)
106109
$currency = $this->_scopeResolver->getScope()->getCurrentCurrency();
107110
}
108111
$localeData = (new DataBundle())->get($localeCode);
109-
$defaultSet = $localeData['NumberElements']['default'] ?: self::DEFAULT_NUMBER_SET;
112+
$defaultSet = $localeData['NumberElements']['default'] ?: self::$defaultNumberSet;
110113
$format = $localeData['NumberElements'][$defaultSet]['patterns']['currencyFormat']
111-
?: ($localeData['NumberElements'][self::DEFAULT_NUMBER_SET]['patterns']['currencyFormat']
114+
?: ($localeData['NumberElements'][self::$defaultNumberSet]['patterns']['currencyFormat']
112115
?: explode(';', $localeData['NumberPatterns'][1])[0]);
113116

114117
$decimalSymbol = $localeData['NumberElements'][$defaultSet]['symbols']['decimal']
115-
?: ($localeData['NumberElements'][self::DEFAULT_NUMBER_SET]['symbols']['decimal']
118+
?: ($localeData['NumberElements'][self::$defaultNumberSet]['symbols']['decimal']
116119
?: $localeData['NumberElements'][0]);
117120

118121
$groupSymbol = $localeData['NumberElements'][$defaultSet]['symbols']['group']
119-
?: ($localeData['NumberElements'][self::DEFAULT_NUMBER_SET]['symbols']['group']
122+
?: ($localeData['NumberElements'][self::$defaultNumberSet]['symbols']['group']
120123
?: $localeData['NumberElements'][1]);
121124

122125
$pos = strpos($format, ';');

0 commit comments

Comments
 (0)