1

I have a transaction which saves 2 order objects. The benefit of which is obviously that if any fail then it is all rolled back.

However, there are associated objects which need to reference the ids of the newly created orders. What I am struggling with is how I can get the ids of the new orders without saving them? So that I can have everything in 1 single transactions. For example below i currently need 2 transactions:

$transaction = Mage::getModel('core/resource_transaction');
$transaction->addObject($orderA);
$transaction->addObject($orderB);
$transaction->save();

$transaction = Mage::getModel('core/resource_transaction');
$transaction->addObject($orderALog);
$transaction->addObject($orderBLog);
$transaction->save();
1

Each quote has a reserved order id as part of the quote. You can use that to find the eventual order. The column in the sales_flat_quote is 'reserved_order_id' In Magento 2 its found in the quote table with the same column. You should be able to access the value by something similar to:

$_reservedOrderId = $orderA->getData('reserved_order_id');

You could then try to load the order and see if it exists using that reserved_order_id, if it does the order was successfully saved and if not, it failed.

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.