Magento Catalog Search (filter by id)
I'm writing a custom plugin thing which needs to search the product catalog. Based on some sample code I saw somewhere (possibly this site), I came up with this working prototype:
$searcher = Mage::getSingleton('catalogsearch/advanced')
-> addFilters(array('n开发者_开发问答ame' => $_REQUEST['name']))
-> addFilters(array('sku' => $_REQUEST['sku']))
;
$products = $searcher->getProductCollection();
This works great for those two fields, but I also need to search by product id. It seems like the proper field to search on is 'entity_id', but its not working:
$searcher->addFilters(array('entity_id' => $_REQUEST['id']));
I've also tried using 'product_id' and simply 'id' with no luck. Keep getting this error:
Mage_Core_Exception: You have to specify at least one search term
Any thoughts on how to accomplish this? Maybe I should be using a different class to do my searching?
Thanks Jimmy for your help! Turns out I was overthinking things. I've implemented an if statement to simply load by id (if provided), otherwise do the search.
精彩评论