93

I know that Magento has a hook-like system called events. Does anyone have a complete list or a script which can be used to determine which events can be called?

  • 4
    I use this as a nice cheat sheet nicksays.co.uk/magento-events-cheat-sheet-1-7 – Derrik Nyomo Jan 24 '13 at 16:38
  • 1
    @DerrikNyomo - you should post that as an answer along with a summary of the information which it provides. :-) – benmarks Jan 24 '13 at 16:40
  • 1
    Cheat sheets for events are in fact more of a hassle, as they give you a false sense that 'the event I want does not exist' and you may waste hours of coding, having missed an event that could have been used (since a lot are dynamically created) I posted an answer to this question : link and my answer also pertains to this question. It dos not give you a complete 'list', but it does give you a complete list of events for the action/page load you are interested in hooking to. – ProxiBlue Jan 26 '13 at 7:43

15 Answers 15

100

There is not a list of all magento events, because most of the events are dynamically named.

If you ask me, knowing these key events (and the consequences) is a good starting point (beside the list from nick):

Every Object extended from Mage_Core_Model_Abstract dispatches a lot events around loading, saving and deleting:

app/code/core/Mage/Core/Model/Abstract.php:255
Mage::dispatchEvent($this->_eventPrefix.'_load_before', $params);
// e.g. sales_order_load_before, checkout_cart_load_before

For example to add checks, after the object was loaded

app/code/core/Mage/Core/Model/Abstract.php:267
Mage::dispatchEvent($this->_eventPrefix.'_load_after', $this->_getEventData());
// e.g. cms_page_load_after

to add additional data to the object before it is saved

app/code/core/Mage/Core/Model/Abstract.php:391
Mage::dispatchEvent($this->_eventPrefix.'_save_before', $this->_getEventData());
// e.g. catalog_product_save_before

To save other models after the "parent" was saved

app/code/core/Mage/Core/Model/Abstract.php:466  
Mage::dispatchEvent($this->_eventPrefix.'_save_after', $this->_getEventData());
// e.g. catalogrule_rule_save_after

clean up, before the model is deleted

app/code/core/Mage/Core/Model/Abstract.php:501
Mage::dispatchEvent($this->_eventPrefix.'_delete_before', $this->_getEventData());
// e.g. store_delete_before

clean up, before the model is deleted - or maybe afterwards? You are here still in the transaction!

app/code/core/Mage/Core/Model/Abstract.php:529
Mage::dispatchEvent($this->_eventPrefix.'_delete_after', $this->_getEventData());
// e.g. website_delete_after

If you want to be sure the entity was deleted

app/code/core/Mage/Core/Model/Abstract.php:541
Mage::dispatchEvent($this->_eventPrefix.'_delete_commit_after', $this->_getEventData());
// e.g. customer_delete_commit_after

The collections extended from Mage_Core_Model_Resource_Db_Collection_Abstract have a two generic events too:

For example: to change the SQL to load the collection:

app/code/core/Mage/Core/Model/Resource/Db/Collection/Abstract.php:588
Mage::dispatchEvent($this->_eventPrefix.'_load_before', array(
    $this->_eventObject => $this
));
// e.g. sales_order_status_history_collection_load_before

For example: to add additional data to the objects:

app/code/core/Mage/Core/Model/Resource/Db/Collection/Abstract.php:637
Mage::dispatchEvent($this->_eventPrefix.'_load_after', array(
    $this->_eventObject => $this
));
// e.g. sales_order_shipment_collection_load_after
  • 4
    Very much a good answer; hoping for something we can tuck in the wiki. The importance of the _eventPrefix for the model events, the targeted request events, the occasionally-useful generic block events, and the importance of logging to find events – benmarks Jan 26 '13 at 13:31
  • 1
    Excellent. I wanted to note that in Magento 2 they really need to ensure all the core classes have a defined event prefix. I have actually rewritten classes just to define the event prefix so I can cleanly hook into save/load events. Hmm. Actually I think I'll go check the Magento 2 source myself. – Tim Reynolds Jan 26 '13 at 15:11
  • 3
    The approach I usually take is, a quick edit/save/revert to app/code/core/Mage/Core/Model/App.php and mage::log($eventName,null,'events.txt',true); to the dispatchEvent method. Load the page I'm trying to observe. Obviously don't leave this as is and revert once your var/logs/events.txt is created. Dirty, yes. Quick, yes. :) – B00MER Apr 15 '13 at 20:39
  • 2
    good, if you want your observer to be on one page. But be carful, there are events which should be dispatched, but might be not. There is a order or payment event which is not thrown, when payed with paypal... – Fabian Blechschmidt Apr 16 '13 at 9:55
  • Is there any event gets fired after shipment creation in magento @FabianBlechschmidt – Kingshuk Deb May 1 '16 at 8:59
48

Do the bloody grep 'Mage::dispatchEvent' app/ -rsn This will provide you with a list of events specific to your installation as the list of events may vary depending on Magento version, customizations and extensions installed.

  • 2
    That is best advice, it will include 3rd party modules events as well. Usually when I want to know which events I can hook to for particular page, I log app:dispatchEvent parameters. – Petar Dzhambazov Jan 24 '13 at 18:35
  • 1
    The grep will also give you bad information: For example, it claims that sales_order_place_after will happen, but it seems that the call to fire it is commented out of Checkout/Type/Onepage.php. – kojiro Jan 24 '13 at 19:25
  • This is a poor answer as it will only pick up a fraction of the available events as it completely misses all the dynamically generated events. @PetarDzhambazov gives good advice to log from the dispatcher and then load pages you are interested in. Best answer by far is the accepted answer given by FabianBlechschmidt – Dom Sep 5 '16 at 10:37
26

I use this as a nice cheat sheet http://www.nicksays.co.uk/magento-events-cheat-sheet-1-7/. It has all the events that that can be called in 1.7.

  • 4
    Since you've already done a good job of linking the content, best to also provide the content here in case Nick says "screw Magento" and deletes his page :-) – benmarks Jan 24 '13 at 16:45
  • 3
    I'm not a fan of this list, because 1: it's incomplete, 2: there are other 1231 blogs about Magento with "all" the events in Magento (+some wiki pages on Magento). – FlorinelChis Jan 24 '13 at 18:31
  • @benmarks guess what happened in the mean time... – toon81 Sep 4 '15 at 12:08
9

I know that this question has been answered I just add my way here:

  • I prepare page that I want to observe in my browser
  • I open app/Mage.php
  • for public static function dispatchEvent (ln:~446) in the begining I add //Mage::log($name, null, 'events.log', true);
  • uncomment that line,
  • refresh page that I'm on
  • comment again that line

Then you open var/log/events.log (~40kb) and see a whole lot events on that page only! :)

  • 2
    This will miss some events which are fired before store config is merged. – benmarks Oct 9 '13 at 12:36
6

Answer has already been accepted but Ill post my answer anyway for the future:

If you want to see the list of events that Magento has you have 3 options:

1) Google for it, there are a lot of people who have compiled a list of Magento events

2) Create a module that hooks on the controller_action_predispatch event which is the event that is called before any other event is called. Inside this module you can log some events that are dispatched:

Add the following on config.xml

<events>
    <controller_action_postdispatch>
        <observers>
            <controller_action_after>
                <class>yourmodule/observer</class>
                <method>hookToControllerActionPostDispatch</method>
            </controller_action_after>
        </observers>
    </controller_action_postdispatch>
</events>

And inside the yourmodule/Model/Observer:

public function hookToControllerActionPostDispatch($observer) {
    Mage::log($observer->getEvent()->getControllerAction()->getFullActionName());
}

The above would log every event that is dispatched...

3) If you have SSH access you can run the following command to get an overview of all the events (and their files where they are dispatched):

cd /path/to/<magento-root>
grep -nris 'dispatchEvent' app/code/
  • 1
    Sorry - while #3 is good, the information in 1 & 2 from your answer is really not correct. 1) There are a few events fired before controller_action_predispatch, notably controller_front_init_before. 2) This approach simply will not log every event that is dispatched, is this a typo or incomplete section? – benmarks Jan 29 '13 at 12:15
  • Edited it to "most" ;) – Kenny Jan 29 '13 at 13:09
  • 2
    Sorry, still not very accurate :-( - there are so many more events dispatched (predispatch, layout, rendering, as well as model and collection loads)... – benmarks Jan 29 '13 at 22:43
  • Updated the answer to "some events". – Kenny Jan 30 '13 at 6:06
4

I am using Magento Developer Toolbar that has nice feature of displaying events that can be observed on loaded page.

4

Here you can view the most of existing events: http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/magento_events

4

I have done a grep on core Mage module of Magento , and complied a list,

Exhaustive List of Magento Events

P.S. As pointed out, may contain events which are inside deprecated functions of Magento, so do check the file and line reference before implementation.

Open for suggestions!

  • 1
    You're still missing all of the subclassed magic events. Can't be grepped for. – benmarks Jul 2 '14 at 19:08
  • Magic events as in? The ones which are dynamic? Could you elaborate plz @benmarks – huzefam Jul 9 '14 at 23:18
  • @benmarks i agree, i do not think we need to prepare a list explicitly for this – huzefam Jul 18 '14 at 6:00
  • Hence my comment, which was offered based on the use of "exhaustive" – benmarks Jul 18 '14 at 16:23
4
grep "::dispatchEvent" -R * | sort -u

grep "eventPrefix" -R * | sort -u

The previous listed grep command would render duplicates (a lot) and it doesn't cover the list of event prefixes that would be required to understand the dynamically generated event names. These commands render both lists with only unique values. You could add the -n flag like the other grep answer and get the line number i suppose. But the question didn't ask where in the code they all were. ~_~

  • we have similar answer here. Refer @TimBezhashvyly's answer – Rajeev K Tomy Oct 13 '15 at 6:57
  • sort of.... the previous listed grep command would render duplicates (a lot) and it doesn't cover the list of event prefixes that would be required to understand the dynamically generated event names. These commands render both lists with only unique values. You could add the -n flag like the other grep answer and get the line number i suppose. But the question didn't ask where in the code they all were. – mprototype Oct 13 '15 at 7:01
  • could you please add this description to your answer. Then your answer become super cool... (am ready to do an upvote then ) :-) – Rajeev K Tomy Oct 13 '15 at 7:09
  • Does that help? – mprototype Oct 13 '15 at 7:13
  • Yes. +1 for that. :) – Rajeev K Tomy Oct 13 '15 at 7:13
3

theres a cheat sheet here also http://mikebywaters.wordpress.com/2012/07/23/magento-event-observer-list/

  • 1
    Lone link is considered a poor answer (see faq) since it is meaningless by itself and target resource is not guaranteed to be alive in the future. It would be preferable to include the essential parts of the answer here, and provide the link for reference. – j0k Feb 3 '13 at 10:25
3

http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/magento_events

Here you can find complete list of observer events.

  • 1
    No, you cannot. There is no such thing. :-) – benmarks Jul 11 '13 at 15:43
3

Refer these cheat sheets

https://www.nicksays.co.uk/magento-events-cheat-sheet-1-8/ http://rabee.me/codes/magento/cheatsheet/1.9/

It will helpful to you.

2

You can find all list of backend + frontend events on single link

http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/magento_events

  • 1
    This is not a complete resource, because there is no complete resource. – benmarks Dec 24 '14 at 20:01
  • Duplicate answer... Move your eyes 200px up ;) – 7ochem May 22 '15 at 9:40
2

If someone ever needs an updated list, I'm trying to keep this one up to date:

https://gist.github.com/digitalpianism/d8157c6b492238af2ed7809e5e3a134e

1

You can find all magento-1x events by following url. https://magento2.atlassian.net/wiki/display/m1wiki/Magento+1.x+Events+Reference

protected by Fabian Blechschmidt May 29 '14 at 9:11

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.