Skip to content

Commit 5de19c2

Browse files
committed
Fixed Backward compability & other review comments
1 parent 1191efc commit 5de19c2

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

app/code/Magento/Checkout/Model/Sidebar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ protected function normalize($itemQty)
135135
}
136136

137137
$filter = new LocalizedToNormalized(
138-
['locale' => $this->resolver->getLocale()]
138+
['locale' => $this->resolver->getLocale(), 'decimal_style' => NumberFormatter::DECIMAL]
139139
);
140140
return $filter->filter((string)$itemQty);
141141
}

app/code/Magento/Checkout/Test/Unit/Model/SidebarTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,12 @@ public function testRemoveQuoteItem()
148148
*
149149
* @dataProvider dataProviderUpdateQuoteItem
150150
*/
151-
public function testUpdateQuoteItem($locale, $itemId, $expectedItemQty, $itemQty)
152-
{
151+
public function testUpdateQuoteItem(
152+
string $locale,
153+
int|string $itemId,
154+
int|string|float $expectedItemQty,
155+
int|string|float $itemQty
156+
) {
153157
$this->resolverMock->expects($this->once())
154158
->method('getLocale')
155159
->willReturn($locale);
@@ -188,7 +192,7 @@ public function testUpdateQuoteItemWithZeroQty()
188192
/**
189193
* @return array
190194
*/
191-
public static function dataProviderUpdateQuoteItem()
195+
public static function dataProviderUpdateQuoteItem(): array
192196
{
193197
return [
194198
//locale, itemId, expectedItemQty, ItemQty

lib/internal/Magento/Framework/Filter/LocalizedToNormalized.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class LocalizedToNormalized implements FilterInterface
2020
protected $_options = [
2121
'locale' => null,
2222
'date_format' => null,
23-
'precision' => null
23+
'precision' => null,
24+
'decimal_style' => null
2425
];
2526

2627
/**
@@ -67,8 +68,17 @@ public function setOptions(?array $options = null)
6768
public function filter($value)
6869
{
6970
if (is_numeric($value)) {
71+
72+
if (filter_var($value, FILTER_VALIDATE_INT) !== false) {
73+
$value = (int)$value;
74+
} elseif (filter_var($value, FILTER_VALIDATE_FLOAT) !== false) {
75+
$value = (float)$value;
76+
}
7077
$numberParse = new NumberParse(
71-
$this->_options['locale']
78+
$this->_options['locale'],
79+
empty($this->_options['decimal_style'])
80+
? NumberFormatter::PATTERN_DECIMAL
81+
: $this->_options['decimal_style']
7282
);
7383
return (string)$numberParse->filter($value);
7484
} elseif ($this->_options['date_format'] === null && strpos($value, ':') !== false) {

lib/internal/Magento/Framework/Filter/Test/Unit/LocalizedToNormalizedTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class LocalizedToNormalizedTest extends TestCase
2121
*
2222
* @dataProvider localizedToNormalizedDataProvider
2323
*/
24-
public function testLocalizedToNormalized($value, $options, $expectedValue)
24+
public function testLocalizedToNormalized(string $value, array $options, string|array $expectedValue)
2525
{
2626
$filter = new LocalizedToNormalized($options);
2727
$this->assertEquals($expectedValue, $filter->filter($value));
@@ -30,16 +30,16 @@ public function testLocalizedToNormalized($value, $options, $expectedValue)
3030
/**
3131
* @return array
3232
*/
33-
public static function localizedToNormalizedDataProvider()
33+
public static function localizedToNormalizedDataProvider(): array
3434
{
35-
3635
return [
3736
'1' => [
3837
"0.5",
3938
[
4039
'locale' => 'nl',
4140
'date_format' => null,
42-
'precision' => null
41+
'precision' => null,
42+
'decimal_style' => null
4343
],
4444
"0.5"
4545
],
@@ -48,7 +48,8 @@ public static function localizedToNormalizedDataProvider()
4848
[
4949
'locale' => 'en',
5050
'date_format' => null,
51-
'precision' => null
51+
'precision' => null,
52+
'decimal_style' => NumberFormatter::PATTERN_DECIMAL
5253
],
5354
"0.5"
5455
],

0 commit comments

Comments
 (0)