Dependant layered navigation filters in Magento

Although not the best method, we wrote a quick and easy means to remove layered navigation filters that are dependant on other filters being enabled. This code should really be in the block and popped into an extension - with the attributes administrable via the backend, but for the purposes of this tutorial - we are just going to hardcode it into the template and let you decide how you want to improve it.
  • 1

     

    Open ./app/design/frontend/default/default/template/catalogue/layer/view.phtml
  • 2

     

    Add
     getActiveFilters();
     $_depends = array(
     "fits product" => array("product manufacturer")
     );
    foreach ($_filters as $_filter):
    $_activeFilters[] = strtolower($_filter->getName());
    endforeach; 
    ?>
    
    just before getStateHtml() ?>
  • 3

     

    Replace the contents of
    ...
    with
     getFilters() ?>
     
     getItemsCount()): ?>
     
     getName())])):
     $_filterDepends = &$_depends[strtolower($_filter->getName())];
     foreach ($_filterDepends as $_filterDepend):
     if (!in_array($_filterDepend,$_activeFilters) && $_showFilter) {
    $_showFilter = false;
     }
     endforeach;
     endif; 
     ?> 
     
     
     
    __($_filter->getName()) ?>
    getHtml() ?>
  • 4

     

    Change $_depends in step 1 to reflect the names of the attributes that have dependencies on each other.
     $_depends = array(
     "fits product" => array("product manufacturer")
     );
    
    Ie. In our example, we do not want to display fits product until product manufacturer has been filtered.
[syntaxhighlighter]