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?
-
4I use this as a nice cheat sheet nicksays.co.uk/magento-events-cheat-sheet-1-7– Derrik NyomoCommented Jan 24, 2013 at 16:38
-
1@DerrikNyomo - you should post that as an answer along with a summary of the information which it provides. :-)– benmarksCommented Jan 24, 2013 at 16:40
-
1Cheat 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.– ProxiBlueCommented Jan 26, 2013 at 7:43
15 Answers
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
-
4Very 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– benmarksCommented Jan 26, 2013 at 13:31 -
1Excellent. 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. Commented Jan 26, 2013 at 15:11
-
3The approach I usually take is, a quick edit/save/revert to
app/code/core/Mage/Core/Model/App.php
andmage::log($eventName,null,'events.txt',true);
to thedispatchEvent
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. :)– B00MERCommented Apr 15, 2013 at 20:39 -
2good, 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... Commented Apr 16, 2013 at 9:55
-
Is there any event gets fired after shipment creation in magento @FabianBlechschmidt Commented May 1, 2016 at 8:59
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.
-
2That 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. Commented Jan 24, 2013 at 18:35
-
1The 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 ofCheckout/Type/Onepage.php
.– kojiroCommented Jan 24, 2013 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– DomCommented Sep 5, 2016 at 10:37
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.
-
4Since 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 :-)– benmarksCommented Jan 24, 2013 at 16:45
-
3I'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). Commented Jan 24, 2013 at 18:31
-
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! :)
-
2This will miss some events which are fired before store config is merged.– benmarksCommented Oct 9, 2013 at 12:36
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/
-
1Sorry - 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
, notablycontroller_front_init_before
. 2) This approach simply will not log every event that is dispatched, is this a typo or incomplete section?– benmarksCommented Jan 29, 2013 at 12:15 -
-
2Sorry, still not very accurate :-( - there are so many more events dispatched (predispatch, layout, rendering, as well as model and collection loads)...– benmarksCommented Jan 29, 2013 at 22:43
-
I am using Magento Developer Toolbar that has nice feature of displaying events that can be observed on loaded page.
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!
-
1You're still missing all of the subclassed magic events. Can't be grepped for.– benmarksCommented Jul 2, 2014 at 19:08
-
Magic events as in? The ones which are dynamic? Could you elaborate plz @benmarks– huzefamCommented Jul 9, 2014 at 23:18
-
For example github.com/benmarks/magento-mirror/blob/magento-1.8/app/code/…– benmarksCommented Jul 18, 2014 at 1:23
-
@benmarks i agree, i do not think we need to prepare a list explicitly for this– huzefamCommented Jul 18, 2014 at 6:00
-
Hence my comment, which was offered based on the use of "exhaustive"– benmarksCommented Jul 18, 2014 at 16:23
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 Commented Oct 13, 2015 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. Commented Oct 13, 2015 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 ) :-) Commented Oct 13, 2015 at 7:09
-
-
theres a cheat sheet here also http://mikebywaters.wordpress.com/2012/07/23/magento-event-observer-list/
-
1Lone 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.– j0kCommented Feb 3, 2013 at 10:25
http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/magento_events
Here you can find complete list of observer events.
-
1
Here you can view the most of existing events: http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/magento_events
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.
You can find all list of backend + frontend events on single link
http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/magento_events
-
1This is not a complete resource, because there is no complete resource.– benmarksCommented Dec 24, 2014 at 20:01
-
If someone ever needs an updated list, I'm trying to keep this one up to date:
https://gist.github.com/digitalpianism/d8157c6b492238af2ed7809e5e3a134e
You can find all magento-1x events by following url. https://magento2.atlassian.net/wiki/display/m1wiki/Magento+1.x+Events+Reference