0
votes

I've followed a tutorial, but my observer isn't catching events. I know the events are firing because I'm logging them. I can't find the error in my code.

/local/Package/MODULE/etc/config.xml

<config>
<modules>
    <Package_MODULE>
        <version>0.1.0</version>
    </Package_MODULE>
</modules>

<global>
    <models>
        <module>
            <class>Package_MODULE_Model</class>
        </module>
    </models>
    <events>
            <catalog_product_gallery_upload_image_after>
                    <observers>
                            <module_model_upload>
                                    <type>model</type>
                                    <class>module/observer</class>
                                    <method>printTestMessage</method>
                            </module_model_upload>
                    </observers>
            </catalog_product_gallery_upload_image_after>
    </events>

</global>
</config>

/local/Package/MODULE/Model/Observer.php

<?php

class Package_MODULE_Model_Observer{
    public function printTestMessage(Varien_Event_Observer $observer){
             Mage::log("TESTING ", null, 'events.log');  //<--same log statement I'm using to test the events firing
    }
}

/etc/modules/Package_MODULE.xml

<config>
<modules>
    <Package_MODULE>
        <active>true</active>
        <codePool>local</codePool>
    </Package_MODULE>
</modules>
</config>

EDIT2: This error shows up in system.log:

2013-02-14T17:10:21+00:00 ERR (3): Notice: Uninitialized string offset: 3  in /opt/bitnami/apps/magento/htdocs/includes/src/Varien_File_Uploader.php on line 538
2013-02-14T17:10:21+00:00 ERR (3): Warning: include(/opt/bitnami/apps/magento/htdocs/includes/src/Package_MODULE_Model_Observer.php): failed to open stream: No such file or directory  in /opt/bitnami/apps/magento/htdocs/includes/src/Varien_Autoload.php on line 93
2013-02-14T17:10:21+00:00 ERR (3): Warning: include(): Failed opening '/opt/bitnami/apps/magento/htdocs/includes/src/Package_MODULE_Model_Observer.php' for inclusion (include_path='/opt/bitnami/apps/magento/htdocs/includes/src:.:/opt/bitnami/php/lib/php')  in /opt/bitnami/apps/magento/htdocs/includes/src/Varien_Autoload.php on line 93
2
The model definition in XML should only contain module name, and not module_model.. <module> instead of <module_model> - Kalpesh
@KalpeshMehta I made the change. Still nothing happens. - swl1020
Some stupid question, but : - are you sure log is enabled ? - does the events.log files exists with writeable permission ? if No is the log directory writable to allow new file creation ? - have you tried simply Mage::log('test'); ? - dagfr
@dagfr Yes the logging is working. I have noticed something in system.log. I'll post it in the question. - swl1020
Ok, we notice 2 things in your error log. 1 compilation is enabled, did you recompile your code ? 2. you see the error described by @KalpeshMetha 2 times Model - dagfr

2 Answers

3
votes

Check the include warning... This is due to the compiler being enabled but your class hasn't been compiled.

I've answered this question probably more times than I can count: disable the compiler or recompile.

0
votes

You have the wrong class name in the configuration for your observer. <class>module_model/observer</class> doesn't want the _model in it. The class alias for the model Package_MODULE_Model_Observer is module/observer.