{% comment %} Renders facets (filtering and sorting) Accepts: - results: {Object} Collection or Search object - enable_filtering: {Boolean} Show filtering when true - enable_sorting: {Boolean} Show sorting when true - filter_type: {String} Type of filter - paginate: {Object} Usage: {% render 'facets', results: collection, enable_filtering: true, enable_sorting: true, filter_type: 'vertical', paginate: paginate %} {% endcomment %} {{ 'component-show-more.css' | asset_url | stylesheet_tag }} {{ 'component-visual-display.css' | asset_url | stylesheet_tag }} {%- liquid assign sort_by = results.sort_by | default: results.default_sort_by assign total_active_values = 0 if results.url assign results_url = results.url else assign terms = results.terms | escape assign results_url = '?q=' | append: terms | append: '&options%5Bprefix%5D=last&sort_by=' | append: sort_by endif -%}
{%- if filter_type == 'vertical' or filter_type == 'horizontal' -%}
{%- if results.terms -%} {%- endif -%} {% if enable_filtering %} {% comment %} Heading is the first tabbable element on filter type horizontal {% endcomment %}
{%- if filter_type == 'horizontal' and results.filters != empty -%}

{{ 'products.facets.filter_by_label' | t }}

{%- endif -%} {% comment %} Pills are right below the title for filter type vertical {% endcomment %} {%- if filter_type == 'vertical' -%}
{%- unless results.filters == empty -%}

{{ 'products.facets.filter_by_label' | t }}

{%- endunless -%} {{ 'products.facets.clear_all' | t }}
{%- for filter in results.filters -%} {%- for value in filter.active_values -%} {{ filter.label | escape }}: {{ value.label | escape }} {% render 'icon-close-small' %} {{ 'products.facets.clear_filter' | t }} {%- endfor -%} {% if filter.type == 'price_range' %} {%- if filter.min_value.value != null or filter.max_value.value != null -%} {%- if filter.min_value.value -%} {{ filter.min_value.value | money }} {%- else -%} {{ 0 | money }} {%- endif -%} - {%- if filter.max_value.value -%} {{ filter.max_value.value | money }} {%- else -%} {{ filter.range_max | money }} {%- endif -%} {% render 'icon-close-small' %} {{ 'products.facets.clear_filter' | t }} {%- endif -%} {% endif %} {%- endfor -%}
{%- endif -%} {% comment %} Filters for both horizontal and vertical filter {% endcomment %} {%- for filter in results.filters -%} {% liquid assign total_active_values = total_active_values | plus: filter.active_values.size case filter.presentation when 'swatch' assign has_visual_display = true assign show_more_number = 15 assign visual_layout_class = 'facets-layout-grid facets-layout-grid--' | append: filter.presentation else assign has_visual_display = false assign visual_layout_class = 'facets-layout-list' assign show_more_number = 10 endcase %} {% case filter.type %} {% when 'boolean', 'list' %}
{{- filter.label | escape }} {%- if filter_type == 'vertical' -%} ({{ filter.active_values.size }}) {%- endif -%} {%- if filter_type == 'vertical' and filter.operator == 'AND' -%} {{ 'products.facets.filter_and_operator_subtitle' | t }} {%- endif -%} {% render 'icon-caret' %}
{%- if filter_type != 'vertical' -%}
{{- 'products.facets.filters_selected' | t: count: filter.active_values.size -}} {%- if filter.operator == 'AND' -%} {{ 'products.facets.filter_and_operator_subtitle' | t }} {%- endif -%}
{{ 'products.facets.reset' | t }}
{%- endif -%}
{{ filter.label | escape }}
    {%- liquid assign sorted_values = filter.values # Keep the selected values grouped together when operator is AND if filter.operator == 'AND' assign active_filter_values = filter.values | where: 'active', true assign inactive_filter_values = filter.values | where: 'active', false assign sorted_values = active_filter_values | concat: inactive_filter_values endif -%} {%- for value in sorted_values -%} {% liquid assign is_disabled = false if value.count == 0 and value.active == false assign is_disabled = true endif %}
  • {%- endfor -%}
{% comment %} No show more for no JS {% endcomment %}
    {%- for value in filter.values -%}
  • {%- endfor -%}
{%- if filter.values.size > show_more_number and filter_type == 'vertical' -%} {%- endif %}
{% when 'price_range' %} {% liquid assign currencies_using_comma_decimals = 'ANG,ARS,BRL,BYN,BYR,CLF,CLP,COP,CRC,CZK,DKK,EUR,HRK,HUF,IDR,ISK,MZN,NOK,PLN,RON,RUB,SEK,UYU,VES,VND' | split: ',' assign uses_comma_decimals = false if currencies_using_comma_decimals contains cart.currency.iso_code assign uses_comma_decimals = true endif %}
{{ filter.label | escape }} {% render 'icon-caret' %}
{%- assign max_price_amount = filter.range_max | money | strip_html | escape -%} {{- 'products.facets.max_price' | t: price: max_price_amount -}} {%- if filter_type != 'vertical' -%} {{ 'products.facets.reset' | t }} {%- endif -%}
{{ cart.currency.symbol }}
{%- if filter_type != 'vertical' -%} {{ cart.currency.symbol }} {%- endif -%}
{% endcase %} {%- endfor -%}
{% comment %} Pills after filtes on filter type horizontal {% endcomment %} {%- if filter_type == 'horizontal' -%} {%- endif -%} {% endif %} {% if results.current_vendor or results.current_type %} {% endif %} {%- if filter_type == 'horizontal' -%} {% comment %} Sorting and product count are the last elements when filter type is horizontal {% endcomment %} {%- if enable_sorting -%}

{%- assign sort_by = results.sort_by | default: results.default_sort_by -%} {% render 'icon-caret' %}
{%- endif -%}

{%- if results.results_count -%} {{ 'templates.search.results_with_count' | t: terms: results.terms, count: results.results_count }} {%- elsif results.products_count == results.all_products_count -%} {{ 'products.facets.product_count_simple' | t: count: results.products_count }} {%- else -%} {{ 'products.facets.product_count' | t: product_count: results.products_count, count: results.all_products_count }} {%- endif -%}

{%- render 'loading-spinner' -%}
{%- endif -%}
{% comment %} Sorting for vertical filter are grouped with filter when no JS{% endcomment %} {%- if enable_sorting and filter_type == 'vertical' -%}

{%- assign sort_by = results.sort_by | default: results.default_sort_by -%} {% render 'icon-caret' %}
{% if results.current_vendor or results.current_type %} {% endif %} {%- if results.terms -%} {%- endif -%}
{%- endif -%} {%- endif -%} {% comment %} Drawer and mobile filter {% endcomment %}
{% render 'icon-filter' %} {%- if enable_filtering and enable_sorting -%} {{ 'products.facets.filter_and_sort' | t }} {%- elsif enable_filtering -%} {{ 'products.facets.filter_button' | t }} {%- elsif enable_sorting -%} {{ 'products.facets.sort_button' | t }} {%- endif -%} {%- if enable_filtering -%} {{ 'products.facets.filter_button' | t }} {%- endif -%} {%- render 'icon-close' -%}

{%- if enable_filtering and enable_sorting -%} {{ 'products.facets.filter_and_sort' | t }} {%- elsif enable_filtering -%} {{ 'products.facets.filter_button' | t }} {%- elsif enable_sorting -%} {{ 'products.facets.sort_button' | t }} {%- endif -%}

{%- if enable_filtering -%} {{ 'products.facets.filter_button' | t }} {%- endif -%}

{%- if results.results_count -%} {{ 'templates.search.results_with_count' | t: terms: results.terms, count: results.results_count }} {%- elsif results.products_count == results.all_products_count -%} {{ 'products.facets.product_count_simple' | t: count: results.products_count }} {%- else -%} {{ 'products.facets.product_count' | t: product_count: results.products_count, count: results.all_products_count }} {%- endif -%}

{%- if enable_filtering -%} {%- for filter in results.filters -%} {% liquid case filter.presentation when 'swatch' assign has_visual_display = true assign visual_layout_class = 'facets-layout-grid facets-layout-grid--' | append: filter.presentation else assign has_visual_display = false assign visual_layout_class = 'facets-layout-list' endcase %} {% case filter.type %} {% when 'boolean', 'list' %}
{{ filter.label | escape }} {% render 'icon-arrow' %}
    {%- liquid assign sorted_values = filter.values # Keep the selected values grouped together when operator is AND if filter.operator == 'AND' assign active_filter_values = filter.values | where: 'active', true assign inactive_filter_values = filter.values | where: 'active', false assign sorted_values = active_filter_values | concat: inactive_filter_values endif -%} {%- for value in sorted_values -%} {% liquid assign is_disabled = false if value.count == 0 and value.active == false assign is_disabled = true endif %}
  • {%- endfor -%}
{% when 'price_range' %} {% liquid assign currencies_using_comma_decimals = 'ANG,ARS,BRL,BYN,BYR,CLF,CLP,COP,CRC,CZK,DKK,EUR,HRK,HUF,IDR,ISK,MZN,NOK,PLN,RON,RUB,SEK,UYU,VES,VND' | split: ',' assign uses_comma_decimals = false if currencies_using_comma_decimals contains cart.currency.iso_code assign uses_comma_decimals = true endif %}
{{ filter.label | escape }} {% render 'icon-arrow' %}
{%- assign max_price_amount = filter.range_max | money | strip_html | escape -%}

{{ 'products.facets.max_price' | t: price: max_price_amount }}

{{ cart.currency.symbol }}
{{ cart.currency.symbol }}
{% endcase %} {%- endfor -%} {%- endif -%} {%- if enable_sorting -%}
{% render 'icon-caret' %}
{%- endif -%}
{% if results.current_vendor or results.current_type %} {% endif %} {%- if results.terms -%} {%- endif -%}
{%- for filter in results.filters -%} {%- for value in filter.active_values -%} {{ filter.label | escape }}: {{ value.label | escape }} {% render 'icon-close-small' %} {{ 'products.facets.clear_filter' | t }} {%- endfor -%} {%- if filter.type == 'price_range' -%} {%- if filter.min_value.value != null or filter.max_value.value != null -%} {%- if filter.min_value.value -%} {{ filter.min_value.value | money }} {%- else -%} {{ 0 | money }} {%- endif -%} - {%- if filter.max_value.value -%} {{ filter.max_value.value | money }} {%- else -%} {{ filter.range_max | money }} {%- endif -%} {% render 'icon-close-small' %} {{ 'products.facets.clear_filter' | t }} {%- endif -%} {%- endif -%} {%- endfor -%} {{ 'products.facets.clear_all' | t }}
{% comment %} Sort, product count and filter pills at the end when filter is type of Drawer for the correct tabbing order {% endcomment %} {%- if enable_sorting and filter_type == 'drawer' -%}

{%- assign sort_by = results.sort_by | default: results.default_sort_by -%} {% render 'icon-caret' %}
{% if results.current_vendor or results.current_type %} {% endif %} {%- if results.terms -%} {%- endif -%}
{%- endif -%}

{%- if results.results_count -%} {{ 'templates.search.results_with_count' | t: terms: results.terms, count: results.results_count }} {%- elsif results.products_count == results.all_products_count -%} {{ 'products.facets.product_count_simple' | t: count: results.products_count }} {%- else -%} {{ 'products.facets.product_count' | t: product_count: results.products_count, count: results.all_products_count }} {%- endif -%}

{%- render 'loading-spinner' -%}
{%- if filter_type == 'drawer' -%}
{%- endif -%}