Skip to content

Commit 5ba7a73

Browse files
committed
MC-41911: Decimal quantity is converted to integer value when updated
1 parent 4614d9e commit 5ba7a73

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

app/code/Magento/Checkout/Controller/Cart/Add.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
*/
77
namespace Magento\Checkout\Controller\Cart;
88

9+
use Magento\Checkout\Model\Cart\RequestQuantityProcessor;
910
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
1011
use Magento\Catalog\Api\ProductRepositoryInterface;
1112
use Magento\Checkout\Model\Cart as CustomerCart;
13+
use Magento\Framework\App\ObjectManager;
1214
use Magento\Framework\App\ResponseInterface;
1315
use Magento\Framework\Controller\ResultInterface;
1416
use Magento\Framework\Exception\NoSuchEntityException;
@@ -25,6 +27,11 @@ class Add extends \Magento\Checkout\Controller\Cart implements HttpPostActionInt
2527
*/
2628
protected $productRepository;
2729

30+
/**
31+
* @var RequestQuantityProcessor
32+
*/
33+
private $quantityProcessor;
34+
2835
/**
2936
* @param \Magento\Framework\App\Action\Context $context
3037
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
@@ -33,6 +40,7 @@ class Add extends \Magento\Checkout\Controller\Cart implements HttpPostActionInt
3340
* @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
3441
* @param CustomerCart $cart
3542
* @param ProductRepositoryInterface $productRepository
43+
* @param RequestQuantityProcessor|null $quantityProcessor
3644
* @codeCoverageIgnore
3745
*/
3846
public function __construct(
@@ -42,7 +50,8 @@ public function __construct(
4250
\Magento\Store\Model\StoreManagerInterface $storeManager,
4351
\Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator,
4452
CustomerCart $cart,
45-
ProductRepositoryInterface $productRepository
53+
ProductRepositoryInterface $productRepository,
54+
?RequestQuantityProcessor $quantityProcessor = null
4655
) {
4756
parent::__construct(
4857
$context,
@@ -53,6 +62,8 @@ public function __construct(
5362
$cart
5463
);
5564
$this->productRepository = $productRepository;
65+
$this->quantityProcessor = $quantityProcessor
66+
?? ObjectManager::getInstance()->get(RequestQuantityProcessor::class);
5667
}
5768

5869
/**
@@ -99,6 +110,7 @@ public function execute()
99110
\Magento\Framework\Locale\ResolverInterface::class
100111
)->getLocale()]
101112
);
113+
$params['qty'] = $this->quantityProcessor->prepareQuantity($params['qty']);
102114
$params['qty'] = $filter->filter($params['qty']);
103115
}
104116

app/code/Magento/Checkout/Model/Cart/RequestQuantityProcessor.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace Magento\Checkout\Model\Cart;
99

1010
use Magento\Framework\Locale\ResolverInterface;
11-
use Zend_Locale_Data;
1211

1312
/**
1413
* Cart request quantity processor
@@ -60,17 +59,18 @@ public function process(array $cartData): array
6059
*/
6160
public function prepareQuantity($quantity)
6261
{
63-
$symbols = Zend_Locale_Data::getList($this->localeResolver->getLocale(),'symbols');
62+
$formatter = new \NumberFormatter($this->localeResolver->getLocale(), \NumberFormatter::CURRENCY);
63+
$decimalSymbol = $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
6464

6565
if (is_array($quantity)) {
6666
foreach ($quantity as $key => $qty) {
67-
if (strpos((string)$qty, '.') !== false && $symbols['decimal'] !== '.') {
68-
$quantity[$key] = str_replace('.', $symbols['decimal'], $qty);
67+
if (strpos((string)$qty, '.') !== false && $decimalSymbol !== '.') {
68+
$quantity[$key] = str_replace('.', $decimalSymbol, $qty);
6969
}
7070
}
7171
} else {
72-
if (strpos((string)$quantity, '.') !== false && $symbols['decimal'] !== '.') {
73-
$quantity = str_replace('.', $symbols['decimal'], (string)$quantity);
72+
if (strpos((string)$quantity, '.') !== false && $decimalSymbol !== '.') {
73+
$quantity = str_replace('.', $decimalSymbol, (string)$quantity);
7474
}
7575
}
7676

0 commit comments

Comments
 (0)