Magento 2遇到错误的“请求的数量超过购物车中允许的最大数量”。
代码示例:
class CustomAddToCart {
public function __construct(
\Magento\Checkout\Model\Cart $cart
) {
$this->cart = $cart;
}
public function execute()
{
$product = ....
$this->cart->addProduct($product, ['product' => $product->getId(), 'qty' => 1]);
$this->cart->save();
}
}
当购物车进行保存Magento尝试将当前在购物车中的最后一个项目的数量更改为2。由于我们网站中的所有产品仅具有1个库存数量1,只能在购物车中添加一次。所以我不知道为什么Magento这样做。如果有人已经经历过,任何人都可以帮我吗?
code example:
class CustomAddToCart {
public function __construct(
\Magento\Checkout\Model\Cart $cart
) {
$this->cart = $cart;
}
public function execute()
{
$product = ....
$this->cart->addProduct($product, ['product' => $product->getId(), 'qty' => 1]);
$this->cart->save();
}
}
When the cart do the save Magento tries to change the quantity of the last item currently in the cart into 2. Since all products in our website only have a stock quantity of 1 it can only be added in the cart once. So I do not know why Magento is doing this. Can anybody please help me if someone already had experience this.
xdebug break point where last item in cart is increased from 1 to 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我希望你做得很好!
请检查下面的配置,该配置是所有产品的全局。
1。商店>配置>目录>库存>产品股票期权>购物车中允许的最大数量
其次,您需要检查以下数量更改产品的配置。此设置将在全球设置上优先考虑,因此请在以下设置的帮助下进行相关的更改,然后再尝试一次。
2。目录>产品>编辑产品,同时添加到购物车中;搜索“高级库存”并单击它,您将获得购物车中允许的最大数量,然后将其更改为1(可以是任何东西)
3。 不要忘记清除缓存。 ,
请查看以下链接。
https://github.com/magento/magento/magento/magento/magento2/magento2/issues/18477
索努
I hope you are doing great!
Please check below configuration which is global for all the products.
1. Stores > Configuration > Catalog > Inventory > Product Stock Options > Maximum Qty Allowed in Shopping Cart
Secondly, you need to check the below configuration of the product for which the quantity is changing. This setting will take the precedence on global setting so please do the product related changes with the help of below setting and try one more time.
2. Catalog > Products > Edit the product which is having a problem while adding to the cart > Search for "Advanced Inventory" and click on it you will get Maximum Qty Allowed in Shopping Cart and change it to 1 (It can be anything)
3. Don't forget to clear the cache.
Please take a look at the below link.
https://github.com/magento/magento2/issues/18477
Thanks,
Sonu