3

I need to send email with PDF attachment when the order payment is done or when the order status is changed to complete..however i can't find any event related to completion of order ...mails are being sent for order placing or shipment etc but not on order complete...Any help will be appreciated.

2

Use the observer "sales_order_save_commit_after" or "sales_order_invoice_pay" then you can get the order status and depending on the status you do what you want. Here is an example:

// for event sales_order_save_commit_after
public function sendpdf($observer)
{
    $order = $observer->getOrder();
    if($order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE){
    // do your order complete stuff
    }
}

or

// Event sales_order_invoice_pay
public function sendpdf ($observer)
{
    $invoice = $observer->getEvent()->getInvoice();
    switch ($invoice->getState()) {
        case Mage_Sales_Model_Order_Invoice::STATE_PAID :
            //do your stuff
            break;
    }
    return $this;
}

You will have to check that you don't do the calculation twice, because this method is triggered each time an order is saved. reference

| improve this answer | |
  • On sales_order_invoice_pay, I want to change order state back to 'new', but it goes new then processing. Any ideas? – Ricky Odin Matthews Sep 29 '17 at 10:22

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.