By default Magento will display every attribute with a status of 'Filterable' on layered navigation. I want to be able to decide which filterable attributes appear on each category page.
It's important to note that I need the same product to display different filterable attributes on different category pages. It's also important to note that a category may contain products from several different attribute sets, so I cannot do this via Attribute sets.
For example, let's say I have attributes A, B and C and I have two category pages, CAT1 and CAT2. By default the filters would appear:
CAT1
- A (option 1, 2 etc)
- B (option 1, 2 etc)
- C (option 1, 2 etc)
CAT2
- A (option 1, 2 etc)
- B (option 1, 2 etc)
- C (option 1, 2 etc)
I want the option to be able to say CAT1 should only display attribute B and C whilst CAT2 should display A and C; thus it would appear:
CAT1
- B (option 1, 2 etc)
- C (option 1, 2 etc)
CAT2
- A (option 1, 2 etc)
- C (option 1, 2 etc)
Again, it's important to note that the two categories could contain exactly the same products…it's just that I want to be able to decide which attributes can be filtered depending on the category.
In the actual site I have > 100 categories
and > 3000 products
. There's also an admin team so whatever solution I implement can't be hard coded – the users have to be able to amend for each category page.
Anyone heard of any solution like this? Or is this a bespoke bit of development work I'm looking at here?
Best Answer
This is a broad subject. Most probably you won't get a fully working answer, but I can give you some tips on where to start.
I would add 2 more category attributes:
One being a yes/no attribute called
Use custom filter attributes
with the codeuse_custom_filters
. If this is set tono
then all the available attributes will be used in the filters.The second attribute should be a multiselect with all the attributes available for filtering. let's call it
Attributes for filter
with codefilter_attributes
.You can get the product attributes available for filtering like this:
Here is a tutorial on how to add a category attribute.
Also here is a tutorial on how to add an attribute with custom options. The example is for products, but it works the same for categories. Just replace
catalog_product
withcatalog_category
.Now you need to change the functionality that determines the filterable attributes.
This happens in the layer model: https://github.com/OpenMage/magento-mirror/blob/magento-1.9/app/code/core/Mage/Catalog/Model/Layer.php#L215.
You just need to rewrite that method and check if you are in a category context (if
Mage::registry('current_category')
returns something other thannull
).then check this ($collection is the variable in the method mentioned):
Not sure if
getFilterAttributes
will return an array or a string. If it returns a string you just have toexplode
it by comma before using it.