Question

I need tracking number on sales order grid,

enter image description here

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top