How to extend Magento Order Grid?

Here is small example which explains how to modify order grid. Main class for order grid is “Mage_Adminhtml_Block_Sales_Order_Grid”, if you want to add some column you have to rewrite this class (block).

How to rewrite magento block:


If you call block “adminhtml/sales_order_grid”, you will get Inchoo_Test_Block_Adminhtml_Order_Grid of course you need to create your class Inchoo_Test_Block_Adminhtml_Order_Grid.

This is example of our block Inchoo_Test_Block_Adminhtml_Order_Grid:

< ?php
class Inchoo_Test_Block_Adminhtml_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
     public function __construct()
     * Retrieve collection class
     * @return string
    protected function _getCollectionClass()
        return 'sales/order_grid_collection';
    protected function _prepareCollection()
        $collection = Mage::getResourceModel($this->_getCollectionClass());
        //we changed mysql query, we added inner join to order item table
        $collection->join('sales/order_item', 'order_id=entity_id', array('name'=>'name', 'sku' =>'sku', 'qty_ordered'=>'qty_ordered' ), null,'left');
        return parent::_prepareCollection();
    protected function _prepareColumns()
        $this->addColumn('real_order_id', array(
            'header'=> Mage::helper('sales')->__('Order #'),
            'width' => '80px',
            'type'  => 'text',
            'index' => 'increment_id',
        if (!Mage::app()->isSingleStoreMode()) {
            $this->addColumn('store_id', array(
                'header'    => Mage::helper('sales')->__('Purchased from (store)'),
                'index'     => 'store_id',
                'type'      => 'store',
                'store_view'=> true,
                'display_deleted' => true,
                'filter_index' => 'main_table.store_id'
        $this->addColumn('created_at', array(
            'header' => Mage::helper('sales')->__('Purchased On'),
            'index' => 'created_at',
            'type' => 'datetime',
            'width' => '100px',
            'filter_index' => 'main_table.created_at'
        $this->addColumn('billing_name', array(
            'header' => Mage::helper('sales')->__('Bill to Name'),
            'index' => 'billing_name',
        $this->addColumn('qty_ordered', array(
            'header'    => Mage::helper('sales')->__('Items Ordered'),
            'index'     => 'qty_ordered',
            'type'      => 'number',
            'total'     => 'sum'
        $this->addColumn('sku', array(
            'header'    => Mage::helper('catalog')->__('SKU'),
            'index'     => 'sku',
			'type' => 'text'
        $this->addColumn('base_grand_total', array(
            'header' => Mage::helper('sales')->__('G.T. (Base)'),
            'index' => 'base_grand_total',
            'type'  => 'currency',
            'currency' => 'base_currency_code',
        $this->addColumn('grand_total', array(
            'header' => Mage::helper('sales')->__('G.T. (Purchased)'),
            'index' => 'grand_total',
            'type'  => 'currency',
            'currency' => 'order_currency_code',
        $this->addColumn('status', array(
            'header' => Mage::helper('sales')->__('Status'),
            'index' => 'status',
            'type'  => 'options',
            'width' => '70px',
            'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
        return $this;
    protected function _prepareMassaction()
        if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/cancel')) {
            $this->getMassactionBlock()->addItem('cancel_order', array(
                 'label'=> Mage::helper('sales')->__('Cancel'),
                 'url'  => $this->getUrl('*/sales_order/massCancel'),
        if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/hold')) {
            $this->getMassactionBlock()->addItem('hold_order', array(
                 'label'=> Mage::helper('sales')->__('Hold'),
                 'url'  => $this->getUrl('*/sales_order/massHold'),
        if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/unhold')) {
            $this->getMassactionBlock()->addItem('unhold_order', array(
                 'label'=> Mage::helper('sales')->__('Unhold'),
                 'url'  => $this->getUrl('*/sales_order/massUnhold'),
        $this->getMassactionBlock()->addItem('pdfinvoices_order', array(
             'label'=> Mage::helper('sales')->__('Print Invoices'),
             'url'  => $this->getUrl('*/sales_order/pdfinvoices'),
        $this->getMassactionBlock()->addItem('pdfshipments_order', array(
             'label'=> Mage::helper('sales')->__('Print Packingslips'),
             'url'  => $this->getUrl('*/sales_order/pdfshipments'),
        $this->getMassactionBlock()->addItem('pdfcreditmemos_order', array(
             'label'=> Mage::helper('sales')->__('Print Credit Memos'),
             'url'  => $this->getUrl('*/sales_order/pdfcreditmemos'),
        $this->getMassactionBlock()->addItem('pdfdocs_order', array(
             'label'=> Mage::helper('sales')->__('Print All'),
             'url'  => $this->getUrl('*/sales_order/pdfdocs'),
        return $this;
    public function getRowUrl($row)
        if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
            return $this->getUrl('*/sales_order/view', array('order_id' => $row->getId()));
        return false;
    public function getGridUrl()
        return $this->getUrl('*/*/grid', array('_current'=>true));

If you want to add some column you need to add next code in method: _prepareColumns

$this->addColumn('sku', array(
'header'    => Mage::helper('catalog')->__('SKU'),
'index'     => 'sku',
'type' => 'text'

Also you will notice that we modified method: _prepareCollection(), we changed SQL query, we made inner join to second database table in order to get data from second database table. This is our working example and your SQL query you can modify as you wish.

You made it all the way down here so you must have enjoyed this post! You may also like:

Magento Grid Serializer for Ajax Grids Damir Korpar
Damir Korpar, | 10

Magento Grid Serializer for Ajax Grids

Show product thumbnail in grids Petar Sambolek
Petar Sambolek, | 14

Show product thumbnail in grids

Filter order grid by multiple ID’s Petar Sambolek
Petar Sambolek, | 13

Filter order grid by multiple ID’s


  1. I want to change the csv file when downloaded. But I dont know how to override the function getCsv() in core/Mage/Adminhtml/Block/Report/Grid.php? Please help

  2. Or you could used this instead :
    protected function _prepareCollection()
    $collection = Mage::getResourceModel($this->_getCollectionClass());

    //we changed mysql query, we added inner join to order item table
    $collection->join(‘sales/order_item’, ‘order_id=entity_id’, array(‘name’=>’name’, ‘sku’ =>’sku’, ‘qty_ordered’=>’qty_ordered’ ), null,’left’);
    return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();

    like that you will avoid redefining massActions and _prepareColumns functions 🙂

  3. If one order has more than one item it throws exception like “Item (Webtex_Giftcards_Model_Sales_Order) with the same id”, how to resolve this?, I need each item in separate row.

  4. simple way to add column
    Step 1: Create the Renderer directory under /app/code/core/Mage/Adminhtml/Block/Sales/Order

    Step 2:
    Create a Block File in /app/code/core/Mage/Adminhtml/Block/Sales/Order/Renderer/Red.php (You can use any name)



    $order = Mage::getModel(‘sales/order’)->loadByIncrementID($order_id);

    $items = $order->getAllItems();

    // print_r($items);exit();

    foreach ($items as $itemId => $item)




    $sku[] = $item->getSku();





    $skutext = implode(‘,’,$sku);



    return $conbinetext;




    Step 3: Add the Below Code in




    ‘index’ => ‘shopby’,

    ‘filter’=> false,


    ‘renderer’=> ‘Mage_Adminhtml_Block_Sales_Order_Renderer_Red’,// THIS IS


    1. People! Please do not suggest changing core magento files. Not a good idea.

  5. I have done the changes as mentioned in the article and it is working beautifully. I am just stuck at one point and would like to have your suggestions for the same – The CUSTOMER Group Dropdown shows up and the searching on that column is also working beautifully however no values are showing up in that column. It is strange since the preceding column which is Order Status is also a dropdown but shows all values.

  6. @Tajinder, You are correct that it isn’t 100%. However, the method in this article breaks all paging/counters regardless of filters used whereas my method works 100% when not using the SKU filter and when using the SKU filter the paging still works, just the count will be off.

    An override of the sales/order_grid_collection class’ getSize method would be required to fix this issue which is not worth the trouble IMO as it is still very functional. Although, a pull request would gladly be accepted. 😉

  7. Hello,

    I modified with success my grid, but when it comes to count the orders, it’s not working correctly. It’s always showing just one page and 1 item on counter (above grid). The grid and all the list are ok.

    Could anyone provide me a litte help ?


    1. Hi Paulo, Have you found a workaround for this problem? I have also number 1 displayed no matter how many records there are in my custom order grid.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.