5

What is the difference between the sales_order_invoice_register, sales_order_invoice_save_after and sales_order_place_after events?

I'd like to run a method after the payment capture for the invoice is carried out. Which event is best to hook to?

Thanks!

1
  • 1
    Did you manage to resolve your issue?
    – Sander Mangel
    Dec 10 '13 at 13:39
9

sales_order_invoice_save_after is triggered when the sales_order_invoice object is saved.

sales_order_invoice_register is an event in the class Mage_Sales_Model_Order_Invoice method register. This method is used to assign data about the invoice to the order.

I would suggest going with sales_order_invoice_save_after or, maybe even better: sales_order_invoice_pay since that method is called when the invoice is payed.

3
  • 1
    Be careful when using sales_order_invoice_save_after. It is triggered everytime, so if the invoice already exists, it is triggered when adding data or whatever. So check carefully that the invoice is in a state you want to have it to run whatever you want to run. You don't know whether the invoice is new. What you can do is adding a flag in the sales_order_invoice_save_before event to the invoice object and check for this flag, but sales_order_invoice_pay is better. At least if no third party modules didn't use pay() (no example, just my nightmare) Dec 7 '13 at 23:44
  • Good explain Sander
    – Amit Bera
    Jul 8 '14 at 1:59
  • 1
    fyi - sales_order_invoice_pay doesn't necessarily mean the order has been fully paid (there may be items not yet invoiced). If you need to check that the order is fully paid then you can use $observer->getEvent()->getInvoice()->getOrder()->$order->getBaseTotalDue() inside sales_model_invoice_pay. getBaseTotalDue() returns the outstanding balance on the order--so a zero return indicates the order is 100% paid.
    – STW
    Oct 1 '14 at 2:10
1

use sales_order_invoice_save_after as this event is triggered many times, so to avoid unnecessary execution you can check the requesting Module, Controller and Action if the condition is met than execute it. you can do it by using below code in your observer file.

$request        = Mage::app()->getRequest();
$moduleName     = $request->getModuleName();
$controllerName = $request->getControllerName();
$actionName     = $request->getActionName();
if ($moduleName != 'customer' && $controllerName != 'accout' && $actionName != 'login') {
    //your observer code here

}
1
  • This is a bad idea because invoices can be created by a payment extension too. In this case the controller & action will be different Aug 2 '17 at 9:51

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.