3

I'm having an issue with search results. I was switching my search results page over to a one column layout and removed the sidebar in catalogsearch.xml by taking out

    <reference name="left">
        <block type="catalogsearch/layer" name="catalogsearch.leftnav" after="currency" template="catalog/layer/view.phtml"/>
    </reference>

When I removed that, the search results that were returned were incorrect, but when I leave it in, the search results are correct. The page successfully got switched over to a 1column layout, so overall, the problem is solved, however it would be nice to know why I need that in the xml to return proper results and it would be nice to remove unneeded code. I'm not seeing anything in that file that should effect the collection that gets returned.

3 Answers 3

1

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;
}
1

For catalog or catalogsearch layout */layer is required block.

If you no need display this block, just set empty template (template="")

In you case, you can set empty template and move block to center.

  <reference name="content">
        <block type="catalogsearch/layer" name="catalogsearch.leftnav" after="currency" template=""/>
    </reference>
1

Finally! Thank you alex! Been fiddling with this for hours. Anyone else having issues disabling the SM_SHOPBY module, use this fix.

  1. Turn off SM_Shopby
  2. Go to Catalog>Manage Categories>Custom Design
  3. Choose the layout you want to affect i.e. 2 columns left
  4. Paste this:

    <block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"> 
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.