2
votes

I have created this observer. The observer works if I call dispatchEvent within a test.php script.

include 'app/Mage.php';

umask(0);
Mage::app('default');

$event_data_array  =  array('cid' => '123');
Mage::dispatchEvent('customer_register_success', $event_data_array);

I am logging the events in app/Mage.php to see if this same event is being called when I register a new user, and it is. var/log/myevent.log is being created and written too.

 public static function dispatchEvent($name, array $data = array())
    {
        Varien_Profiler::start('DISPATCH EVENT:'.$name);
        $result = self::app()->dispatchEvent($name, $data);
        Varien_Profiler::stop('DISPATCH EVENT:'.$name);

        if($name == 'customer_register_success') Mage::log('customer_register_success', null, 'myevent.log'); // This log file is being created when I go through the registration process.

        return $result;
    }

My Observer code is as follows (was copied from this forum)

app/code/local/Meteorify/Observerexample/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Meteorify_Observerexample>
            <version>0.0.1</version>
        </Meteorify_Observerexample>
    </modules>
    <global>
        <models>
            <meteorifyobserverexample>
                <class>Observerexample_Model</class>
            </meteorifyobserverexample>
        </models>
        <events>
            <customer_register_success>
                <observers>
                    <meteorify_observerexample_model_observer>
                        <type>singleton</type>
                        <class>Meteorify_Observerexample_Model_Observer</class>
                        <method>example</method>
                    </meteorify_observerexample_model_observer>
                </observers>
            </customer_register_success>
        </events>
    </global>
</config>

app/code/local/Meteorify/Observerexample/Model/Observer.php

    <?php
class Meteorify_Observerexample_Model_Observer {

    public function example($observer) {
        //$observer contains data passed from when the event was triggered.
        //You can use this data to manipulate the order data before it's saved.
        //Uncomment the line below to log what is contained here:
        //Mage::log($observer);

        Mage::log('We just made an Observer!', null, 'mylog.log');
    }

}

app/etc/modules/Meteorify_Observerexample.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Meteorify_Observerexample>
            <codePool>local</codePool>
            <active>true</active>
        </Meteorify_Observerexample>
    </modules>
</config>

The code works and the var/log/mylog.log is being created when I call test.php, but when I register a user, it doesn't get called.

2

2 Answers

0
votes

Your problem is coming from your model definition.

<models>
    <meteorifyobserverexample>
        <class>Meteorify_Observerexample_Model</class> <!-- and not Observerexample_Model -->
    </meteorifyobserverexample>
</models>

You may also try changing this class under you <event> node

<class>meteorifyobserverexample/observer</class> <!-- instead of Meteorify_Observerexample_Model_Observer -->
0
votes

Ok, turns out i'm being a bit dumb.. i forgot to turn off the Compiled code.

Fix - In admin System -> Tools -> Compilation - Disable.