Category Specific Layered Navigation Changes (Disabling Attribute Filters) [closed]
-
16-10-2019 - |
Question
I'm trying to disable a particular attribute filter in layered navigation for a specific category. The attribute filter I wish to disable is the manufacturer in this instance.
I'm trying the following in the 'Custom Design Layout' for the category in question:-
<block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml">
<action method="unsetChild"><alias>manufacturer_filter</alias></action>
</block>
This is half working, it hides the manufacturer filter in the layered navigation, but it also hides everything else below this in catalog.leftnav
.
Any idea how the above needs modifying to prevent that from happening?
To explain what I mean, here are screenshots.
Before the XML update
After the XML update
Solution
You can achieve this if you rewrite the Mage_Catalog_Model_Layer::getFilterableAttributes
method.
For a specific category you can add a new filter.
Something like this (not tested)
public function getFilterableAttributes()
{
$setIds = $this->_getSetIds();
if (!$setIds) {
return array();
}
$collection = Mage::getResourceModel('catalog/product_attribute_collection');
$collection
->setItemObjectClass('catalog/resource_eav_attribute')
->setAttributeSetFilter($setIds)
->addStoreLabel(Mage::app()->getStore()->getId())
->setOrder('position', 'ASC');
if ($this->getCurrentCategory()->getId() == 7) {
//if in that specific category...You can even make this a category setting or a config setting so you won't hard code it.
$collection->addFieldToFilter('attribute_code', array('neq'=>'manufacturer'));
}
$collection = $this->_prepareAttributeCollection($collection);
$collection->load();
return $collection;
}