Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find an appropriate event in Magento?

Sometimes when looking for a convenient event to hook I do a bit of exploratory programming...

  • Modify Mage::dispatchEvent with this extra line:

    Mage::log($name.'('.implode(',', array_keys($data)).')');
    
  • Mark a start point which I know I cannot catch any sooner:

    Mage::log(__METHOD__.'::START');
    
  • Mark an end point which I don't want to catch any later:

    Mage::log(__METHOD__.'::STOP');
    
  • Watch the log and step through the site (eg. order submission, whatever is being investigated)

    tailf var/log/system.log
    

This gives me a screen full of boring data and the names of objects being passed. Other than the START and STOP I'm usually not looking for anything specific enough to grep for it and I have to rely on my experience to identify possible bootstrap points. For example when placing orders I know there is often a 'quote' somewhere, or it is possible to get a reference to the order through a 'payment' object, or vice-versa.

Then I have to remember to remove my markers (not that hard when using any sort of versioning).

What methods do you use to find events? Can you do it without modifying core code?

like image 620
clockworkgeek Avatar asked Mar 12 '11 00:03

clockworkgeek


1 Answers

If I'm looking for a specific event, usually I will edit dispatchEvent() in Mage.php and add this to the top(I think these are the right params for log, writing this from memory though):

Mage::log( $name, 1, 'events.txt' );

Then I'll refresh the page, comment out that line to keep the file from getting extra events in it, and then go look at my events.txt file to see all the events that fired for that page load.

It's kind of hacky to be sure, but I've found it useful for finding events with variables as part of their names.

like image 133
Josh Avatar answered Oct 11 '22 12:10

Josh