Event Observer – sales_order_creditmemo_save_after Triggers sales_order_invoice_save_after

event-observer

I have an observer listening for events that fire sales_order_creditmemo_save_after. The issue I have is that when a credit memo is saved on the invoice, the sales_order_invoice_save_after event is also fired – which causes issues with my code, because I also have another observer listening on that event.

For the observer listening on sales_order_invoice_save_after – is there a way to distinguish whether the event was a credit memo or an invoice?

I have found deep down in the $observer object, protected '_historyEntityName' => string 'creditmemo' (length=10) however is there a more standard way to access this information?

Best Answer

The work around was to add a conditional check on the sales_order_invoice_save_after to look for the order status label. Because I only needed the observer to work when the order status was 'Processing', I was able to use:

if ($order->getStatusLabel() == 'Processing')

However I am yet to find a way to access protected '_historyEntityName' => string 'creditmemo' (length=10) in the observer object.