2

I have a working observer using sales_order_place_after and I am changing it to use sales_order_invoice_pay. Is this is the correct method? Will this to fire only if the invoice is fully paid, front-end or admin? My test seems to indicate this is correct but I'd appreciate a look.

in Observer.php

   $invoice = $observer->getEvent()->getInvoice();
   $order = $invoice->getOrder();
        if (!$order->canInvoice() ) {
            Mage::getModel('myapps_orderman/export_mscrmapi') 
            ->exportOrder($order);
        }
2

Hard question. theoretically should all payment methods use $order->pay() to mark the order as pays and create an invoice. I would use this, sales_order_invoice_pay.

If you want to be really sure, no one sets the order beside this method to paid, you can flag the order in the sales_order_load_after event, if it is not yet paid and check for the flag in the sales_order_save_after event, whether it is now paid. Additionally you can check whether the grand_total and the total_paid is the same.

But I recommend to use sales_order_invoice_pay.

  • I'll be managing payment methods added to the Magento defaults and can check them. This works for me. – Dan Dec 8 '13 at 14:21
  • I am running into a situation where the data collected in the order by a third party extension sometimes is there at the time of the sales_order_invoice_pay and sometimes not there. When I used sales_order_place_after the data was always there. I am asking the developers when they save the data, I'm thinking that they have an event that fires sometime before mine and sometimes after. The data is in the order moments later but not always at the time the event fires my observer. Does this seem like a reasonable path for investigation? – Dan Dec 10 '13 at 17:59
  • Just check whether they observer the same event in their config.xml if yes, you can add a <depends> node in your Company_Module.xml to catch the event after the payment module. But normally the order doesn't change. So either they catch and then your observer catches or the other way around – Fabian Blechschmidt Dec 10 '13 at 18:56

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.