Categories


Archives


Recent Posts


Categories


Watching the Watchers

astorm

Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

Sometimes when you’re tracking down a bit of tricky Magento functionality, you need to quickly suss out not only what events have fired, but which observers methods are actually listening for the events that fired on a particular request.

There’s no elegant way to doing this with Magento, but if you’re not above a little temporary logging code in core files (moved to the local code pool, of course), then a few extra lines at the start of _callObserverMethod is what you want.

#File: app/code/core/Mage/Core/Model/App.php

protected function _callObserverMethod($object, $method, $observer)
{
    $log = 'Trying to call ' . $method . ' on ' . get_class($object)
    . ' for ' . $observer->getEvent()->getName();
    file_put_contents('/tmp/test.log',"$log n",FILE_APPEND);
    Mage::Log($log);            

    if (method_exists($object, $method)) {            
        $object->$method($observer);
    } elseif (Mage::getIsDeveloperMode()) {
        Mage::throwException('Method "'.$method.'" is not defined in "'.get_class($object).'"');
    }
    return $this;
}

Copyright © Alana Storm 1975 – 2023 All Rights Reserved

Originally Posted: 11th September 2011

email hidden; JavaScript is required