Magento 1 – How to Hide Attribute in Layered Navigation for Specific Category

attributeslayered-navigationmagento-1

Is it a way to hide an attribute in Layering Navigation for a specified category? I have a category which join products with different attribute sets. In this case layering navigation becomes very long as content. I would like to hide some attributes especially in that category, not in others.

Is there an extension or code to allow me using custom layout xml for that category to exclude some attributes?

Best Answer

In my opinion the best flexible way is using "Custom Layout Update" feature in a category the place where you can set some layout tags to hide one or more filters. It is like hiding Categories block in Layering Navigation when you search for something using local.xml (method unsetChild). – ADDISON74

We required this too and we use a very similiar solution as zhartaunik has suggested ...

You have to modifiy/rewrite Mage_Catalog_Block_Layer_View and

Add:

/**
 * Get all excluded attributes of current category
 *
 * @return array
 */
protected function _getExcludedAttributes()
{
    if (!is_array($this->getData('_excluded_attributes')))  {
        $attributes = array_map('trim', explode(',', $this->getData('_excluded_attributes')));
        $this->setData('_excluded_attributes', $attributes);
    }
    return $this->getData('_excluded_attributes');
}

And change

public function getFilters()
{
    $filters = array();
    if ($categoryFilter = $this->_getCategoryFilter()) {
        $filters[] = $categoryFilter;
    }

    $filterableAttributes = $this->_getFilterableAttributes();
    $excludedAttributes   = $this->_getExcludedAttributes(); # added
    foreach ($filterableAttributes as $attribute) {
        if (!in_array($attribute->getAttributeCode(), $excludedAttributes)) { # added
            $filters[] = $this->getChild($attribute->getAttributeCode() . '_filter');
        }
    }

    return $filters;
}

Now you can go to local.xml or "Custom Layout Update" and add this:

<reference name="catalog.leftnav">
    <action method="setData">
        <type>_excluded_attributes</type>
        <code>price,manufacturer</code>
    </action>
</reference>
Related Topic