Magento – Failed opening ‘Mage/Sync/Model/Observer.php’ for inclusion

ce-1.7.0.2event-observerextensions

I am trying to make an extension containing an observer.

But magento search the model in mage instead of my local extension "Test". system.log tells me:

Failed opening 'Mage/Sync/Model/Observer.php' for inclusion

My /app/code/local/Test/Sync/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Test_Sync>
            <version>0.0.1</version>
        </Test_Sync>
    </modules>
    <global>
        <models>
            <test>
                <class>Test_Sync_Model</class>
            </test>
        </models>
    </global>
    <frontend>
        <events>
            <sales_order_save_commit_after>
                <observers>
                    <test_sales_order_save_commit_after>
                        <type>singleton</type>
                        <class>sync/observer</class>
                        <method>export</method>
                    </test_sales_order_save_commit_after>
                </observers>
            </sales_order_save_commit_after>
        </events>
    </frontend>
</config>

/app/code/local/Test/Sync/Model/Observer.php

class Test_Sync_Model_Observer {
    public function export($observer)
    {
      // code
    }
}

I checked file access and cleared all caches.

Why does he not use my observer?

Best Answer

The problem is so far not really related to the observer mechanism. It is a more basic problem.

When Magento tries to load files like Mage/Yourmodule/Model/Foo.php, this indicates that the lookup of the Magento class code (i.e. sync/observer or yourmodule/foo for my example) in Mage::getModel() (Magento calls getModel() internally when initializing the observer) did not work properly.

The code to be written in the <class> ... </class> node follows the same logic as you would pass it to getModel().

What you did is to define a mapping from test -> Test_Sync_Model. So if you use

<class>test/observer</class> Magento should properly use Test_Sync_Model_Observer.

But you actually might have intended to define the alias test_sync (which is more common). So in the models section it must be <test_sync> and in the observer <class>test_sync/observer</class>.

Related Topic