Skip to content

Magento: Join Table on Sales Order Grid

i’m going to show how to join table on sales order grid, this is very very basic way to join table in magento

let’s say i have a table

faspay_log(
trx_id int auto increment primary_key,
bill_no varchar(255)
)

to join with sales order grid, go to app/code/core/mage/adminhtml/block/sales/order/Grid.php

first thing..join the table..you have to join the table at _prepareCollection()

       $collection = Mage::getResourceModel($this->_getCollectionClass());

$collection->join(‘faspay/log’, ‘bill_no = increment_id’, array(‘trx_id’=>’trx_id’), null,’left’);

$this->setCollection($collection);
return parent::_prepareCollection();

 

and then add a new field at  _prepareColumns(), let’s say you want to add the trx_id field after order# field

 

$this->addColumn(‘real_order_id’, array(
‘header’=> Mage::helper(‘sales’)->__(‘Order #’),
‘width’ => ’80px’,
‘type’  => ‘text’,
‘index’ => ‘increment_id’,
));

$this->addColumn(‘trx_id’, array(
‘header’ => Mage::helper(‘sales’)->__(‘Record Number’),
‘index’ => ‘trx_id’,

));

 

mangstabh!!

Share

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *