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.

Sohel Rana
  • 35,846
  • 3
  • 72
  • 90
localhost
  • 249
  • 1
  • 4
  • 17

2 Answers2

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>
Sohel Rana
  • 35,846
  • 3
  • 72
  • 90
  • 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 Oct 02 '16 at 06:47
  • If you create a custom module, modules tag inside config.xml is the minimum requirement of creating new module. – Sohel Rana Oct 02 '16 at 07:04
  • @SohelRana Can i get help https://magento.stackexchange.com/q/284297/57334 – zus Aug 03 '19 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.

Shawn Abramson
  • 3,555
  • 1
  • 17
  • 22