- Preselect filters before products load.
- Add or remove selected filter values.
- Set or clear a price range.
- Set or clear the product order.
- Hide or show filters.
- React when the user changes filters.
Exported Function
Your project must export a function namedprepareCollectionProductsFilters.
When It Runs
The extension receives atrigger that tells you why it is running.
Initial: runs before the application fetches products for the collection.UserFiltersChanged: runs after the user changes filters, before the application fetches the updated products.
Initial when you want to apply default filters.
Use UserFiltersChanged when you want to react to the user’s current filter selection.
Context
The function receives a context object.context.collection to know which collection is being loaded.
Use context.trigger to know why the extension is running.
Use context.filters to inspect and change the filters.
Filter Editor
Thefilters editor lets you change the selected filters and the visible filters.
boolean return true when the change was applied.
Available Filters
You can inspect the filters that are available for the collection.Filter Types
Ordering
UsesetOrder to change the product ordering.
Example: Add a Default Filter
Example: Hide a Filter
Example: Set a Price Range
Best Practices
- Keep the function fast.
- Use
Initialfor default filter rules. - Use
UserFiltersChangedfor rules that depend on the user’s current selection. - Prefer filter IDs when you know them.
- Check that a filter or value exists before applying it.
- Avoid changing filters in a way that surprises the user.