Magento - How to add multi-level navigation to advanced search?

How to add layered navigation to advanced search results pages?

Magento Version 1.7.

+7
source share
5 answers

In the patch below, multi-level navigation in the advanced search will be displayed and will work perfectly with layered navigation. Multilevel navigation and search results are displayed on the basis of two separate product collections, one of which is created by catalogsearch / Model / Layer.php and the other by catalogsearch / Model / Advanced.php . Therefore, we need to redefine several functions of both of these models to make multi-layer navigation in advanced search.

1- In your local.xml in the tag catalogsearch_advanced_result add.

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

Override the prepareProductCollection command for the searchearch / model / Layer.php directory with

 public function prepareProductCollection($collection){ if(Mage::helper('catalogsearch')->getQuery()->getQueryText())//for normal search we get the value from query string q=searchtext return parent::prepareProductCollection($collection); else{ $collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes()); /** * make sure you cross check the $_REQUEST with $attributes */ $attributes = Mage::getSingleton('catalog/product')->getAttributes(); Mage::log(print_r($_REQUEST,1)); foreach($attributes as $attribute){ $attribute_code = $attribute->getAttributeCode(); //Mage::log("--->>". $attribute_code); if($attribute_code == "price")//since i am not using price attribute continue; if (empty($_REQUEST[$attribute_code])){ //Mage::log("nothing found--> $attribute_code"); continue; } if(!empty($_REQUEST[$attribute_code]) && is_array($_REQUEST[$attribute_code])) $collection->addAttributeToFilter($attribute_code, array('in' => $_REQUEST[$attribute_code])); else if(!empty($_REQUEST[$attribute_code])) $collection->addAttributeToFilter($attribute_code, array('like' => "%" . $_REQUEST[$attribute_code] . "%")); } $collection->setStore(Mage::app()->getStore()) ->addMinimalPrice() ->addFinalPrice() ->addTaxPercents() ->addStoreFilter() ->addUrlRewrite(); //Mage::log($collection->getSelect()->__toString()); Mage::getSingleton('catalogsearch/advanced')->prepareProductCollection($collection); Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection); Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection); } return $this; } 

Override the getProductCollection, getSearchCriterias function from the searchearch / model / Advanced.php directory using

 public function getProductCollection(){ if (is_null($this->_productCollection)) { $this->_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection') ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes()) ->addMinimalPrice() ->addStoreFilter(); Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection); Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection); if(isset($_GET['cat']) && is_numeric($_GET['cat'])) $this->_productCollection->addCategoryFilter(Mage::getModel('catalog/category')->load($_GET['cat']),true); } return $this->_productCollection; } public function getSearchCriterias() { $search = parent::getSearchCriterias(); /* display category filtering criteria */ if(isset($_GET['cat']) && is_numeric($_GET['cat'])) { $category = Mage::getModel('catalog/category')->load($_GET['cat']); $search[] = array('name'=>'Category','value'=>$category->getName()); } return $search; } 
+7
source

There is no quick fix for this. Standard Search and Advanced Search use two different search methods.

If you compare layouts in catalogsearch.xml , you see that the catalogsearch/layer block is not included for catalogsearch_advanced_result . If you copy the block definition from catalogsearch_result_index and change the template root to 3columns.phtml , various errors will be reset.

+5
source

In my 1.6.2, a multi-level navigator appeared after installing 0 (Zero) in the system β†’ Configuration β†’ Directory β†’ Directory Search β†’ Apply multi-level navigation if the search results are less than

+1
source

catalogsearch.xml simply adding the following line to catalogsearch.xml the preliminary search results on the left helped me see it on my EE site, however I did not check it in the CE version.

 <block type="catalogsearch/layer" name="catalogsearch.leftnav" before="-" template="catalog/layer/view.phtml"/> 

So my full left area looks like this: in the preliminary search area in the xml file:

 <reference name="left"> <block type="catalog/navigation" name="hello.leftnav" as="hello.leftnav" template="catalog/navigation/hello_left_nav-search.phtml" /> <block type="catalog/layer_view" name="catalog.leftnav" before="-" template="catalog/layer/view.phtml"/> </reference> 

Hope this helps others.

0
source

All Articles