Magento 2遇到错误的“请求的数量超过购物车中允许的最大数量”。

发布于 2025-02-13 12:21:08 字数 747 浏览 0 评论 0原文

代码示例:

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这样做。如果有人已经经历过,任何人都可以帮我吗?

xdebug break Point,其中cart中的最后一项从1增加到2

xdebug呼叫堆栈跟踪

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

xdebug call stack trace of the trace

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安静 2025-02-20 12:21:08

我希望你做得很好!

请检查下面的配置,该配置是所有产品的全局。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文