Magento: Add New Column to Sales Order Grid in Admin

This article shows how you can add new columns to sales order grid in Magento 1.x admin.

For this, you need to rewrite/override the Adminhtml’s sales_order_gird block class.

Here is the block override code to be written in your module’s config.xml file:

YourCompany/YourModule/etc/config.xml


<global>
    <blocks>
        <yourmodule>
            <class>YourCompany_YourModule_Block</class>
        </yourmodule>
        <adminhtml>
            <rewrite>
                <sales_order_grid>YourCompany_YourModule_Block_Adminhtml_Sales_Order_Grid</sales_order_grid>
            </rewrite>
        </adminhtml>
    </blocks>
</global>

Now, you need to create a new class file that overrides the sales_order_grid adminhtml class. The code below shows how to display two columns in the sales order grid. The two columns fetches data from fields custom_status and custom_message. These two fields are manually added to the sales order table.

YourCompany/YourModule/Block/Adminhtml/Sales/Order/Grid.php


<?php
class YourCompany_YourModule_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{
    protected function _prepareColumns()
    {
        // your own options, you may edit it as you need
        $options = array(
                        'Confirmed' => 'Confirmed',
                        'Waiting' => 'Waiting',
                        'Postponed' => 'Postponed',
                    ); 
                        
        $this->addColumn('custom_status', array(
            'header'    =>  Mage::helper('customer')->__('Custom Status'),
            'width'     =>  '150px',
            'index'     =>  'custom_status',
            'type'      =>  'options',
            'options'   =>   $options, 
            //'renderer'  => 'YourCompany_YourModule_Block_Adminhtml_Sales_Order_Grid_Renderer_CustomStatus',           
        ));
        
        // add column after grand_total column
        $this->addColumnsOrder('custom_status', 'grand_total'); 
        
        $this->addColumn('custom_message', array(
            'header'    =>  Mage::helper('customer')->__('Custom Message'),
            'width'     =>  '150px',
            'index'     =>  'custom_message',
            'type'      =>  'text',            
        ));
        
        // add column after grand_total column
        $this->addColumnsOrder('custom_message', 'grand_total'); 
        
        return parent::_prepareColumns();
    }
}
?>

Now, clear cache from Magento admin (System -> Cache Management).

That all. Now, you should be able to see two new columns in Sales Order Grid in your Magento admin (Sales -> Orders).

Hope this helps. Thanks.