Reputation: 8647
Using layered navigation, how can I let customers filter products based on other categories the products appear in?
I'm working on a clothing store that has products organized into categories like this:
We'd like to add special collections, such as "Winter Collection" or "Interview Attire". These special categories fall under a separate root category (and have an attribute set to special value, so we can differentiate between normal categories and these special ones). All products within these will also be assigned to the main categories.
If a user is browsing the Winter Collection, they should be able to filter based on those main categories. If a jacket exists in the Winter Collection and the Outwear category, we should show Outerwear as an option to filter on. Only relevant categories should appear; for example, we won't have swim suits in the Winter Collection, so the Swim Wear category should not appear.
The idea is that we don't want to duplicate those main categories for each collection - we already know what type of clothing it is (based on the category), so our collections should be aware of that.
How can this be done?
Upvotes: 4
Views: 1870
Reputation: 8647
I was able to figure out a decent solution which mostly works. I'm posting it here in case someone else has a similar question.
The only drawbacks are:
First step was to add a new attribute to categories called "special_type". This dropdown allows admins to select whether the category acts as a core category (per my bullet list) or a special "collection".
The next step was to override the functionality inside Mage_Catalog_Model_Layer_Filter_Category::_getItemsData() where $categories
is populated. If $this->getLayer()->getCurrentCategory()->getSpecialType() ==
the default type, I call the original method (return parent::_getItemsData()
). Otherwise...
I pass $this->getLayer()->getProductCollection()
into a custom method which determines which standard categories this appears in. I use the following filters in my query:
The last two basically allow this functionality: if I'm currently filtering on Tops, only show child categories of Tops and nothing else.
The custom method returns a collection of categories matching my criteria and get assigned to $categories
. The rest of the method is left intact.
Hope this helps somebody in a similar situation.
Upvotes: 1
Reputation: 14862
A long-winded solution is to create a new attribute as a multi-select, and populate this with all of your categories. You would then have to go through every product and select all the 'categories' that apply.
The problem with this approach is that in the filters the categories will appear as a flat list, as opposed to a tree structure, e.g:
I think it would be worse than that. I think the filters auto-sort alphabetically?
There may be a plugin to do what you are after.
Upvotes: 1