Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Observer for removed items in the cart

Is there an observer which can be used to observe events when a product is removed from the cart? I haven't found any.

What I have found is checkout_cart_update_items_after which can be used if a product is removed by altering the product count, but not when the user uses the remove button. The only alternative I see in the moment is checkout_cart_save_after which is used whenever the cart changes. Of course this needs custom logic which check which product was removed. Not perfect.

So is there a better way to watch out for remove events?

like image 411
spa Avatar asked Feb 08 '12 10:02

spa


1 Answers

You can use the sales_quote_remove_item event, dispatched in Mage_Sales_Model_Quote::removeItem().
The removed item is passed to the observer as an argument.

Mage::dispatchEvent('sales_quote_remove_item', array('quote_item' => $item));

To get the associated product model in an event observer, use $observer->getQuoteItem()->getProduct().

like image 184
Vinai Avatar answered Sep 26 '22 06:09

Vinai