Magento event sales_order_invoice_register is called multiple times

Magento event sales_order_invoice_register is called multiple times

October 4, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento event sales_order_invoice_register is called multiple times

Understanding Magento Invoice Events

In Magento, the sales_order_invoice_register event is triggered whenever an invoice is registered for an order. This event provides a hook that allows you to perform actions like sending custom emails after an invoice is created.

However, you’ve noticed that this event is being fired multiple times for the same invoice on some orders, resulting in your observer code executing and sending emails repeatedly. Let’s explore why this might happen and find a solution.

The register Function in Magento

The register function in Mage_Sales_Model_Order_Invoice is responsible for creating an invoice and triggering related events. However, it’s important to understand that this function can be called multiple times under certain circumstances:

  1. Cron jobs: If your cron job is configured to run the Magento sales_order_invoice_register event, it might trigger this event repeatedly if there are pending invoices.

  2. Observer priority: The order in which observers are executed (determined by their priorities) can also cause multiple invocations of the same event for a single invoice.

  3. Custom extensions: Third-party extensions or custom code could potentially call this function directly, bypassing the normal Magento flow and leading to duplicate events.

Ensuring Single Event Invocation

To ensure that your observer only executes once per invoice, you can implement a check in your observer method. Here’s how to do it:

public function observe($observer)
{
    $event = $observer->getEvent();
    $invoice = $event->getInvoice();

    // Check if the invoice has already been processed
    if ($this->_isProcessed($invoice)) {
        return;
    }

    // Your observer logic goes here

    // Mark the invoice as processed
    $this->_markAsProcessed($invoice);
}

private function _isProcessed($invoice)
{
    // Implement your own logic to check if an invoice has already been processed
    // This could involve checking a custom attribute or using Magento's event log
    return false; // Default to unprocessed
}

private function _markAsProcessed($invoice)
{
    // Implement your own logic to mark the invoice as processed
    // This could involve setting a flag in a custom table or updating an attribute
}

In this code, we add private methods _isProcessed and _markAsProcessed. The _isProcessed method should return true if the invoice has already been handled by your observer and false otherwise.

The _markAsProcessed method is responsible for updating the invoice’s state or creating a record to indicate that it has been processed. You need to implement these methods according to your specific requirements.

Best Practices

To minimize the chances of multiple event invocations, consider the following best practices:

  • Avoid calling the register function directly from your custom code.
  • Use Magento’s built-in event dispatching system for all related actions.
  • Ensure that your cron jobs are configured correctly and run at optimal intervals.
  • Check if any third-party extensions might be triggering this event unintentionally.

Conclusion

While it is possible for the sales_order_invoice_register event to be triggered multiple times, you can implement a simple check in your observer method to ensure single execution per invoice. By using a process-checking mechanism and marking invoices as processed after handling, you can prevent unnecessary email duplication caused by repeated event invocations.

Remember that this solution requires custom implementation for the _isProcessed and _markAsProcessed methods based on your specific requirements and Magento version. For more advanced techniques or if you’re using a recent Magento version (like 2.4), consider looking into Magento’s built-in event log features or implementing a distributed lock system.

Always test your solution thoroughly to ensure it works as expected in various scenarios. If you need further assistance or want to explore more advanced solutions, feel free to reach out to us at Laravel Company.

Happy coding!

Extensions Configuration Cron Email

Our network