How do I override a Magento Core module?

How do I override a Magento Core module?

September 25, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How do I override a Magento Core module?

Overriding Magento Core Modules: A Detailed Guide

The Magento platform offers great flexibility through its module architecture. However, modifying core files directly can lead to issues during upgrades or cause conflicts with other customizations. To avoid this, we’ll show you how to properly override the Order/Sales table and PDF generation code in your admin interface using a local extension.

Understanding Magento’s Layout and Override Mechanisms

Magento follows a principle of “Don’t modify core files.” Instead, it allows you to extend or override existing functionality through modules. This is achieved by following specific naming conventions for your module files that mirror the core structure.

The Core Module Structure: core/Mage/Sales

Before we begin, let’s understand the structure of the core Sales module:

core
└── Mage
    └── Sales
        ├── Block
        │   ├── Adminhtml
        │   │   └── Order
        │   │       └── Grid.php
        │   └── Item.php
        ├── Controller
        │   ├── Adminhtml
        │   │   └── OrderController.php
        │   └── OrderController.php
        ├── Helper
        │   ├── Data.php
        │   └── Order.php
        ├── Model
        │   ├── Observer.php
        │   └── Resource
        │       └── Setup.php
        └── etc
            └── config.xml

Creating a Local Extension to Override Core Files

To override the core files, we create an extension with the same directory structure and file names as the core module.

Step 1: Create your local extension folder

app
└── code
    ├── local
        └── Mage
            └── Sales
                ├── Block
                │   ├── Adminhtml
                │   │   └── Order
                │   │       └── Grid.php
                │   └── Item.php
                ├── Controller
                │   ├── Adminhtml
                │   │   └── OrderController.php
                │   └── OrderController.php
                ├── Helper
                │   ├── Data.php
                │   └── Order.php
                ├── Model
                │   ├── Observer.php
                │   └── Resource
                │       └── Setup.php
                └── etc
                    └── config.xml

Step 2: Override the specific files

Let’s say we want to override the Adminhtml_OrderController.php file. We create a new local version in our extension folder:

local
└── Mage
    └── Sales
        ├── Controller
        │   ├── Adminhtml
        │   │   └── OrderController.php  // [Core]
        │   └── OrderController.php     // [Local override]

Step 3: Modify the local override file

In your overridden OrderController.php, you can now modify the core behavior. For example, to change the order grid view in the admin interface:

// app/code/local/Mage/Sales/Controller/Adminhtml/OrderController.php

class Mage_Sales_Adminhtml_OrderController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
        $this->_title($this->__('Sales'))->_title($this->__('Orders'));

        // Add your custom modifications here...

        $this->_initAction();
        $this->renderLayout();
    }
}

Configuring Your Override in the config.xml File

The config.xml file is crucial for Magento to recognize your overriding module. You need to specify the modules that you want to replace and the priority of your extension.

Step 1: Create a new configuration file

Create a new config.xml file inside your local Sales extension’s etc folder:

local
└── Mage
    └── Sales
        └── etc
            └── config.xml   // [New]

Step 2: Define the module and override rules

Inside this file, define your module details and specify the modules you want to replace.

<?xml version="1.0"?>
<config>
    <modules>
        <Mage_Sales>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_All locale="en_US">
                    <depends/>
                </Mage_All>
            </depends>
        </Mage_Sales>
    </modules>

    <global>
        <!-- Replace the Sales module with your local version -->
        <models>
            <sales>
                <class>Mage_Sales_Model</class>
                <resourceModel>sales_resource</resourceModel>
            </sales>
            <sales_resource>
                <class>Mage_Sales_Model_Resource</class>
                <entities>
                    <!-- Override existing entities -->
                    <order>
                        <table>sales_flat_order</table>
                    </order>
                </entities>
            </sales_resource>
        </models>

        <blocks>
            <sales>
                <rewrite>
                    <!-- Overwrite the core blocks with your local versions -->
                    <adminhtml_order_grid>Mage_Sales_Block_Adminhtml_Order_Grid</adminhtml_order_grid>
                    <!-- Add more rewrites as needed -->
                </rewrite>
            </sales>
        </blocks>

        <resources>
            <sales_setup>
                <setup>
                    <module>Mage_Sales</module>
                    <version>1.0.0.0</version>
                </setup>
            </sales_setup>
        </resources>
    </global>
</config>

Conclusion: Overriding Core Modules Safely and Effectively

By following this approach, you’ve successfully overridden the Order/Sales table in your admin interface without directly modifying core files. This ensures that your customizations are preserved during upgrades and reduces the risk of conflicts with other extensions.

Remember to clear the cache after making changes:

php magento cache:clean

If you’re looking for more advanced techniques or need help with specific Magento development challenges, visit Laravel Company’s Magento Development Services page. Our experienced team is ready to assist you in building and maintaining high-performing e-commerce solutions.

Database Extensions Themes Admin

Our network