Skip to content

Commit d604aea

Browse files
committed
MAGETWO-99152: Special Prices cannot save over 4 characters in Japanese Yen - The comma separator seems to be the issue
1 parent c224526 commit d604aea

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class Format implements \Magento\Framework\Locale\FormatInterface
2525
*/
2626
protected $currencyFactory;
2727

28+
/**
29+
* @var array
30+
*/
31+
private $groupSeparatorByLocale = [];
32+
2833
/**
2934
* @param \Magento\Framework\App\ScopeResolverInterface $scopeResolver
3035
* @param ResolverInterface $localeResolver
@@ -81,7 +86,13 @@ public function getNumber($value)
8186
$value = str_replace(',', '', $value);
8287
}
8388
} elseif ($separatorComa !== false) {
84-
$value = str_replace(',', '.', $value);
89+
$locale = $this->_localeResolver->getLocale();
90+
$groupSeparator = $this->retrieveLocaleGroupSeparator($locale);
91+
if ($groupSeparator === ',') {
92+
$value = str_replace(',', '', $value);
93+
} else {
94+
$value = str_replace(',', '.', $value);
95+
}
8596
}
8697

8798
return (float)$value;
@@ -149,4 +160,22 @@ public function getPriceFormat($localeCode = null, $currencyCode = null)
149160

150161
return $result;
151162
}
163+
164+
/**
165+
* Retrieve group separator symbol by locale
166+
*
167+
* @param $locale string
168+
* @return string
169+
*/
170+
private function retrieveLocaleGroupSeparator(string $locale): string
171+
{
172+
if (!array_key_exists($locale, $this->groupSeparatorByLocale)) {
173+
$formatter = new \NumberFormatter($locale, \NumberFormatter::DECIMAL);
174+
$this->groupSeparatorByLocale[$locale] = $formatter->getSymbol(
175+
\NumberFormatter::GROUPING_SEPARATOR_SYMBOL
176+
);
177+
}
178+
179+
return $this->groupSeparatorByLocale[$locale];
180+
}
152181
}

lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,14 @@ public function getPriceFormatDataProvider(): array
103103
*
104104
* @param mixed $value
105105
* @param float $expected
106+
* @param string $locale
106107
* @dataProvider provideNumbers
107108
*/
108-
public function testGetNumber($value, $expected): void
109+
public function testGetNumber(string $value, float $expected, string $locale = null): void
109110
{
111+
if ($locale !== null) {
112+
$this->localeResolver->method('getLocale')->willReturn($locale);
113+
}
110114
$this->assertEquals($expected, $this->formatModel->getNumber($value));
111115
}
112116

@@ -122,11 +126,15 @@ public function provideNumbers(): array
122126
['12343', 12343],
123127
['-9456km', -9456],
124128
['0', 0],
125-
['2 054,10', 2054.1],
126-
['2046,45', 2046.45],
129+
['2 054,10', 205410, 'en_US'],
130+
['2 054,10', 2054.1, 'de_DE'],
131+
['2046,45', 204645, 'en_US'],
132+
['2046,45', 2046.45, 'de_DE'],
127133
['2 054.52', 2054.52],
128-
['2,46 GB', 2.46],
134+
['2,46 GB', 246, 'en_US'],
135+
['2,46 GB', 2.46, 'de_DE'],
129136
['2,054.00', 2054],
137+
['2,000', 2000, 'ja_JP'],
130138
];
131139
}
132140
}

0 commit comments

Comments
 (0)