0

I have set an event-observer in my custom module but observer is not getting called. i have enabled my log and i am getting this warning :

2013-08-14T11:17:48+00:00 ERR (3): Warning: include(Mage/CompanyName/ModuleName/Model/Observer.php): failed to open stream: No such file or directory  in /var/www/nyp/lib/Varien/Autoload.php on line 93
2013-08-14T11:17:48+00:00 ERR (3): Warning: include(): Failed opening 'Mage/CompanyName/ModuleName/Model/Observer.php' for inclusion (include_path='/var/www/nyp/app/code/local:/var/www/nyp/app/code/community:/var/www/nyp/app/code/core:/var/www/nyp/lib:.:/usr/share/php:/usr/share/pear')  in /var/www/nyp/lib/Varien/Autoload.php on line 93

Code in my config.xml to attach event and observer :

<global>
    <events>
        <sales_order_place_after>
            <observers>
                <CompanyName_ModuleName_Observer>
                    <type>singleton</type>
                    <class>CompanyName_ModuleName/observer</class>
                    <method>methodName</method>
                </CompanyName_ModuleName_Observer>
            </observers>
        </sales_order_place_after>
    </events>
 <global>

Code in my CompanyName/ModuleName/Model/Observer.php :

<?php

class CompanyName_ModuleName_Model_Observer
{
    public function __contruct()
        {

        }

    public function methodName(Varien_Event_Observer $observer)
    {

    }
}

Thanks,

4 Answers 4

4

Based on the class group you are using (CompanyName_ModuleName) you should use:

<global>
    <models>
        <CompanyName_ModuleName>CompanyName_ModuleName_Model</CompanyName_ModuleName>
    </models>
</global>
5
  • Hello benamrks when i gave the observer class directly into the config.xml it starts working but now the problem is - when the customer place order (Completes the last step of checkout) it goes to cart page again. Is it something i like i am using wrong event ? i just want to add some functionality after the order is placed successfully.
    – Sarvagya
    Commented Aug 14, 2013 at 12:11
  • Likely an error with your code, unless the methodName method is empty as above - then it's something else.
    – benmarks
    Commented Aug 14, 2013 at 12:13
  • I need to know when we use this event does it makes the method run with existing event or it stops the existing method and makes the new one running.
    – Sarvagya
    Commented Aug 14, 2013 at 12:23
  • I suppose you could say that it sidesteps, but then steps back (passively). See Mage_Core_Model_App::dispatchEvent().
    – benmarks
    Commented Aug 14, 2013 at 12:33
  • Hello benamarks many many thanks for guiding me. finally i got it working the problem was due to compiler. Compiler was enabled when i disabled it everything starts working. Do you Know why it happened ? i mean why enabling the compiler breaks the functionality.
    – Sarvagya
    Commented Aug 14, 2013 at 13:02
3

It seems you have an error here:

<class>CompanyName_ModuleName/observer</class>

Everything prior to the slash is lowercased in using the model shorthand notation, and rarely should contain an underscore. This would be the shortname you provided when doing your setup of your module:

<global>
    <models>
        <yourmodel>CompanyName_ModuleName_Model</yourmodel>
    </models>
</global>

If you didn't define this, no worries. Use the fully-qualified path:

<class>CompanyName_ModuleName_Model_Observer</class>
2

I think this post should help you.

In your case it would be something like this:

<global>
    <events>
        <sales_order_place_after>
            <observers>
                <modulename_observername>
                    <type>singleton</type>
                    <class>modulename/observer</class>
                    <method>methodName</method>
                </modulename_observername>
            </observers>
        </sales_order_place_after>
    </events>
    <models>
        <modulename>
            <class>CompanyName_ModuleName_Model</class>
        </modulename>
    </models>
 <global>
0

cofig code would be like this.

<events>
          <core_block_abstract_prepare_layout_before>
               <observers>
                   <companyname_jquery_prepare_layout_before>
                       <class>modulename/observer</class>
                       <method>prepareLayoutBefore</method>
                   </companyname_jquery_prepare_layout_before>
               </observers>
           </core_block_abstract_prepare_layout_before>
</events>

this will sure help you to get better idea about how observer work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.