You can create an event with the Mage::dispatchEvent method. If you have an object like the order then you have to define a parameterlist as Array. array( 'order' => $order)
Just implement following line to your extension class:
Mage::dispatchEvent('the_event_name',array( 'order' => $order));
To observe an event, specify the observer in the config.xml at /app/(codepool)/Extensionname/ .
<config>
<global>
<events>
<the_event_name>
<observers>
<extensionname>
<type>singleton</type>
<class>Extensionname_Model_Observer</class>
<method>methodName</method>
</extensionname>
</observers>
</the_event_name>
</events>
</global>
</config>
Create an Extension and a model (Observer.php): /app/(codepool)/Extensionname/Model/Observer.php
class Extensionname_Model_Observer
{
public function methodName($event)
{
$order = $event->getOrder();
//for example send a new order mail to customer
$order->sendNewOrderEmail()->setEmailSent(true)->
save();
//do something else ....
}
}
No comments:
Post a Comment