Magento – Getting the product collection from an advanced search

catalogsearchee-1.13magento-enterpriseproduct-collection

I'm trying to get the product collection containing only the products that appear in a search, from inside app\design\frontend[theme]\catalog\layer\view.phtml

I've tried:

$search = Mage::getSingleton('catalogsearch/advanced');
$searchCollection = $search->getProductCollection()->addAttributeToFilter('visibility', 4);

and

$searchCollection = Mage::getModel('catalog/category')->getProductCollection();
$searchCollection = Mage::getSingleton('catalogsearch/advanced')->prepareProductCollection( $searchCollection );
$searchCollection = $searchCollection->getProductCollection();

Both of these return every single product on the site, not just the ones in the search results.

Can anyone help?

Best Answer

This was the only working solution I could find: https://stackoverflow.com/questions/20978893/whats-the-proper-way-to-call-catalogsearch-from-a-custom-block-in-magento

Though I did replace

$searchText = 'ipad';

with

$searchText = Mage::helper('catalogsearch')->getQueryText();

to make it dynamic.

Related Topic