Magento: Add new column to Product Grid in Admin

This article shows how you can add new columns to product grid (Catalog -> Manage Products) in Magento 1.x admin.

For this, you need to rewrite/override the Adminhtml’s catalog_product_grid block class.

Here is the block override code to be written in your module’s config.xml file:

YourCompany/YourModule/etc/config.xml


<global>
    <blocks>
        <yourmodule>
            <class>YourCompany_YourModule_Block</class>
        </yourmodule>
        <adminhtml>
            <rewrite>
                <catalog_product_grid>YourCompany_YourModule_Block_Adminhtml_Catalog_Product_Grid</catalog_product_grid>
            </rewrite>
        </adminhtml>
    </blocks>
</global>

Now, you need to create a new class file that overrides the catalog_product_grid adminhtml class. The code will be adding two columns (URL Key & Manufacturer) after the SKU column. URL Key column will be of type text and Manufacturer column will be of type options/dropdown.

YourCompany/YourModule/Block/Adminhtml/Customer/Grid.php


<?php

class YourCompany_YourModule_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid
{
    public function setCollection($collection)
    {
        // selecting url_key and manufacturer attribute in the collection        
        $collection->addAttributeToSelect('url_key');
        $collection->addAttributeToSelect('manufacturer');
        parent::setCollection($collection);
    }
    
    protected function _prepareColumns()
    {   
        /**
         * Adding URL KEY text column
         */      
        $this->addColumn('url_key', array(
            'header'    =>  Mage::helper('catalog')->__('URL Key'),
            'width'     =>  '100px',
            'index'     =>  'url_key',
            'type'      =>  'text',            
        ));
        
        // show URL Key column after SKU column
        $this->addColumnsOrder('url_key', 'sku');
        
        /**
         * Adding Manufacturer options dropdown column
         */ 
        $attribute = Mage::getResourceModel('eav/entity_attribute_collection')
                          ->addFieldToFilter('attribute_code', 'manufacturer');

        $attributeValue = Mage::getResourceModel('eav/entity_attribute_option_collection')
                                ->setAttributeFilter($attribute->getData('attribute_id'))
                                ->setStoreFilter(0, false);

        $manufacturerOption = array();
        foreach ($attributeValue as $manufacturer) {
            $manufacturerOption[$manufacturer->getOptionId()] = $manufacturer->getValue();
        }
 
        $this->addColumn('manufacturer',
            array(
                'header'=> Mage::helper('catalog')->__('Manufacturer'),
                'width' => '100px',
                'type'  => 'options',
                'index' => 'manufacturer',
                'options' => $manufacturerOption
        ));
        
        // show Manufacturer column after SKU column
        $this->addColumnsOrder('manufacturer', 'sku');
        
        return parent::_prepareColumns();
    }    
}
?>

Now, clear cache from Magento admin (System -> Cache Management).

That all. Now, you should be able to see two new column in Product Grid in your Magento admin (Catalog -> Manage Products).

Hope this helps. Thanks.