Supporting Storefront Filtering
Storefront filtering lets merchants quickly make filters for collection and search results pages. Filters use current product data like availability, price, variant options, and more.
In this guide, you will see how to add storefront filtering to your theme.
Resources
To implement storefront filtering, you will use the following resources:
- Filter object
- Depending on the page you are working on, choose one of the following:
Implementing Storefront Filtering
To support storefront filtering, you need to implement a filter for customers to interact with.
Filters applied are reflected through URL parameters, so you should also familiarize yourself with the structure of filter URL parameters.
Filters must be created in the SHOPLINE backend before they can be applied.
The Filter Display
Collections with more than 5,000 products do not display filters.
The following sections outline the basic implementation of filters for collections and search results. Each implementation uses a form to host the filter inputs, with a submit button to apply the associated filters. However, you can use JavaScript to automatically submit the form based on input changes. Once the form is submitted, the page will refresh and apply the filters.
Upon form submission, the page will refresh and apply the filters.
For more advanced solutions, refer to Seed's implementation.
Collection Filters
Collection filters should be included in the collection template or referenced by content included by the collection template
.
The example implementation below includes two main components:
- A list of filter groups and their values.
- A list of active filters, if any.
Each of these components is output through the collection object's filters
attribute and the associated filter
object.
<form class="filter-form">
<details class="filter-group">
<summary class="filter-group-summary">
<div>
<span></span>
<span>()</span>
</div>
</summary>
<div class="filter-group-box">
<div class="filter-group-box__header">
<span class="filter-group-box__header-selected"> selected</span>
<a href="" class="filter-group-box__header-reset">Reset</a>
</div>
<ul class="facets__list">
<li class="facets__item">
<label for="Filter--" class="facet-checkbox">
<input
id="Filter--"
type="checkbox"
name=""
value=""
checked
/>
<span>
</span>
</label>
</li>
</ul>
<div class="filter-group-box__submit">
<input type="submit" value="Apply">
</div>
<div class="filter-group-box__price-range">
<div class="filter-group-box__price-range-from">
<span></span>
<input
name=""
id="Filter-"
value=""
type="number"
placeholder="0"
min="0"
max=""
>
<label for="Filter-">From</label>
</div>
<div class="filter-group-box__price-range-to">
<span></span>
<input name=""
id="Filter-"
value=""
type="number"
placeholder=""
min="0"
max=""
>
<label for="Filter-">To</label>
</div>
</div>
<div class="filter-group-box__submit">
<input type="submit" value="Apply">
</div>
</div>
</details>
<div class="active-filters">
<a href="?sort_by=" class="active-filters__clear">Clear all</a>
<a class="active-filters__remove-filter" href="">
- X
</a>
<a class="active-filters__remove-filter" href="">
: X
</a>
</div>
</form>
Search Results Filters
Search results with more than 1,000 products do not display filters.
Search result filters should be included in the search template or referenced by content included by the search template
.
The example implementation below includes two main components:
- A list of filter groups and their values.
- A list of active filters, if any.
Each of these components is output through the search object's filters
attribute and the associated filter
object.
If filters are applied on the search results page, all non-product results are filtered out.
<form class="filter-form">
<details class="filter-group">
<summary class="filter-group-summary">
<div>
<span></span>
<span>()</span>
</div>
</summary>
<div class="filter-group-box">
<div class="filter-group-box__header">
<span class="filter-group-box__header-selected"> selected</span>
<a href="" class="filter-group-box__header-reset">Reset</a>
</div>
<ul class="facets__list">
<li class="facets__item">
<label for="Filter--" class="facet-checkbox">
<input
id="Filter--"
type="checkbox"
name=""
value=""
checked
/>
<span>
</span>
</label>
</li>
</ul>
<div class="filter-group-box__submit">
<input type="submit" value="Apply">
</div>
<div class="filter-group-box__price-range">
<div class="filter-group-box__price-range-from">
<span></span>
<input
name=""
id="Filter-"
value=""
type="number"
placeholder="0"
min="0"
max=""
>
<label for="Filter-">From</label>
</div>
<div class="filter-group-box__price-range-to">
<span></span>
<input name=""
id="Filter-"
value=""
type="number"
placeholder=""
min="0"
max=""
>
<label for="Filter-">To</label>
</div>
</div>
<div class="filter-group-box__submit">
<input type="submit" value="Apply">
</div>
</div>
</details>
<div class="active-filters">
<a href="?sort_by=&keyword=" class="active-filters__clear">Clear all</a>
<a class="active-filters__remove-filter" href="">
- X
</a>
<a class="active-filters__remove-filter" href="">
: X
</a>
</div>
</form>
Error loading component.