Cart items watcher

Is there an observer that can be used to monitor events when a product is removed from the basket? I did not find.

I found checkout_cart_update_items_after , which can be used if the product is removed by changing the quantity of goods, but not when the user uses the delete button. The only alternative that I see at the moment is checkout_cart_save_after , which is used whenever the basket changes. Of course, this requires custom logic that checks which product has been removed. Not ideal.

So, is there a better way to keep track of events?

+8
observer-pattern magento
source share
2 answers

You can use the sales_quote_remove_item event dispatched to Mage_Sales_Model_Quote::removeItem() .
The deleted 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() .

+24
source share

Regarding the issue of viewing events (no matter what they may be), see Mage_Core_Model_App::dispatchEvent() . Example debug / registration code:

 public function dispatchEvent($eventName, $args) { $argsArray = array(); $logfile = fopen(Mage::getBaseDir().'/var/log/events.log','a'); if(is_array($args)){ foreach ($args as $k => $v){ switch (gettype($v)) { case 'object': $v = get_class($v); break; case 'array': $v = 'array'; } $argsArray[$k] = $v; } } $log = $eventName.":\r\t"; foreach($argsArray as $k => $v){ $log .= $k; $log .= "\r\t\t".$v; } $log .= "\r\r"; fwrite($logfile,$log); fclose($logfile); // ...Rest of method... } 
+3
source share

All Articles