开发者

How to create event dispatcher in magento? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Creating Hello world开发者_Go百科 event dispatcher(observer) in Magento?

Hi ,

In my Mage website i am in a situation to perform a set of tasks after a product being added to the shopping cart... i tried to create an event dispatcher, but not succeeded in it.

Can anyone give me info about step by step implementation of event dispatcher or any helpful link?

Thanks,

Balan


Step 1: define your module in /app/etc/module/Mycompany_Observer.xml:

<?xml version="1.0" encoding="utf-8"?>
<config>
    <modules>
        <Mycompany_Observer>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Core />
            </depends>
        </Mycompany_Observer>
    </modules>
</config>

Step 2: define your configuration in /app/code/local/Mycompany/Observer/etc/config.xml:

<?xml version="1.0" encoding="utf-8"?>
<config>
    <modules>
        <Mycompany_Observer>
            <version>0.1.0</version>
        </Mycompany_Observer>
    </modules>
    <global>
        <models>
            <myobserver>
                <class>Mycompany_Observer_Model</class>
            </myobserver>
        </models>
    </global>
    <frontend>
        <events>
            <add_to_cart_after>
                <observers>
                    <my_unique_identifier>
                        <type>singleton</type>
                        <class>myobserver/observer</class>
                        <method>myAddToCartAfter</method>
                    </my_unique_identifier>
                </observers>
            </add_to_cart_after>
        </events>
    </frontend>
</config>

Step 3: define your observer in /app/code/local/Mycompany/Observer/Model/Observer.php:

class Mycompany_Observer_Model_Observer extends Mage_Core_Model_Abstract
{
    public function myAddToCartAfter($oObserver)
    {
        var_dump($oObserver->getData());
        die('stop');
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜