Skip to content

Commit 6be1685

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 982b1c4 commit 6be1685

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,12 @@ public function updateQuoteItem($itemId, $itemQty)
129129
protected function normalize($itemQty)
130130
{
131131
if ($itemQty) {
132+
if (is_string($itemQty) && str_contains($itemQty, ',')) {
133+
$itemQty = (double)str_replace(',', '.', $itemQty);
134+
}
135+
132136
$filter = new LocalizedToNormalized(
133-
['locale' => $this->resolver->getLocale()]
137+
['locale' => $this->resolver->getLocale(), 'decimal_style' => false]
134138
);
135139
return $filter->filter((string)$itemQty);
136140
}

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ class LocalizedToNormalized implements FilterInterface
1717
* @var array
1818
*/
1919
protected $_options = [
20-
'locale' => null,
21-
'date_format' => null,
22-
'precision' => null
20+
'locale' => null,
21+
'date_format' => null,
22+
'precision' => null,
23+
'decimal_style' => null,
2324
];
2425

2526
/**
@@ -60,14 +61,21 @@ public function setOptions(?array $options = null)
6061
*
6162
* Normalizes the given input
6263
*
63-
* @param string $value Value to normalized
64+
* @param string $value Value to normalized
6465
* @return string|array The normalized value
6566
*/
6667
public function filter($value)
6768
{
6869
if (is_numeric($value)) {
69-
$numberParse = new NumberParse($this->_options['locale'], NumberFormatter::PATTERN_DECIMAL);
70-
return (string) $numberParse->filter($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+
}
78+
return (string)$numberParse->filter($value);
7179
} elseif ($this->_options['date_format'] === null && strpos($value, ':') !== false) {
7280
$formatter = new IntlDateFormatter(
7381
$this->_options['locale'],

0 commit comments

Comments
 (0)