Magento: Add Manufacturer Column to Admin Product Grid

Magento Icon

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.

This entry was posted in Magento. Bookmark the permalink.

12 Responses to Magento: Add Manufacturer Column to Admin Product Grid

  1. Lloyd says:

    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.

  2. kurt says:

    can i see the output of this code?

  3. fair says:

    hi Josh

    should this code work with 1.4.1?

    THX

    • Josh Pratt says:

      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.

      • fair says:

        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
        ));

  4. sam says:

    Could you do this for ‘cost’ price and how would you do it?

  5. brd says:

    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!

  6. brd says:

    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

  7. Chris says:

    mad props

  8. 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

  9. Marc says:

    Thanks! Had been the missing link for me. Just worked.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">