The key to the fact that the layer block needs to be there can be found in Mage_CatalogSearch_Block_Layer
in the construct.
/**
* Internal constructor
*/
protected function _construct()
{
parent::_construct();
Mage::register('current_layer', $this->getLayer(), true);
}
The second line is the key: Mage::register('current_layer', $this->getLayer(), true);
without this line none of the search results will display correctly. What this does is tell the system what the current state of the search is.
This will set the current layer as type Mage_CatalogSearch_Model_Layer
but if this line is not run then later on the layer gets set as type Mage_Catalog_Model_Layer
. The two models have two similar but different prepareCollection functions.
Mage_CatalogSearch_Model_Layer
Has an important call to addSearchFilter
public function prepareProductCollection($collection)
{
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText())
->setStore(Mage::app()->getStore())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addStoreFilter()
->addUrlRewrite();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
return $this;
}
Mage_Catalog_Model_Layer
Has no addition of addSearchFilter and does not set or filter on the store.
public function prepareProductCollection($collection)
{
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addUrlRewrite($this->getCurrentCategory()->getId());
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
return $this;
}
Best Answer
To explain what happens during your search auto-suggest, I add some information about the search-functionality related to this here:
Searching for 'trousers' (actually 'trou') in the demo shop: GET http://demo.magentocommerce.com/catalogsearch/ajax/suggest/?q=trou gives you the following return via AJAX:
From the request above you can see that the suggestAction from the CatalogSearch AjaxController.php is called. The suggestAction calls
$this->getResponse()->setBody($this->getLayout()->createBlock('catalogsearch/autocomplete')->toHtml());
to return the search-output. Openingapp/code/core/Mage/CatalogSearch/Block/Autocomplete.php
you will see that the HTML-code for your autosuggest-text is created there which is shown above.In the
_toHtml()
function there is an inline-element named<span class="amount">
which shows the number of results for the term. You might have a CSS-rule for.amount
or one of the other CSS-classes around.search-autocomplete
which were modified. Or there might have been someone/something rewriting theapp/code/core/Mage/CatalogSearch/Block/Autocomplete.php
block class.