Search code examples
magentosearch

Accessing Magento search results collection


I need to get a list of the skus returned by the Magento search results. I've looked around and googled but cannot find where the products come from when displaying them on the search results page. I have the searchresults.phtml file open. It looks like when $this->getChildHtml('content') is called that is where the products are looped through but I think there is some magic going on with the core/textlist. Anyway I'd like to access the product collection provided by the search results and loop through it on the searchresults.phtml file.

EDIT: Just to clarify, what I really need is access to the product collection that comes from the search results.

EDIT: Turns out that searchresults.phtml is a custom page.


Solution

  • After realizing I was working with a custom template I now see there are probably two places I'll need to address:

    catalogsearch/result.phtml

    catalogsearch/advanced/result.phtml

    For result.phtml the block is Mage_CatalogSearch_Block_Result. In that block you can call $this->_productCollection(). The sku is in the collection. I'm assuming the same is true for advanced.

    EDIT: for the advanced search you have to use $this->getChild('search_result_list')->_productCollection.