The event and observer pattern is probably one of Magento's more interesting features, since it allows developers to extend Magento in critical parts of the application flow.
In order to provide more flexibility and facilitate the interaction between the different modules, Magento implements an event/observer pattern; this pattern allows for modules to be loosely coupled.
There are two parts of this system – an event dispatch with the object and event information, and an observer listening to a particular event.
Events are created or dispatched using the Mage::dispatchEvent()
function. The core team has already created several events on critical parts of the core. For example, the model abstract class Mage_Core_Model_Abstract
calls two protected functions every time a model is saved – _beforeSave()
and _afterSave()
; on each of these methods two events are fired:
protected function _beforeSave() { if (!$this->getId()) { $this->isObjectNew(true...