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.
In my opinion, the best way is using a Magento extension to set up a required order quantity for products in a category that customers have to meet before checking out.
I found out an extension on Magento Connect that supports this function: Limit Order Quantity per Category