I have been stuck for hours trying to add both Product Name and SKU to the Sales Order Grid in Magento.
I have created the joins and added the columns but the no data is being displayed and can't figure out why???
Any help would be nice…
Inside _prepareCollection
protected function _prepareCollection()
{
$collection->getSelect()->joinLeft(array('sfoi' => 'sales_flat_order_item'),
'order_id=main_table.entity_id = quote_item_id', array('sfoi.sku',
'sfoi.name'));
$this->setCollection($collection);
return parent::_prepareCollection();
}
And my two columns
$this->addColumn('sku', array(
'header' => Mage::helper('sales')->__('SKU'),
'align' => 'left',
'sortable' => true,
'index' => 'sku'
));
$this->addColumn('name', array(
'header' => Mage::helper('sales')->__('Item Name'),
'align' => 'left',
'sortable' => true,
'index' => 'name'
));
$this->addColumn('total_item_count', array(
'header' => Mage::helper('sales')->__('Total Items'),
'width' => '80px',
'index' => 'total_item_count',
'type' => 'text',
'filter_index' => 'total_item_count'
));
I am able to get number of items into the Grid but not name and SKU is just empty
Could do with a heads up here!
Best Answer
Rather then put complex query you can just use the
Renderer
in Magento GridThen you have to create the Renderer File
NameSpace\ModuleName\Block\Adminhtml\Renderer\Productssku.php
Write down below code in you this file