Closed nitech closed 4 years ago
There is a pre-filter feature by adding a second parameter on the setup twig function. Json format with field handle and the values to be filtered. Checkout customization readme for an example implementation
Thanks @pdaleramirez. I know of the pre-filter, and I'm using it. What I'm really asking is how I can somehow associate a certain Super Filter setup with a category. And I am suggesting that you might expose Super Filter setups as possible values for a dropdown-field.
Or am I overlooking some obvious way to solve this?
What about passing url params to twig setup like this:
So for example, if you have a route url myshop.com/products/steamkjeler
your twig set up would be
{% set categorySlug = craft.request.getSegment(2) %}
{% set currentCategory = craft.categories.where({'slug': categorySlug }).one() %}
{{ craft.superFilter.setup('siteProducts', {
productFamilyField: [currentCategory.id]
}) }}
That way you get different pre-filter for every page category
Thanks (and sorry for a late reply).
I solved this in the following manner:
The values of the dropdown represent each super filter and are manually inserted:
productFilter
from the current category or default to the default filter if no category selected:{% if category is defined %}
{# Specific product category #}
{# Get super filter type from Product Family Category's productFilter field - or get default value #}
{% set superFilterSetup = category.productFilter.value|default('general') %}
{{
craft.superFilter.setup(superFilterSetup,
{
filter: {
productFamily: category.id
}
})
}}
{% else %}
{# Start page of products - create generic super filter for all products and replace 'kompressorer' #}
{{ craft.superFilter.setup('general') }}
{% endif %}
Is it possible to associate a certain setup with a category? In my case, I have a productFamily category. Every product is associated with at least one productFamily category.
I create a nav from the productFamily items, and allow the user to click one of the nav items to pre-filter which products should be displayed.
It would be nice to be able to associate a filter setup with a certain category (perhaps by exposing super filter setups as a field type?)