As Magento save coupon code
on Sales_flat_Order table so you need to MySQL join with Sales_flat_order
table
Add sales_flat_order table to collection.In magento, sales_flat_order and sales_flat_order_grid table related with Flat Grid order table entity_id and sales_flat_order table entity_id
.
$select = $collection->getSelect();
$select->joinLeft(array('order' => Mage::getModel('core/resource')->getTableName('sales/order')), 'order.entity_id=main_table.entity_id',
array('coupon_code' => 'coupon_code'))
Rewrite class then add columns to show Coupon:
<?php
/**
* Sales Order Class
*
* @author Amit Bera
*/
class Amit_CustomOrderGrid_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{
protected function _prepareColumns()
{
$this->addColumn('coupon_code', array(
'header' => Mage::helper('sales')->__('Color Name'),
'align' =>'left',
'width' => '50px',
'index' => 'coupon_code',
'filter_index' => 'order.coupon_code'
));
parent::_prepareColumns();
return Mage_Adminhtml_Block_Widget_Grid::_prepareColumns();
}
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->joinLeft(array('order' => Mage::getModel('core/resource')->getTableName('sales/order')),
'order.entity_id=main_table.entity_id',array('coupon_code' => 'coupon_code'))
$this->setCollection($collection);
// return parent::_prepareCollection();
return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
}
}
?>