Observer for removed items in the cart

两盒软妹~` 提交于 2019-11-30 13:45:46

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().

Regarding the question of watching for events (whatever they may be), see Mage_Core_Model_App::dispatchEvent(). Sample debug/logging 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...
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!