Skip to content

Commit 73c3d9a

Browse files
committed
#39236: Magento 2.4.7 update (mini)cart no decimal qty allowed
- fixed issue with the wrong parsing float values (depends on '.' or ',')
1 parent 6be1685 commit 73c3d9a

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\Exception\LocalizedException;
1111
use Magento\Framework\Filter\LocalizedToNormalized;
1212
use Magento\Framework\Locale\ResolverInterface;
13+
use Magento\Framework\NumberFormatter;
1314
use Magento\Quote\Api\Data\CartItemInterface;
1415
use Magento\Quote\Model\Quote\Address\Total;
1516

@@ -134,7 +135,7 @@ protected function normalize($itemQty)
134135
}
135136

136137
$filter = new LocalizedToNormalized(
137-
['locale' => $this->resolver->getLocale(), 'decimal_style' => false]
138+
['locale' => $this->resolver->getLocale(), 'decimal_style' => NumberFormatter::DECIMAL]
138139
);
139140
return $filter->filter((string)$itemQty);
140141
}

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Framework\Filter;
78

89
use Exception;
@@ -17,9 +18,9 @@ class LocalizedToNormalized implements FilterInterface
1718
* @var array
1819
*/
1920
protected $_options = [
20-
'locale' => null,
21-
'date_format' => null,
22-
'precision' => null,
21+
'locale' => null,
22+
'date_format' => null,
23+
'precision' => null,
2324
'decimal_style' => null,
2425
];
2526

@@ -67,14 +68,10 @@ public function setOptions(?array $options = null)
6768
public function filter($value)
6869
{
6970
if (is_numeric($value)) {
70-
$decimalStyle = $this->_options['decimal_style'] ?? null;
71-
if ($decimalStyle === null) {
72-
$numberParse = new NumberParse($this->_options['locale'], NumberFormatter::PATTERN_DECIMAL);
73-
} elseif ($decimalStyle === false) {
74-
$numberParse = new NumberParse($this->_options['locale'], NumberFormatter::DECIMAL);
75-
} else {
76-
$numberParse = new NumberParse($this->_options['locale'], $decimalStyle);
77-
}
71+
$numberParse = new NumberParse(
72+
$this->_options['locale'],
73+
empty($this->_options['decimal_style']) ? NumberFormatter::PATTERN_DECIMAL : $this->_options['decimal_style']
74+
);
7875
return (string)$numberParse->filter($value);
7976
} elseif ($this->_options['date_format'] === null && strpos($value, ':') !== false) {
8077
$formatter = new IntlDateFormatter(
@@ -152,7 +149,7 @@ private function parseDate($date)
152149
$parse[$month] = 'M';
153150
}
154151
if ($year !== false) {
155-
$parse[$year] = 'y';
152+
$parse[$year] = 'y';
156153
}
157154
preg_match_all('/\d+/u', $date, $splitted);
158155
$split = false;
@@ -192,7 +189,7 @@ private function parseDate($date)
192189
}
193190
if ($split === false) {
194191
if (count($splitted[0]) > $cnt) {
195-
$result['year'] = $splitted[0][$cnt];
192+
$result['year'] = $splitted[0][$cnt];
196193
}
197194
} else {
198195
$result['year'] = iconv_substr($splitted[0][0], $split, $length);

0 commit comments

Comments
 (0)