1

Hi I need help with the following

I created a new method in for sales/model/observer.php as follows

class Company_Sales_Model_Observer
{

    public function addid(Varien_Event_Observer $observer)
    {
       <code to write in the log file>
    }
}

There is already another method registered in the config.xml file as follows

   <events>
        <sales_order_save_commit_after>
            <observers>
                <company_sales>
                    <type>singleton</type>
                    <class>company_sales/observer</class>
                    <method>processEbook</method>
                </company_sales>
            </observers>
        </sales_order_save_commit_after>
    </events>

I added the following code in the sales/etc/config.xml after the existing method registration as follows

    <events>
        <sales_order_save_commit_after>
            <observers>
                <company_sales>
                    <type>singleton</type>
                    <class>company_sales/observer</class>
                    <method>processEbook</method>
                </company_sales>
            </observers>
        </sales_order_save_commit_after>
        <sales_order_save_after>
            <observers>
                <company_sales>
                    <type>singleton</type>
                    <class>company_sales/observer</class>
                    <method>addid</method>
                </company_sales>
            </observers>
        </sales_order_save_after>
    </events>

But it is not calling the method. Where am I going wrong? Please help

Thanks!

Update: What if I want to create the method addid with the event sales_order_save_commit_after as the method ProcessEbook. How will I go about it. Thank you for your answer!

  • just change the event name you have use company_sales two time just put unique name for each events – Amit Bera Oct 9 '14 at 2:02
  • also put config.xml on this question – Amit Bera Oct 9 '14 at 2:04
  • for second sales_order_save_commit_after event change company_sales to other name – Amit Bera Oct 9 '14 at 5:44
3

If you look at your config.xml file you will find duplicate observer tag names . These names must be unique, otherwise magento will only the first one it finds. Please change it to something unique. A good approach is to use namespace in your tag names. Thanks.

You can do it in the following way,

<sales_order_save_commit_after>
            <observers>
                <company_sales>
                    <type>singleton</type>
                    <class>company_sales/observer</class>
                    <method>processEbook</method>
                </company_sales>
                <company_sales_addid>
                    <type>singleton</type>
                    <class>company_sales/observer</class>
                    <method>addid</method>
                </company_sales_addid>
            </observers>
        </sales_order_save_commit_after>

Please notice the tag <company_sales_addid>. The name of this tag must be unique. Otherwise it won't work.

Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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