I want to limit the number of products that can be added to the cart from a particular category.I want the customer to add only one product from each category. If the customer tries to add one more product ,the product added previously should get replaced by the one added later. Can anyone help me with this?
2 Answers
I can help you with steps you need to take:
- Identify an event you can hook onto using an observer. This event should be one that always fires when you add-to-cart but before the product is actually added to cart. This is because you need to validate the product being added to the existing cart, if there's is one.
- Identify what category(ies) it belongs to and record it.
- Check the quote's items and get all of their categories as well.
- Validate that the product's category(ies) against the quote's categories.
- Take corresponding measures.
-
foe this you can use controller_action_predispatch_checkout_cart_add this event May 26, 2016 at 8:37
-
Can you please elaborate a little more on how to proceed with this event?– sk1May 26, 2016 at 10:57
-
Three events used during Add To Cart Process
1)checkout_cart_product_add_after
2) sales_quote_product_add_after
3)sale_quote_add_item
Use oberserver event is :
1) sale_quote_add_item
I will send you code later