I’ve successfully set up an observer in Magento that binds to a custom add to cart event. Now, under a certain condition, I need to stop the add to cart event (or remove it even?), and flash a message to the user.
Currently, this product is set to allow for a maximum quantity of 1 per order. In the event that a user attempts to add more than 1, Magento displays an error message and prevents the item from being added to the cart.
Screenshot: [link] http://cl.ly/image/3V2C2j1S0f37
Ideally, I want to mimic the same functionality from my observer, but I have absolutely no idea how to tackle this as I’m new to Magento.
I’ve read that I need to throw an exception. But when I did that, it just took me to an error page. Wondering if I need to somehow add a modified version of this:
Mage::helper('cataloginventory')->__('The maximum quantity allowed for purchase is %s.', '<span class="sku-failed-qty" id="sku-stock-failed-' . $item->getId() . '">' . ($item->getQtyMaxAllowed() * 1) . '</span>');
Any help, or pointers would be greatly appreciated.
You can try the following. This will check if the quantity is bigger than 1. If this is the situation then we will update the quantity to 1. We also add a notice message so the user is informed about the quantity change.
===== EDIT ======
Another option would be: