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.

ZeLoubs
  • 67
  • 1
  • 8

2 Answers2

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');
Vivek Khandelwal
  • 392
  • 2
  • 18
Amit Bera
  • 77,456
  • 20
  • 123
  • 237
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.

Jonathan Hussey
  • 4,990
  • 1
  • 16
  • 25