Add custom attribute in magento admin product grid

We all know that magento admin product grid display some attribute of the product. Some time we require displaying the custom attribute value into that grid. So I post this blog to fulfill that requirement.

Step: 1: Create the attribute for the product and give the proper type.

Example: Crates attribute ‘newstatus’

 

Step: 2: Crate directory structure.

For that first we create the following directory structure in our magento.


[Magento]\app\code\local\Mage\Adminhtml\Block\Catalog\Product

 

Step: 3: Overwrite the default product grid.

For adding new attribute to grid, overwrite the default grid file. For that we copy the file “Grid.php” from the following location


[Magento]\app\code\core\Mage\Adminhtml\Block\Catalog\Product

And paste this file at our new created location. So path become like this:


[Magento]\app\code\local\Mage\Adminhtml\Block\Catalog\Product\Grid.php

 

Step: 4­: Add Attribute to grid.

First find out the following function.


protected function _prepareColumns()

Now add the code for displaying the attribute to grid. Here I insert the attribute ‘newstatus’ created at step-1.


$this->addColumn('newstatus',

array(

'header'=> Mage::helper('catalog')->__('Company Status'),

'width' => '80px',

'index' => 'newstatus',

'type'  => ‘text’,

));

Step: 5­: Add Attribute to filter grid.

Find the following function.


protected function _prepareCollection()

 

Add the fields in that code for filtration.


->addAttributeToSelect('newstatus')

 

Refresh the cache memory and reindexing the data. Now this attributes display into admin product grid.

I hope this will help you.

Thank you.

Speak Your Mind