I need tracking number on sales order grid,
1 Answer
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>
-
Make sure config.xml is default file, and where i can create Observer.php file– user51361Commented Apr 26, 2017 at 6:53
-
-
reference id not dipsplay– user51361Commented Apr 26, 2017 at 7:10
-
-
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