Magento 1.8 – Why Magento Observer is Not Firing

event-observermagento-1.8model

I have truble with observer, don't know how to solve it!

Here is part of the config.xml and Observer.php files

Mycompany/Mymodule/etc/config.xml

<?xml version="1.0"?>    
<global>
        <models>
            <mymodule>
                <class>Mycompany_Mymodule_Model</class>
                <resourceModel>mymodule_mysql4</resourceModel>
            </mymodule>
            <mymodule_mysql4>
                <class>Mycompany_Mymodule_Model_Mysql4</class>
                <entities>
                    <mymodule>
                        <table>mymodule</table>
                    </mymodule>
                </entities>
            </mymodule_mysql4>
        </models>
        <events>
            <checkout_type_onepage_save_order_after>
                <observers>
                    <mycompany_mymodule_order_complete>
                        <class>mymodule/observer</class>
                        <method>mymoduleCompleteOrder</method>
                    </mycompany_mymodule_order_complete>
                </observers>
            </checkout_type_onepage_save_order_after>
       </events>
 </global>

Mycompany/Mymodule/Model/Observer.php

class Mycompany_Mymodule_Model_Observer 
{
    protected $_config;

    protected function _construct()
    {
        $this->_config = Mage::getModel('mymodule/config');
    }

    public function mymoduleCompleteOrder($observer)
    {...
      ....
    } 

Best Answer

I do not know what exactly problem you have, but I see one problem in your code.

In your observer you have _construct() method.

It is not the php constructor (php constructor has two underscores).

Also your observer does not extend Mage_Core_Model_Abstract which runs _construct()` method during object initialization.

So as a result _construct() will not be executed and protected $_config; will always be null.

If you use $this->_config in mymoduleCompleteOrder(), it can generate error, and your code is not executed correctly.

Related Topic