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?
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.