I have a custom function that creates a PDF file, which is triggered for the event sales_order_save_after. But why this function is triggered twice, I got 2 PDFs everytime for the same order.

If I use sales_order_place_after, then the function is only triggered once. So this fix my problem.

But my question is why sales_order_save_after is triggered twice in Magento?


1 Answer 1


It's possible one of your Payment modules or something may be saving the order as well, causing the twice save.

I've solved this personally in the following way (you could use it in your pdf generator, assuming it's in observer?

class Your_Module_Model_Observer

   public $eventComplete = false;

   function sales_quote_collect_totals_after()


    $this->eventComplete = true;

    // pdf code here
  • Thanks, I tried your code, and the event is triggered once. but I also fixed this by using the event sales_order_place_after, which is also triggered only once, as I mentioned in the question. It's the same right? Commented Aug 25, 2017 at 13:49
  • Yeah, I beleive you can do things like $order->save(); in code, for example you load the order, change shipping then save it. Then load again, add payment, save it. Place is when the order has been literally placed so different from saves. Commented Aug 25, 2017 at 14:04
  • I actually noticed that when the event sales_order_save_after triggered twice, the two PDFs are not the same. the first one doesn't include the customer note (order comment) where the second one include the customer note. Is it possible to only get the second one with the customer note? with sales_order_place_after or your code above, I can only get the first PDF without customer note. Commented Aug 25, 2017 at 15:13
  • Hmm, maybe try declaring $eventComplete as 0, then increment it in the function $this->eventComplete++; then you can check for value of it, e.g. if not == 1 then return false. Commented Aug 30, 2017 at 12:05
  • 1
    I confirm that the same problem exists in Magento 2 and this solution solved it for me. Commented Mar 21, 2018 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.