2

I am working on the layered navigation. i am trying to get the list of applied filters using getActiveFilters of the block Mage_Catalog_Block_Layer_State.

I am trying to understand how getActiveFilters function works but not getting.

Please Help me how can i get getActiveFilters in magento.

I am trying this on the custom cms page.which is not working.

This code is working on the category page.

2 Answers 2

1

From: https://stackoverflow.com/questions/11862967/magento-get-selected-filter-in-layered-navigation

$appliedFilters = Mage::getSingleton('catalog/layer')->getState()->getFilters();

Also check this: How do i get active filters in observer method? is it useful in your case?

4
  • i had tried this but am not able to get the active filters Commented Mar 10, 2016 at 15:49
  • What is returned?, nothing at all or empty array? Im not sure but I'm thinking maybe you need to initialize "catalog/layer" when in cms page handle. Add the layer block in layout for example.
    – davidmpaz
    Commented Mar 10, 2016 at 16:13
  • it is returning empty array and i had reffered answer of marius from magento.stackexchange.com/questions/56340/… Commented Mar 10, 2016 at 16:17
  • Sorry I can not be of more help. But seems like in your referred thread they came up to a solution. You will need to work it out in your particular case I think.
    – davidmpaz
    Commented Mar 11, 2016 at 8:48
1

The following code works for me,

   <?php $mcbls = new Mage_Catalog_Block_Layer_State(); ?>
   <?php $asbclv = new Amasty_Shopby_Block_Catalog_Layer_View(); ?>
   <?php $_filters = $mcbls->getActiveFilters(); ?>
   <div class="tool-shop-by" id="tool-shop-by-containor">
        <ul class="tool-result">
          <li>
              <?php 
              foreach ($_filters as $_filter): ?>
                  <?php if ($_filter->hasData('children')): 
                    //echo "<pre>"; print_r($_filter->getData('children')); exit;?>
                      <?php foreach ($_filter->getData('children') as $child): 
                        ?>
                          <a label="<?php echo $child['label'] ?>" href="<?php echo $child['url'] ?>"><?php echo $child['label'] ?>&nbsp;<span><i class="meigeeadditional-close"></i></span></a>
                      <?php endforeach ?>
                  <?php else: 
                    //echo "<pre>123"; print_r($_filter->getData('children')); exit;?>
                      <a href="<?php echo $_filter->getRemoveUrl(); ?>"><?php echo $_filter->getLabel(); ?><span><i class="meigeeadditional-close"></i></span></a>
                  <?php endif ?>
              <?php endforeach; ?>
          </li>
        </ul>
        <?php if (count($_filters)): ?>
        <div class="actions"> <a href="<?php echo $asbclv->getClearUrl() ?>" class="clear_all">Clear all</a></div>
        <?php endif; ?>
      </div>

Your Answer

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

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