![]()
A client requested to add a column to the product grid in the admin so that they could filter by manufacturer. It would be great if Magento made this more simple to do, but it’s not that bad to just do it manually. Instead of creating a whole module to do this, I’m just overriding one file. You can make a module with it quite easily if you want.
The following was used and tested with Magento 1.3.2.4
Step 1:
Copy this file: /app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php and paste it here: /app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php. This will override the core file with your own without actually modifying core code.
Step 2:
By looking at this file, you will clearly see how Magento is setting up the columns. Find where you want to put the Manufacturer column, and paste the following code:
$manufacturer_items = Mage::getModel('eav/entity_attribute_option')->getCollection()->setStoreFilter()->join('attribute','attribute.attribute_id=main_table.attribute_id', 'attribute_code'); foreach ($manufacturer_items as $manufacturer_item) : if ($manufacturer_item->getAttributeCode() == 'manufacturer') $manufacturer_options[$manufacturer_item->getOptionId()] = $manufacturer_item->getValue(); endforeach; $this->addColumn('manufacturer', array( 'header'=> Mage::helper('catalog')->__('Manufacturer'), 'width' => '100px', 'type' => 'options', 'index' => 'manufacturer', 'options' => $manufacturer_options ));
Step 3:
Enjoy your new column. Props to wolfdog85 for helping me figure out the code. The original forum post can be found here.

Hey, This is damn sweeet.. Gives you a better feel for the grid. I predicted this was in the mix soon. Sure would be awesome if a flexible grid would allow once to choose which are displayed..
Very nice writeup and example.
can i see the output of this code?
kurt,
Well, if you follow the instructions quick and do it on your own installation of Magento, you would be able to.
hi Josh
should this code work with 1.4.1?
THX
fair – I haven’t even needed to try it on 1.4.1 yet. Try it out. It won’t take long to test it.
i did try to add a custom attribute to the grid but the column stays blank…
does the attribute needs specific setting maybe?
$page_items = Mage::getModel(‘eav/entity_attribute_option’)->getCollection()->setStoreFilter()->join(‘attribute’,'attribute.attribute_id=main_table.attribute_id’, ‘attribute_code’);
foreach ($page_items as $page_item) :
if ($page_item->getAttributeCode() == ‘page’)
$page_options[$page_item->getOptionId()] = $page_item->getValue();
endforeach;
$this->addColumn(‘page’,
array(
‘header’=> Mage::helper(‘catalog’)->__(‘Page’),
‘width’ => ’10px’,
‘type’ => ‘options’,
‘index’ => ‘page’,
‘options’ => $page_options
));
Could you do this for ‘cost’ price and how would you do it?
Changed from manufacturer to condition for what I needed. Worked great in adding the column and showing the options in the dropdown menu (new, used). Unfortunately it only shows in the column near a product if I select New or Used from dropdown, if I don’t select from dropdown all columns stay blank. Does something also need to be added to by default show the option selected in each row?
Here’s what I added:
$condition_items = Mage::getModel(‘eav/entity_attribute_option’)->getCollection()->setStoreFilter()->join(‘attribute’,'attribute.attribute_id=main_table.attribute_id’, ‘attribute_code’);
foreach ($condition_items as $condition_item) :
if ($condition_item->getAttributeCode() == ‘condition’)
$condition_options[$condition_item->getOptionId()] = $condition_item->getValue();
endforeach;
$this->addColumn(‘condition’,
array(
‘header’=> Mage::helper(‘catalog’)->__(‘Condition’),
‘width’ => ’70px’,
‘index’ => ‘condition’,
‘type’ => ‘options’,
‘options’ => $condition_options
));
Thanks for any help!
Update:
added this
->addAttributeToSelect(‘condition’)
within
protected function _prepareCollection()
{
$store = $this->_getStore();
$collection = Mage::getModel(‘catalog/product’)->getCollection()
->addAttributeToSelect(‘sku’)
->addAttributeToSelect(‘name’)
->addAttributeToSelect(‘condition’)
works great now
mad props
Hi,
i tried to add a new column for my attribute and did exactly as you guys has mentioned here.but i it fetches no value for that particular attribute. can you guys help me here.
Thanks
Thanks! Had been the missing link for me. Just worked.