Adding Shipping Method to the Magento Order Grid
Open /app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
Create the file structure of :
/app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php
Copy the contents of the Core file, and paste into the Local version.
Find the protected function _prepareCollection. You are going to modify this function by adding one line to make the custom attribute available for inserting into the grid.
Just add this line :
$collection->getSelect()->join('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id',array('shipping_description'));
after this line:
$collection = Mage::getResourceModel($this->_getCollectionClass());
So altogether you should have a function that looks like this:
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->join('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id',array('shipping_description'));
$this->setCollection($collection);
return parent::_prepareCollection();
}
So now that you’ve modified that function we need to add the new column to the grid using the addColumn method. So now find the _prepareColumns() function.
Now just add this code :
$this->addColumn('shipping_method', array(
'header' => Mage::helper('sales')->__('Shipping Method'),
'index' => 'shipping_description',
));
In order to prevent a massive “SQLSTATE[23000]: Integrity constraint violation: 1052 Column ‘status’ in where clause is ambiguous” ERROR when sorting your orders…Make sure you add this:
'filter_index'=>'main_table.status',
to the addColumn Status array
Now save and upload your new Local Grid.php file, login to Magento Admin, Browse to Sales > Orders and you will see your BRAND NEW SHINY column!
Cheers!
4 comments
Aaron McGuire - September 19, 2013 6:16 pm
You sir, are my hero. I have been looking for this for days. Thank you very much for sharing.
admin - September 19, 2013 10:47 pm
Glad I could help!
Arjan - April 22, 2014 10:09 am
Hi, this works nice, thanks. The only thing what is not working at my shop now is the search functionality. I cannot search for shipping method in the order grid, it results in a blank result, the search on other (default) criteria works fine. Do you know what to do?
admin - April 22, 2014 3:56 pm
Which version of Magento are you using?