![]()
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.