Usually, i divide Magento hooks into two category: block hooks and model hooks. Model hooks are used to add extra handling for business logic and block hooks for template rendering.
1. Block Hooks;
final public function toHtml()
{
Mage::dispatchEvent('core_block_abstract_to_html_before', array('block' => $this));
if (Mage::getStoreConfig('advanced/modules_disable_output/'.$this->getModuleName())) {
return '';
}
$html = $this->_loadCache();
if ($html === false) {
$translate = Mage::getSingleton('core/translate');
/* @var $translate Mage_Core_Model_Translate */
if ($this->hasData('translate_inline')) {
$translate->setTranslateInline($this->getData('translate_inline'));
}
$this->_beforeToHtml();
$html = $this->_toHtml();
$this->_saveCache($html);
if ($this->hasData('translate_inline')) {
$translate->setTranslateInline(true);
}
}
$html = $this->_afterToHtml($html);
/**
* Check framing options
*/
if ($this->_frameOpenTag) {
$html = '<'.$this->_frameOpenTag.'>'.$html.'<'.$this->_frameCloseTag.'>';
}
/**
* Use single transport object instance for all blocks
*/
if (self::$_transportObject === null) {
self::$_transportObject = new Varien_Object;
}
self::$_transportObject->setHtml($html);
Mage::dispatchEvent('core_block_abstract_to_html_after', array('block' => $this, 'transport' => self::$_transportObject));
$html = self::$_transportObject->getHtml();
return $html;
}
There are two outstanding statements:
Mage::dispatchEvent('core_block_abstract_to_html_before', array('block' => $this));
Mage::dispatchEvent('core_block_abstract_to_html_after', array('block' => $this, 'transport' => self::$_transportObject));
When you hooks core_block_abstract_to_html_before, it will change the block as you want.
2. Model Hooks;
There are lots of model hooks in the Magento. Please have a check the default hook list below:
http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/events
3. Event Mechanism;
public function dispatchEvent($eventName, $args)
{
foreach ($this->_events as $area=>$events) {
if (!isset($events[$eventName])) {
$eventConfig = $this->getConfig()->getEventConfig($area, $eventName);
if (!$eventConfig) {
$this->_events[$area][$eventName] = false;
continue;
}
$observers = array();
foreach ($eventConfig->observers->children() as $obsName=>$obsConfig) {
$observers[$obsName] = array(
'type' => (string)$obsConfig->type,
'model' => $obsConfig->class ? (string)$obsConfig->class : $obsConfig->getClassName(),
'method'=> (string)$obsConfig->method,
'args' => (array)$obsConfig->args,
);
}
$events[$eventName]['observers'] = $observers;
$this->_events[$area][$eventName]['observers'] = $observers;
}
if (false===$events[$eventName]) {
continue;
} else {
$event = new Varien_Event($args);
$event->setName($eventName);
$observer = new Varien_Event_Observer();
}
foreach ($events[$eventName]['observers'] as $obsName=>$obs) {
$observer->setData(array('event'=>$event));
Varien_Profiler::start('OBSERVER: '.$obsName);
switch ($obs['type']) {
case 'disabled':
break;
case 'object': case 'model':
$method = $obs['method'];
$observer->addData($args);
$object = Mage::getModel($obs['model']);
$this->_callObserverMethod($object, $method, $observer);
break;
default:
$method = $obs['method'];
$observer->addData($args);
$object = Mage::getSingleton($obs['model']);
$this->_callObserverMethod($object, $method, $observer);
break;
}
Varien_Profiler::stop('OBSERVER: '.$obsName);
}
}
return $this;
}