dispatch custom event in Magento
1. A controller dispathes the event register_success and broadcasts the customer data.
[code language=”php”]
Mage::dispatchEvent(‘register_success’, array(‘customer’ => $customer));
[/code]
2. The event configuration in the module’s config.xml file. It says run the function processCustomerData in the php class PackageName_ModuleName_Model_Observer when the event register_success is happened.
[code language=”xml”]
<frontend>
<events>
<enroll_success>
<observers>
<register_success_observer>
<type>singleton</type>
<class>PackageName_ModuleName_Model_Observer</class>
<method>processCustomerData</method>
</register_success_observer>
</observers>
</enroll_success>
</events>
</frontend>
[/code]
3. The function processCustomerData that reacts to the event ‘register_success‘
[code language=”php”]
public function processCustomerData(Varien_Event_Observer $observer)
{
$event = $observer->getEvent();
$customer = $event->getCustomer();
//Do something with the customer data
}
[/code]
References:
Magento observer examples
Magento native event list
Search within Codexpedia
Search the entire web