Add Dropdown Attribute Value in Magento Product Grid

If you have to show “size” dropdown attribute in magento product grid, then take following steps.

In _prepareCollection() function, add following line.

->joinAttribute(‘size’,’catalog_product/size’, ‘entity_id’, null,’left’, $store->getId())

OR

->addAttributeToSelect(‘size’)

Now, In _prepareColumns() function, add following code.

$attribute = Mage::getModel(‘eav/config’)->getAttribute(‘catalog_product’, ‘size’);
$options = array();
foreach( $attribute->getSource()->getAllOptions(true, true) as $option ) {
if($option[‘value’] != ”){
$options[$option[‘value’]] = $option[‘label’];
}
}
$this->addColumn(‘size’,
array(
‘header’=> Mage::helper(‘catalog’)->__(‘Size’),
‘width’ => ’80px’,
‘index’ => ‘size’,
‘type’  => ‘options’,
‘options’ => $options,
));

Thats it!!

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: