B-219 Sec-55 Noida, India
+918010221733

Magento : Product Name and Product SKU in Sales order grid

Product Name and Product SKU in Sales order grid: This is really very important and needed aspects of the sales order grid and saves a lot of time of your’s , Lot of users requested us for this tutorial . so here is a simple hack to display product order name and product sku in magento sales order grid .

Go to /app/code/core/Mage/Adminhtml/Block/Sales/Order and open grid.php

Now replace your _prepareCollection() function to this following code
   
protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass())
            ->join(
                ‘sales/order_item’,
                ‘`sales/order_item`.order_id=`main_table`.entity_id’,
                array(
                    ‘skus’  => new Zend_Db_Expr(‘group_concat(`sales/order_item`.sku SEPARATOR “,”)’),
                    ‘names’ => new Zend_Db_Expr(‘group_concat(`sales/order_item`.name SEPARATOR “,”)’),
                    )
                );
                $collection->getSelect()->group(‘entity_id’);

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

After adding this function lets add the columns in grid for sku and ordername add this code in your _prepareColumns() function
   
$this->addColumn(‘skus’, array(
            ‘header’    => Mage::helper(‘Sales’)->__(‘Skus’),
            ‘width’     => ‘100px’,
            ‘index’     => ‘skus’,
            ‘type’        => ‘text’,

        ));
    $this->addColumn(‘names’, array(
            ‘header’    => Mage::helper(‘Sales’)->__(‘Name’),
            ‘width’     => ‘100px’,
            ‘index’     => ‘names’,
            ‘type’        => ‘text’,
after this you’ll display your sales order screen in like this

SKU's and Product name

(Visited 61 times, 1 visits today)

Leave a reply

You must be logged in to post a comment.