Skip to main content
The Collection Filters Extension lets you change collection filters before products are fetched. It also runs again whenever the user changes the selected filters. Use this extension when you want to:
  • 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 named prepareCollectionProductsFilters.
The function can be synchronous or asynchronous. If the function returns a promise the app will wait up to 3 seconds before assuming the extension failed.

When It Runs

The extension receives a trigger that tells you why it is running.
The triggers are:
  • Initial: runs before the application fetches products for the collection.
  • UserFiltersChanged: runs after the user changes filters, before the application fetches the updated products.
Use 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.
Use 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

The filters editor lets you change the selected filters and the visible filters.
Methods that return boolean return true when the change was applied.

Available Filters

You can inspect the filters that are available for the collection.

Filter Types

Ordering

Use setOrder to change the product ordering.
Example:

Example: Add a Default Filter

Example: Hide a Filter

Example: Set a Price Range

Best Practices

  • Keep the function fast.
  • Use Initial for default filter rules.
  • Use UserFiltersChanged for 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.