Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento Active Filters on Search Page

I want to implement active filters on my magento ecommerce site.

I have been successful in implementing it, but the issue is, the code works on only category pages and not search page

Here's the code that I'm using

<?php /*Create filter dependencies*/

$_activeFilters[] = array();

$_filters = Mage::getSingleton(‘Mage_Catalog_Block_Layer_State’)->getActiveFilters();

foreach ($_filters as $_filter):?>
<?php echo $this->stripTags($_filter->getLabel()) ?><a href=”<?php echo $_filter-     >getRemoveUrl() ?>” title=”<?php echo $this->__(‘Remove This Item’) ?>”><?php echo $this->__(‘Remove This Item’) ?></a>
<?php endforeach; ?>

I'm using this code in toolbar.phtml. Any clue as in why its not working on search page. Any Solutions would be of great help.

Thanks,

Sushil

like image 834
Sushil Sudhakaran Avatar asked Jan 10 '13 05:01

Sushil Sudhakaran


1 Answers

You can use this code for fetching filters on either category list page or search results page

   <?php
   if(Mage::registry('current_category')) {
       $_filters = Mage::getSingleton('catalog/layer')->getState()->getFilters();
   } else {
       $_filters = Mage::getSingleton('catalogsearch/layer')->getState()->getFilters();
   }
   ?>

I have used this code in toolbar.phtml, to show removable filters below the toolbar, like flipkart does.

like image 58
Dhanesh Narvekar Avatar answered Sep 20 '22 11:09

Dhanesh Narvekar