Showing posts with label Magento create sku column in sales order grid backend. Show all posts
Showing posts with label Magento create sku column in sales order grid backend. Show all posts

Monday 12 December 2016

How to add sku column in sales order grid magento admin


How to add sku column in sales order grid magento admin

Note: For not to override magento core functionality, You can create your own module and use the below code in Grid.php

Open app\code\core\Mage\Adminhtml\Block\Sales\Order\Grid.php

Replace the below function

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->getSelect()->joinLeft(
            'sales_flat_order_item',
            '`sales_flat_order_item`.order_id=`main_table`.entity_id',
            array('skus'  => new Zend_Db_Expr('group_concat(`sales_flat_order_item`.sku SEPARATOR ",")'))
    );
    $collection->getSelect()->group('entity_id');
   
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

Now put the below code in _prepareColumns() function

$this->addColumn('sku', array(
    'header' => Mage::helper('sales')->__('SKU'),
    'index' => 'skus',
    'type' => 'text',
    'width' => '100px',
    'filter'    => false,
));