Magento 1.8 – Search by Product ID

magento-1.8search

If we want to search by name or sku, we can just alter the their respective attribute settings in admin panel. But how to search by mentioning product id?

I thought changing Mage_Adminhtml_Model_Search_Catalog would does the same but I figured it out that it doesn't.

    $collection = Mage::helper('catalogsearch')->getQuery()->getSearchCollection()
        ->addAttributeToSelect('entity_id') /* added */
        ->addAttributeToSelect('name')
        ->addAttributeToSelect('description')
        ->addSearchFilter($this->getQuery())
        ->setCurPage($this->getStart())
        ->setPageSize($this->getLimit())
        ->load();

Please help.

Best Answer

You need to edit the Mage_CatalogSearch_Model_Resource_Search_Collection resource model.

Particularly the _getSearchEntityIdsSql function

I'm not yet sure how to add your code here, I'll search and update my post, except if one expert can help you replacing this resource model.

Edit. Apparently there is a foreach on each searchable attribute that append the results in a $selects[] array.

Try adding your request in the $selects array just after the end of foreach.

Related Topic