2

I'm trying to hook into the sales_order_place_after method in my observer and save information about the just placed order into a new database table. I'm able to hook into the event successfully, but when I try to access the order object, I keep getting the error User Error: Some transactions have not been committed or rolled back.

This is my config.xml:

  <sales_order_place_after>
    <observers>
      <myaction_save_order>
        <type>singleton</type>
        <class>mymodule/observer</class>
        <method>saveOrderIdToAttendees</method>
      </myaction_save_order>
    </observers>
  </sales_order_place_after>

This works fine. The problem I'm getting is in my observer:

public function saveOrderIdToAttendees($observer) {
    $this->getHelper()->log('Helloooo');

    $order = $observer->getEvent()->getOrder();

    $this->getHelper()->log($order);
}

For some reason I don't even have access to the getEvent() method. I've tried logging just the $observer->getEvent() object and that gives me the same error.

1
  • Can you add your entire config.xml Commented Oct 8, 2014 at 16:16

2 Answers 2

3

I suggest the event checkout_submit_all_after in this case. As far as a I know sales_order_place_after is triggered when you have placed an order using Multishipping but checkout_submit_all_after will always get triggered.

<global>
<events>
        <checkout_submit_all_after>
            <observers>
                <myaction_save_order>
                    <class>mymodule/observer</class>
                    <method>saveOrderIdToAttendees</method>
                </myaction_save_order>
            </observers>
        </checkout_submit_all_after>
    </events>
</global>

and use

 $order = $observer->getEvent()->getData('order');
5
  • Thank you! This worked for me. Just curious, is there any particular reason to take out the <type>singleton</type>?
    – ZeLoubs
    Commented Oct 8, 2014 at 16:58
  • magento.stackexchange.com/questions/34395/…
    – Amit Bera
    Commented Oct 8, 2014 at 17:00
  • hi you can use singleton
    – Amit Bera
    Commented Oct 8, 2014 at 17:02
  • @AmitBera will this event only trigger after payment process?
    – Anto S
    Commented Jul 30, 2015 at 6:38
  • no immediate after order place..
    – Amit Bera
    Commented Jul 30, 2015 at 6:48
2

Sounds like the observer is called before the order is actually saved to the database. Try sales_order_save_commit_after for an event which is called after the MySQL transaction has been completed.

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.