1

I trying to execute my second observer which reacts to when Place order button has been clicked (sales_order_place_event). My first observer running good but second observer isn't. Could anybody tell me why? what am i doing wrong here?
config.xml

<events>
    <controller_front_init_before>
        <observers>
            <test_capture>
                <class>Foo_Test_Model_Observer</class>
                <method>capture</method>
                <type>singleton</type>
            </test_capture>
        </observers>
    </controller_front_init_before>
    <sales_order_place_after>
        <observers>
            <test_order>
                <class>Foo_Test_Model_Observer</class>
                <method>order</method>
                <type>singleton</type>
            </test_order>
        </observers>
    </sales_order_place_after>
</events>

Observer.php

class Foo_Test_Model_Observer {

    public function capture(Varien_Event_Observer $observer) {
        /*some code*/

    }

    public function order(Varien_Event_Observer $observer){

        echo __LINE__;exit;

    }
}

I tried to put my method in <controller_front_init_before> and run.. it works but my <sales_order_place_after> is not working

  • 1
    children tag of <observers> must unique. – Thao Pham Nov 24 '15 at 11:07
  • fyi i am using third party extension for onepagecheckout and whenever i am clikcing on place order nothing hapening. – Akash Nov 24 '15 at 11:11
  • I think can third party extension conflict with your theme. – Thao Pham Nov 24 '15 at 11:12
  • but orders are being added in backend – Akash Nov 24 '15 at 11:18
  • because in function order of you, you using exit, so orders are being added in backend – Thao Pham Nov 24 '15 at 11:29
1

It happens in an ajax request, so you don't see the "echo" output in the frontend. If you inspect the response in the browser console you should see it.

I recommend to set up xdebug for step by step debugging. Then you can use a breakpoint instead of echo and exit. You also get information at runtime about variables and the call stack. It's really worth the initial effort.

-1

You have set the same observer name: "test". Try changing xml like this:

<events>
        <controller_front_init_before>
            <observers>
                <test>
                    <class>Foo_Test_Model_Observer</class>
                    <method>capture</method>
                    <type>singleton</type>
                </test>
            </observers>
        </controller_front_init_before>
        <sales_order_place_after>
            <observers>
                <test_order>
                    <class>Foo_Test_Model_Observer</class>
                    <method>order</method>
                    <type>singleton</type>
                </test_order>
            </observers>
        </sales_order_place_after>
    </events>
-1

Try this:
config.xml

<events>
    <controller_front_init_before>
        <observers>
            <foo_test_capture>
                <class>Foo_Test_Model_Observer</class>
                <method>testCapture</method>
            </foo_test_capture>
        </observers>
    </controller_front_init_before>
    <sales_order_place_after>
        <observers>
            <foo_test_order>
                <class>Foo_Test_Model_Observer</class>
                <method>testOrder</method>
            </foo_test_order>
        </observers>
    </sales_order_place_after>
</events>

Observer.php

class Foo_Test_Model_Observer
{

    public function testCapture(Varien_Event_Observer $observer) {
        echo 'testCapture';die;

    }

    public function testOrder(Varien_Event_Observer $observer){

        echo 'testOrder';die;

    }
}
  • not working.... – Akash Nov 24 '15 at 11:41
  • have you checked one event? Is working? suppose <events> <sales_order_place_after> <observers> <foo_test_order> <class>Foo_Test_Model_Observer</class> <method>testOrder</method> </foo_test_order> </observers> </sales_order_place_after> </events> – Abdul Nov 24 '15 at 11:53
  • yes tried . I think what @Paw said bout conflicting is right. – Akash Nov 24 '15 at 12:06
  • single event working or not? I thinks event "sales_order_place_after" use any other module. – Abdul Nov 24 '15 at 12:10
  • no single event <sales_order_place_after> not working. – Akash Nov 24 '15 at 12:12

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.