0

I’m currently using the following code to update/save invoices & orders after creating a partial invoice.

$invoice->getOrder()->setIsInProcess(true);
Mage::getModel('core/resource_transaction')
    ->addObject($invoice)
    ->addObject($invoice->getOrder())
;
$invoice->save();
$order->save();

To me, it looks like both $invoice->save() & the adding an object to the resource transaction do the same thing.

Should I still be using both, or should I only use one or the other?

1

You should use it like this:

$invoice->getOrder()->setIsInProcess(true);
Mage::getModel('core/resource_transaction')
    ->addObject($invoice)
    ->addObject($invoice->getOrder())
    ->save()
;

It is somehow similar with

$invoice->save();
$order->save();

The only difference is that both saves are done inside a single transaction. So if something goes wrong when saving the order, the invoice will be rolled back also. If you call them separately there is a chance that the invoice save will work and the order save won't. In this case only the order will be rolled back. This leads to inconsistent data in your db.

  • if saving a collection of resource transactions, and one of them is an invoice with CAPTURE_ONLINE set, if as you say, one part fails and all of them are rolled back, what happens to the capture payment? – Zxurian Dec 5 '13 at 20:13
  • @Zxurian. I don't know. – Marius Dec 5 '13 at 20:29

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.