1

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?

This is my Observer.php code. enter image description here

2
  • do you also want to restrict on no of quantity of a product as well or just on no of product ? May 25, 2016 at 13:20
  • On both no of quantity as well as no of products.
    – sk1
    May 26, 2016 at 7:26

2 Answers 2

0

I can help you with steps you need to take:

  1. 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.
  2. Identify what category(ies) it belongs to and record it.
  3. Check the quote's items and get all of their categories as well.
  4. Validate that the product's category(ies) against the quote's categories.
  5. Take corresponding measures.
3
  • 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?
    – sk1
    May 26, 2016 at 10:57
  • This worked fine. Thank you so much for help!
    – sk1
    May 27, 2016 at 12:30
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.