Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

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.

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! :)

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/

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!

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. ~_~

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

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top