sales_order_save_commit_after event triggered twice?
Try using sales_order_save_after
instead, it's triggered right after an order is saved in the database and returns the full order object
Why this event is triggered twice, I'm not sure. It's an an event triggered from Core/Model/Abstract.php
method afterCommitCallback
, seems that Magento is saving / committing 2 different data sets on the the Order model. Perhaps once the order itself and once the status history.
Is there any difference between the data being parsed on the 2 events that might give a clue to where it's called from?
If anyone is still having problem with this, I found out how magento deals with this.
In the called method you can take the order and set a flag on it.
Ex:
public function export(Varien_Event_Observer $observer) {
$order = $observer->getEvent()->getOrder();
if($order->getExportProcessed()){ //check if flag is already set.
return;
}
// your part of code
//"setExportProcessed" can be called anything you want as it's getting set magically by magento on our $order object.
$order->setExportProcessed(true);
}
In app/code/core/Mage/Cataloginventory/Model/Observer.php
function subtractQuoteInventory(Varien_Event_Observer $observer)
is an example of how magento deals with this.
I changed the event to sales_order_place_after
. This works fine.