Skip to content

Commit fa2a219

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 b8f2b4f commit fa2a219

File tree

2 files changed

+18
-36
lines changed

2 files changed

+18
-36
lines changed

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

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
*/
1111
class Format implements \Magento\Framework\Locale\FormatInterface
1212
{
13+
/**
14+
* Japan locale code
15+
*/
16+
private const JAPAN_LOCALE_CODE = 'ja_JP';
17+
1318
/**
1419
* @var \Magento\Framework\App\ScopeResolverInterface
1520
*/
@@ -25,11 +30,6 @@ class Format implements \Magento\Framework\Locale\FormatInterface
2530
*/
2631
protected $currencyFactory;
2732

28-
/**
29-
* @var array
30-
*/
31-
private $groupSeparatorByLocale = [];
32-
3333
/**
3434
* @param \Magento\Framework\App\ScopeResolverInterface $scopeResolver
3535
* @param ResolverInterface $localeResolver
@@ -87,12 +87,14 @@ public function getNumber($value)
8787
}
8888
} elseif ($separatorComa !== false) {
8989
$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-
}
90+
/**
91+
* It's hard code for Japan locale.
92+
* Comma separator uses as group separator: 4,000 saves as 4,000.00
93+
*/
94+
$value = str_replace(
95+
',',
96+
$locale === self::JAPAN_LOCALE_CODE ? '' : '.',
97+
$value);
9698
}
9799

98100
return (float)$value;
@@ -160,22 +162,4 @@ public function getPriceFormat($localeCode = null, $currencyCode = null)
160162

161163
return $result;
162164
}
163-
164-
/**
165-
* Retrieve group separator symbol by locale
166-
*
167-
* @param string $locale
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-
}
181165
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,13 @@ public function provideNumbers(): array
129129
['12343', 12343],
130130
['-9456km', -9456],
131131
['0', 0],
132-
['2 054,10', 205410, 'en_US'],
133-
['2 054,10', 2054.1, 'de_DE'],
134-
['2046,45', 204645, 'en_US'],
135-
['2046,45', 2046.45, 'de_DE'],
132+
['2 054,10', 2054.1],
133+
['2046,45', 2046.45],
136134
['2 054.52', 2054.52],
137-
['2,46 GB', 246, 'en_US'],
138-
['2,46 GB', 2.46, 'de_DE'],
135+
['2,46 GB', 2.46],
139136
['2,054.00', 2054],
140-
['2,000', 2000, 'ja_JP'],
137+
['4,000', 4000.0, 'ja_JP'],
138+
['4,000', 4.0, 'en_US'],
141139
];
142140
}
143141
}

0 commit comments

Comments
 (0)