2

I need tracking number on sales order grid,

enter image description here

1

1 Answer 1

2

You can do it with below. Add below code in your app/code/local/Vendor/Module/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Vendor_Module>
      <version>0.1.0</version>
    </Vendor_Module>
  </modules>
  <global>
        <blocks>
          <module>
            <class>Vendor_Module_Block</class>
          </module>
            <adminhtml>
                <rewrite>
                    <sales_order_grid>Vendor_Module_Block_Adminhtml_Sales_Order_Grid</sales_order_grid>
                </rewrite>
            </adminhtml>
        </blocks>
  </global>
</config> 

Now create a file app\code\local\Vendor\Module\Block\Adminhtml\Sales\Order\Grid.php with below code.

<?php
class Vendor_Module_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{
    protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());
        $collection->getSelect()->joinLeft(array("track_table"=>Mage::getSingleton('core/resource')->getTableName('sales/shipment_track')), "main_table.entity_id = track_table.order_id",array('track_number'))->group('main_table.entity_id');
        $this->setCollection($collection);
        return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
    }

    protected function _prepareColumns()
    {
        if ($this->_isExport) { 
            $this->addColumnAfter('track_number', array(
                'header' => Mage::helper('sales')->__('Track Order'),
                'index'  => 'track_table.track_number',
                'type' => 'text',
            ), 'status');
        }
        $this->addColumnAfter(
                'track_number',
                array(
                    'header'   => Mage::helper('sales')->__('Track Order'),
                    'align'    => 'left',
                    'type'     => 'text',
                    'index'    => 'track_number',
                    'filter_index'    => 'track_table.track_number',
                ),
                'status'
            );
        parent::_prepareColumns();
    }
}

Create file app/etc/modules/Vendor_Module.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Vendor_Module>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </Vendor_Module>
  </modules>
</config>
18
  • Make sure config.xml is default file, and where i can create Observer.php file
    – user51361
    Commented Apr 26, 2017 at 6:53
  • Check updated answer for full file paths Commented Apr 26, 2017 at 6:57
  • reference id not dipsplay
    – user51361
    Commented Apr 26, 2017 at 7:10
  • Reference id? You mean carrier name? Commented Apr 26, 2017 at 7:11
  • 1
    @Rathinam, updated code to support export functionality. Please remove old files and create only these three files only. Commented Apr 28, 2017 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.