Multiple modules overriding same core file in Magento

Multiple modules overriding same core file in Magento

July 22, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Multiple modules overriding same core file in Magento

Handling Multiple Magento Modules Overriding the Same Core File

Magento is an incredibly flexible e-commerce platform that allows for extensive customization through its module system. However, one question that often arises among developers is: how does Magento handle situations where multiple modules try to override the same core file?

Understanding Magento Module Overrides

In Magento, modules can override core files using a feature called “plugin” overrides or “layout” overrides (for XML files). This mechanism allows you to modify the behavior of core functionality without directly editing the core code.

When a module defines an override for a core file, it is essentially redirecting the execution flow from the original core method to the overridden one. This means that Magento will first execute the original core method, and then immediately call the overridden method defined by your module.

The Override Priority

Magento uses a priority system to resolve conflicts between multiple modules overriding the same core file. The priority is determined by two factors:

  1. Module Order: By default, the order of modules in app/etc/modules/*.xml files defines the priority. Modules listed later in the <modules> section have higher priority.

  2. Priority Parameter: Each override can specify a numeric priority value. Higher priorities are executed first. If no priority is specified, Magento uses the module’s order as described above.

Example: Multiple Overrides for a Core File

Let’s consider an example where two modules—Vendor_Module1 and Vendor_Module2—both try to override the same core file Magento_Core/Model/ResourceModel/SomeModel.php.

Module 1 - Vendor_Module1

In its etc/module.xml, Vendor_Module1 defines an override with priority 10:

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Module1" setup_version="1.0.0">
        <!-- Other module configuration -->
        <sequence>
            <module name="Magento_Core"/>
        </sequence>
    </module>
</config>

It then includes an etc/di.xml file with the override definition:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\SomeModel">
        <plugin name="vendor_module1-override"
                type="Vendor\Module1\Model\Plugin"
                sortOrder="10"/>
    </type>
</config>

Module 2 - Vendor_Module2

Vendor_Module2 also defines an override, but with priority 5 in its etc/di.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\SomeModel">
        <plugin name="vendor_module2-override"
                type="Vendor\Module2\Model\Plugin"
                sortOrder="5"/>
    </type>
</config>

Resolving the Override Conflicts

When both modules are enabled, Magento will resolve the priority as follows:

  1. Vendor_Module1 has a higher priority of 10 compared to Vendor_Module2’s priority of 5.
  2. Therefore, Vendor_Module1’s override plugin is executed first.

This order ensures that the functionality defined in Vendor_Module1’s plugin will be executed before Vendor_Module2.

Conclusion

Magento’s module override system provides a powerful way to extend and modify core behavior without directly altering the original code. However, it requires careful management of priorities to avoid conflicts between multiple modules.

When designing your Magento extensions, always ensure that you define clear priority values in your overrides to prevent potential issues. Remember that higher numeric values indicate lower priority.

For more detailed information on Magento module development and best practices, I recommend visiting Laravel Company’s Magento resources for comprehensive guides and tutorials.

Extensions Themes Orders

Our network