Magento does not provide us with the ability to choose which attributes are included as columns in the Manage Products grid but it’s fairly simple to make the necessary code changes.
The code that generates the Manage Products grid is at /app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php. The first thing you need to do is copy Grid.php into to the local directory structure. In other words, you copy Grid.php into the following location; /app/code/local/Mage/Adminhtml/Block/Catalog/Product/. If there is no such location, then you must create the necessary directories. The final location of the file must be; /app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php
Now, open Grid.php (the one in the local directory structure) and begin editing. Find the following code;
$this->addColumn('sku', array( 'header'=> Mage::helper('catalog')->__('SKU'), 'width' => '80px', 'index' => 'sku', ));
That’s the code that adds the SKU column to the product grid. Now, let’s say you have a custom attribute called Supplier ID (supplier_ID) and you want these to appear on the Manage Products grid as well. Place the following code either before or after the above block of code, as long as it’s inside _prepareColumns().
$this->addColumn('supplier_id', array( 'header'=> Mage::helper('catalog')->__('Supplier ID'), 'width' => '150px', 'index' => 'supplier_id', ));
Then add the following line to _prepareCollection() where the other attributes are listed like this;
->addAttributeToSelect('supplier_id')
That should be all you need to do. You might have to re-compile, refresh your caches, logout, and log back in to see the change in your product grid.
The above example is for adding an attribute with a Catalog Input Type for Store Owner of Text Field. What if your attribute uses a dropdown list? The code above will have to be modified.
Let’s say you have an attribute called Supplier (supplier) which in the product editor presents a dropdown list of suppliers to choose from. To do this, we can add the following code to _prepareColumns():
$supplier_items = Mage::getModel('eav/entity_attribute_option')->getCollection()->setStoreFilter()->join('attribute','attribute.attribute_id=main_table.attribute_id', 'attribute_code'); foreach ($supplier_items as $supplier_item) : if ($supplier_item->getAttributeCode() == 'supplier') $supplier_options[$supplier_item->getOptionId()] = $supplier_item->getValue(); endforeach; $this->addColumn('supplier', array( 'header'=> Mage::helper('catalog')->__('supplier'), 'width' => '150px', 'type' => 'options', 'index' => 'supplier', 'options' => $supplier_options, ));
And let’s not forget to add the following line to _prepareCollection() where the other attributes are listed like this;
->addAttributeToSelect('supplier')
That should do it for you. Re-compile, refresh your caches, and logout and then back in if you need to.
NB Don’t copy core files, but use observers and rewrites to accomplish your task. This way, when you upgrade Magento, new functionality will work.
For adding a column the proper way, look here: http://stackoverflow.com/a/5994209/1025437
I added another solution to stackoverflow using just rewrites. The used observer events are, in my opinion, to global.
wow, simply amazing. working from CE 1.6.2 and works perfectly!
Super simple and effective, fantastic, thanks!
(worked on 1.7)
Thanks for sharing.. working with this solution…
With this solution when I search products by name option of supplier disappears. Other filters works great.
It’s work bad with me 🙁 .
SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘custom_params’ cannot be null
🙁 🙁
Nice! You can also find the way to add attributes in this post –
https://www.mag-manager.com/useful-articles/how-to/how-to-include-additional-attributes-to-magento-product-grid/
Very strange method having the if statement inside the foreach, when you could just addFieldToFilter(‘attribute.attribute_code’, ‘supplier’) instead – which is better in every possible way
I am not a Magento (or PHP) expert. I just cobbled together code that did what I needed it to do. I’m sure there are better ways of doing it.
I have seen this on in other places and it works great. Where can I find a list of types? I have a Yes/No attribute that I wish to display in grid view but it is only showing 0 or 1. I have tried ‘options’, ‘select’, ‘boolean’ and a few other guesses but none make it display as Yes or No
Thanks for this info. It worked a treat!