Magento - 2 or more observer on same event

Magento - 2 or more observer on same event

July 22, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento - 2 or more observer on same event

Magento: Resolving Multiple Observers for the Same Event

When working with multiple Magento modules observing the same event, you may encounter situations where only one observer is called while others are ignored. In your case, both ModuleA and ModuleB observe the sales_order_shipment_save_before event, but only ModuleB’s observer is triggered.

Understanding the Issue

Magento’s event system uses a queue of observers for each event. If multiple observers are registered for the same event, Magento processes them in the order they were declared in the configuration file. In your scenario, since you created ModuleA first and then ModuleB, the configuration order has changed.

Resolving the Problem

To ensure both observers (ModuleA and ModuleB) are called for the sales_order_shipment_save_before event, you need to adjust the configuration files.

Step 1: Modify Module A’s Configuration XML

Update your ModuleA’s XML configuration file (e.g., config.xml) by adding a <sort_order> attribute to the observer node. This will ensure Magento processes ModuleA’s observer before ModuleB’s.

<adminhtml>
    <events>
        <sales_order_shipment_save_before>
            <observers>
                <shipmentsave>
                    <type>singleton</type>
                    <class>My_Shipmentsave_Model_Observer</class>
                    <method>salesOrderShipmentSaveBefore</method>
                    <sort_order>10</sort_order>  <!-- Add this line -->
                </shipmentsave>
            </observers>
        </sales_order_shipment_save_before>
    </events>
</adminhtml>

Step 2: Modify Module B’s Configuration XML

Similarly, update your ModuleB’s XML configuration file (e.g., config.xml) by adding a <sort_order> attribute to the observer node. In this case, set the sort order higher than ModuleA to maintain the desired processing sequence.

<adminhtml>
    <events>
        <sales_order_shipment_save_before>
            <observers>
                <shipmentsave>
                    <type>singleton</type>
                    <class>My_Bshipment_Model_Observer</class>
                    <method>salesOrderShipmentSaveBefore</method>
                    <sort_order>20</sort_order>  <!-- Add this line -->
                </shipmentsave>
            </observers>
        </sales_order_shipment_save_before>
    </events>
</adminhtml>

Step 3: Re-index and Clear Cache

After updating the configuration files, re-index your Magento database and clear all cached data:

  1. Navigate to System > Index Management.
  2. Select every index in the list.
  3. Click the Reindex All button.

Next, clear the cache:

  • Go to System > Cache Management.
  • Select every cache option available.
  • Click the Flush Cache Magically button or manually select and delete each cache entry.

Conclusion

By following the steps above, you should now have both observers (ModuleA and ModuleB) called in the desired order for the sales_order_shipment_save_before event. This approach ensures that Magento processes each observer correctly based on the specified sort orders in the configuration files.

Extensions Admin Configuration Orders

Our network