Question

I am trying to figure out how to set the maximum qty allowed in a shopping cart for an individual product.

In my case: Most products can be added to the cart as many times as they want, but I have a few products, that are configurables that can only be added once to the shopping cart per order.

In my research through the internet I found a few stackoverflow post and articles (below): https://stackoverflow.com/questions/27982651/magento-how-to-set-a-minimum-order-quantity-of-individual-simple-products

http://www.templatemonster.com/help/magento-how-to-set-minimummaximum-quantity-of-products-per-order.html#gref

where in Magento 1.9 you could set the Maximum and Minimum Qty Allowed in Shopping Cart per product. However, I haven't been able to find how to do this in Magento 2, I only found the global configurable.

If there is no way to do it through the admin, how would I go about to do this in code.

Était-ce utile?

La solution 2

As mentioned in the answer below, the max qty allowed for a simple product can be controlled through Magento 2 by changing the Maximum Qty Allowed in Shopping Cart in the Advanced Inventory panel at the product level.

However, in my case since I wanted to limit the max number of qty of configurable products I could add to the cart. I know that when a product is added to the cart and is considered to be a configurable, the simple product that expresses the options selected is added to the cart, not the configurable product itself.

For this, I had to create an observer that listened to the checkout_cart_product_add_after event. That way when a new product is attempted to be added to the cart, it will check if the product that is attempted to be added belongs to the configurable product that is only allowed to be added to the cart once, if so error out in this case.

Autres conseils

For Magento 2.1.x

Goto Admin -> Stores -> Configuration enter image description here

For individual settings, go to product details enter image description here

Click Advanced Inventory

enter image description here

You can do this as the other two have answered (using Advanced Inventory) on a configurable product, by looking at the simple products associated with it and changing the "Maximum Qty Allowed in Shopping Cart" for those products too.

I have same requirement ,could you please specify how to do this and full path of code if possible, I am newbie in magento 2

  1. How to define maximum number of quantity in entire cart

    2.Set Maximum Purchase Order Amount

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top