Magento – way to add custom attributes to the Admin side product search

catalogsearchmagento-1.7

I am looking to be able to search by a custom attribute's values on the Admin side in Catalog > Product search.

By default you can search by a range of product ID's, name, type, attribute set name, SKU, etc.

Is there a way to add my own attribute in that product search?

Best Answer

To add an attribute column to products grid you have to create a module with 2 observers.

First you have to observe eav_collection_abstract_load_before event and to add your attribute to collection:

public function eavCollectionAbstractLoadBefore(Varien_Event_Observer $observer)
{
    $observer->getCollection()->addAttributeToSelect('color');
}

Then you have to observe adminhtml_block_html_before event, check that the current grid is products listing and add new column:

public function adminhtmlBlockHtmlBefore(Varien_Event_Observer $observer)
{
    $block = $observer->getBlock();
    if ($block->getId() == 'productGrid') {
        $block->addColumn('test', array(
            'header'    => 'Color',
            'index'     => 'color'
        ));
    }
}

That's all. Enjoy.

Related Topic