Layered navigation - filter by other categories

Using multi-level navigation, how can I let customers filter products based on other product categories that appear in?

I am working on a clothing store that has products organized in the following categories:

  • Tops
    • T-shirts
    • Dress Shirts
  • Bottoms
    • jeans
    • Shorts
  • Swim wear
  • Outerwear
  • Accessories
    • Belts
    • Communications

We would like to add special collections such as Winter Collection or Interviews. These special categories fall under a separate root category (and have an attribute set to a special value, so we can distinguish between ordinary categories and these special ones). All products in them will also be tied to the main categories.

If a user views the Winter Collection, they should be able to filter based on these main categories . If the jacket exists in the winter collection and Outwear category, we should show Outerwear as an option for filtering. Only relevant categories should appear; for example, we will not have bathing suits in the Winter collection, so the Swim Wear category should not appear.

The idea is that we don’t want to duplicate these main categories for each collection - we already know what type of clothes she is (based on the category), so our collections should be aware of this.

How can I do that?

+4
source share
2 answers

The long-term solution is to create a new attribute in the form of multi-select and fill it with all your categories. Then you have to go through each product and select all the “categories” that apply.

The problem with this approach is that in the filters the categories will be displayed as a flat list and not a tree structure, for example:

Example category filter

I think it will be worse. I think filters are automatically sorted alphabetically?

There may be a plugin to do what you need.

+1
source

I was able to find a decent solution that basically works. I post it here if anyone has a similar question.

The only disadvantages:

  • Categories are not displayed in the tree structure (for now - are working on it)
  • Clicking on the removal of a category filter maintains the category tree, as usual, except that it completely fits the root, which was unacceptable. My workaround was to force the X icon to completely remove the filter, rather than go to the parent category.

Details

The first step was to add a new attribute in the "special_type" category. This drop-down list allows administrators to choose whether the category will act as the main category (in my bullet list) or a special "collection".

The next step was to redefine the functionality inside Mage_Catalog_Model_Layer_Filter_Category :: _ getItemsData (), where $categories populated. If $this->getLayer()->getCurrentCategory()->getSpecialType() == is the default type, I call the original method ( return parent::_getItemsData() ). Otherwise...

I pass $this->getLayer()->getProductCollection() into a custom method that determines which standard categories will be displayed. I use the following filters in my query:

  • Exclude custom categories
  • Exclude the currently filtered category
  • Show only top level categories

The last two basically allow this functionality: if I filter on tops now, show only child categories of Tops and nothing more.

The custom method returns a set of categories that match my criteria, and is assigned $categories . The rest of the method remains untouched.

Hope this helps someone in a similar situation.

+1
source

Source: https://habr.com/ru/post/1440335/


All Articles