Recently we were asked by the client to display the products name and payment method in order grid in magento. To achieve that we have override the Mage_Adminhtml_Block_Widget_Grid class.

We have created a module by name TW_Salesproduct. You can give name whatever you would like to give

Create the TW_Salesproduct.xml file under app/etc/modules

<?xml version=”1.0″?>
<config>
<modules>
<TW_Salesproduct>
<active>true</active>
<codePool>local</codePool>
</TW_Salesproduct>
</modules>
</config>

Create the directories (Namespace & Module) under app/code/local. I have named it TW and Salesproduct : app/code/local/TW/Salesproduct
Under app/code/local/TW/Salesproduct we will create the etc folder which will have the config.xml file. Below is the code you can copy and paste.

<?xml version=”1.0″?>
<config>
<modules>
<TW_Salesproduct>
<version>0.1.0</version>
</TW_Salesproduct>
</modules>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<salesproduct before=”Mage_Adminhtml”>TW_Salesproduct_Adminhtml</salesproduct>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<adminhtml>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<TW_Salesproduct>
<title>Products in Order Grid</title>
<sort_order>10</sort_order>
</TW_Salesproduct>
</children>
</admin>
</resources>
</acl>
</adminhtml>
<global>

<blocks>
<adminhtml>
<rewrite>
<sales_order_grid>TW_Salesproduct_Block_Adminhtml_Sales_Order_Grid</sales_order_grid>
</rewrite>
</adminhtml>
<salesproduct>
<class>TW_Salesproduct_Block</class>
</salesproduct>
</blocks>
<helpers>
<salesproduct>
<class>>TW_Salesproduct_Helper</class>
</salesproduct>
</helpers>
</global>
</config>

Under app/code/local/TW/Salesproduct we will create the Helper folder which will have the Data.php file. Below is the code you can copy and paste.

<?php

class TW_Salesproduct_Helper_Data extends Mage_Core_Helper_Abstract
{

}

Under app/code/local/TW/Salesproduct we will create the Block folder which will have the Grid.ph file which we override to show the products and payment method. The path for the Grid.ph file will be app/code/local/TW/Salesproduct/Adminhtml/Sales/Order/Grid.php
<code>
<?php
class TW_Salesorder_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId(‘sales_order_grid’);
$this->setUseAjax(true);
$this->setDefaultSort(‘created_at’);
$this->setDefaultDir(‘DESC’);
$this->setSaveParametersInSession(true);
}

/**
* Retrieve collection class
*
* @return string
*/
protected function _getCollectionClass()
{
return ‘sales/order_grid_collection’;
}

protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass())
->join(
‘sales/order_payment’,
‘`sales/order_payment`.parent_id=`main_table`.entity_id’,
array(
‘method’ => ‘method’, // Showing the payment method
)
)
->join(
‘sales/order_item’,
‘`sales/order_item`.order_id=`main_table`.entity_id’,
array(
‘names’ => new Zend_Db_Expr(‘group_concat(`sales/order_item`.name SEPARATOR “,<br>”)’), // Names of the product in an order
)
);
$collection->getSelect()->group(array(‘main_table.entity_id’,’sales/order_payment.method’));
$this->setCollection($collection);

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,
));
}

$this->addColumn(‘created_at’, array(
‘header’ => Mage::helper(‘sales’)->__(‘Purchased On’),
‘index’ => ‘created_at’,
‘type’ => ‘datetime’,
‘width’ => ‘100px’,
));

$this->addColumn(‘billing_name’, array(
‘header’ => Mage::helper(‘sales’)->__(‘Bill to Name’),
‘index’ => ‘billing_name’,
));

$this->addColumn(‘shipping_name’, array(
‘header’ => Mage::helper(‘sales’)->__(‘Ship to Name’),
‘index’ => ‘shipping_name’,
));

$this->addColumn(‘names’, array(
‘header’ => Mage::helper(‘Sales’)->__(‘Product Name’),
‘width’ => ‘300px’,
‘index’ => ‘names’,
‘type’ => ‘text’,
‘filter’ => false,

));

$this->addColumn(‘method’, array(
‘header’ => Mage::helper(‘Sales’)->__(‘Payment method’),
‘width’ => ‘100px’,
‘index’ => ‘method’,
‘type’ => ‘text’,
‘filter’ => false,

));
$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(),
));
$this->addRssList(‘rss/order/new’, Mage::helper(‘sales’)->__(‘New Order RSS’));

$this->addExportType(‘*/*/exportCsv’, Mage::helper(‘sales’)->__(‘CSV’));
$this->addExportType(‘*/*/exportExcel’, Mage::helper(‘sales’)->__(‘Excel XML’));

return parent::_prepareColumns();
}

}
?>
</code>

That’s it. Please let me know your thought if you have any doubt.