1

I am learning observers and events, but following a simple event, i am unable to disect the problem, as to me it seems fine, and nothing in system.log as well. Following is my module etc/config.xml

<config>
    <global>
        <models>
            <csv>
                <class>Training_Csv_Model</class>
            </csv>
        </models>

        <events>
            <customer_login>
                <observers>
                    <csv>
                        <type>model</type>
                        <class>csv/observer</class>
                        <method>logCSV</method>
                    </csv>
                </observers>
            </customer_login>
        </events>
    </global>
</config>

while my observer.php file is under Name_space/module_name/Model/Observer.php and has following code

    class Training_Csv_Model_Observer{
        public function logCSV($observer){
        $customer = $observer->getCustomer();
        Mage::log($customer->getName()." has logged in", 
                    null,
                    "customer.log");

        }
    }

I am unable to understand why this wouldn't work, as a simple Model would work, meaning my module is working and loading. My knowledge of PHP is limited and i want to know, why this won't work.

2 Answers 2

3

Add following code inside your config.xml

<config>
    <modules>
        <Training_Csv>
            <version>0.0.0.1</version>
        </Training_Csv>
    </modules>
</config>

Your config.xml look like

<config>
    <modules>
        <Training_Csv>
            <version>0.0.0.1</version>
        </Training_Csv>
    </modules>
    <global>
        <models>
            <csv>
                <class>Training_Csv_Model</class>
            </csv>
        </models>

        <events>
            <customer_login>
                <observers>
                    <csv>
                        <type>model</type>
                        <class>csv/observer</class>
                        <method>logCSV</method>
                    </csv>
                </observers>
            </customer_login>
        </events>
    </global>
</config>
3
  • wow, such a small thing had me giving headache for so long. Why is it so important to define that and what it does internally?
    – localhost
    Commented Oct 2, 2016 at 6:47
  • If you create a custom module, modules tag inside config.xml is the minimum requirement of creating new module.
    – Sohel Rana
    Commented Oct 2, 2016 at 7:04
  • @SohelRana Can i get help magento.stackexchange.com/q/284297/57334
    – zus
    Commented Aug 3, 2019 at 11:50
0

If you take a look at the order of your opening nodes and closing nodes, you will see the error. The order of nodes should be <global><events>. The closing nodes are in the correct order but the opening nodes are not ordered correctly.

2
  • I have updated the code, but no result. see my question's update code again
    – localhost
    Commented Oct 2, 2016 at 6:36
  • It looks like both Sohel Rana and I identified the two things that were preventing proper function of your observer. Is everything working now? Commented Oct 2, 2016 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.