user3277150
user3277150

Reputation: 33

Trouble with Magento Observers

I'm new to magento, and am trying to make a simple extension that just takes an order, and creates a log. This is simply for testing purposes, and to help familiarize myself with magento. I'm not getting anything in my system.log... Here's the path to my config Test-Productorderlog-etc-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<config>
    <modules>
        <Test_Productorderlog>
            <version>0.0.1</version>
        </Test_Productorderlog>
    </modules>
    <frontend>
        <events>

            <sales_order_place_after>
                <observers>
                    <productorderlog>
                        <class>Test_Productorderlog_Model_Observers</class>
                        <method>sales_order_place_after</method>
                    </productorderlog>
                </observers>
            </sales_order_place_after>

        </events>
    </frontend>

    <global>
        <models>
            <Test_Productorderlog>
                <class>Test_Productorderlog_Model</class>
            </Test_Productorderlog>
        </models>
    </global>

</config>

My observer is the same path, but instead of the etc folder, Model

<?php
class Test_Productorderlog_Model_Observer {

public function sales_order_place_after(Varien_Event_Observer $observer)
     {
        $observer = $observer->getEvent()->getControllerAction()->getFullActionName();

       Mage::log('it works' , null , 'system.log');
    }

}

I have the Test_Productorderlog.xml set up with the following code. It shows up in my modules list in the admin.

<?xml version="1.0" encoding="UTF-8"?>

<config>
    <modules>
        <Test_Productorderlog>
            <active>true</active>
            <codepool>local</codepool>
        </Test_Productorderlog>
    </modules>
</config>

Not really sure what exactly my observer needs to be... Any help would be appreciated.

Upvotes: 0

Views: 35

Answers (2)

Fabian Schmengler
Fabian Schmengler

Reputation: 24551

Your configuration and observer is correct, but the module is not active. In the Test_Productorderlog.xml, the codePool element must have a capital P:

        <codePool>local</codePool>

instead of

        <codepool>local</codepool>

Upvotes: 1

Deepak Mankotia
Deepak Mankotia

Reputation: 4564

Try with Below configuration

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Test_Productorderlog>
            <version>0.0.1</version>
        </Test_Productorderlog>
    </modules>
    <global>
      <models>
          <productorderlog>
              <class>Test_Productorderlog_Model</class>
          </productorderlog>
      </models>
      <events>

          <sales_order_place_after>
              <observers>
                  <productorderlog>
                <type>singleton</type>
                      <class>productorderlog/observers</class>
                      <method>sales_order_place_after</method>
                  </productorderlog>
              </observers>
          </sales_order_place_after>

      </events>
    </global>
</config>

Let me know if you still have problem.

Upvotes: 0

Related Questions