tags:

views:

276

answers:

1

Hi all, I am dealing with Magento for a while and i find it very interesting and probably my future choice of work tool. Though i have some troubles understanding some of the stuff going on. If i call www.store.com/catalog/product/view/id/2 then the product controller executes from the catalog core module, in it the product is being fetched via _initProduct() method first in which this event is being dispatched:

Mage::dispatchEvent('catalog_controller_product_init_before', array('controller_action'=>$this));
. Which class/method is being called? As i understood that should be a method from observer class which is under Model folder and it should be defined in the etc/config.xml file. Some of the events defined in the config.xml are executed automatically... (why?) where is defined the one used in the viewAction() from the ProductController.php in Catalog module? How i can send and use array data to the observer's methods, cause i saw some of them contains this method: Mage::app()->reinitStores() which re-inits store, group and website collections and it's not something simple. I find this very powerful and i really want to know the posibilities with using Observers and Events.

A: 

Event observers can be defined in the config.xml for any module that is active in the system, they don't necessarily have to be defined in the same module.

You can send data to the event observers by adding information to the event object, which is done in an array defined as the second argument to dispatchEvent. Just add more elements to the array and the event observer method can extract it from $observer->getEvent(). You are also free to define your own events by calling the same dispatchEvent method.

One of the handy things about most Magento models is that they are inherited from the Mage_Core_Model_Abstract class which includes event for _load_after, _save_before, _save_after, _delete_before and _delete_after. For example, the product model has catalog_product_load_after, catalog_product_save_before, etc.

Hope that gives you some more information about the possibilities of using events.

Chris Norton
Thank you for your answer, it's hard to find answers sometimes, but i like Magento a lot, the way it is organized and the way it can be extended. I will have a look at all possibilities with observers, cause i think it can save you from overriding core files in some cases.
Zoran