According to this documentation:
https://shopify.dev/custom-storefronts/products/filter-products#query-products-by-type
We should be able to filter products within a collection using collectionByHandle
.
I have created a very basic test query in the Shopify GraphiQL App explorer tool. When I run the documented query, it returns all products, not filtering at all. See below:
This looks like a bug with the API right? Or am I missing something basic?
3
Answers
OK this turned out to be a configuration issue. To allow filtering by product type, it needs to be turned on in the admin for your store. If you navigate to: Online Store > Navigation
... and scroll to the bottom, you will see where you can add allowed filters:
Even if it says your theme doesn't support filters, it will still change the way the API behaves.
I have the same problem, the filters param of products query seem to be ineffective and returning me all the products in the collection.
I can’t find the "allowed filters" option.
Currently I’m using the Storefront API as an external app, all works fine except that.
Here the code.
const variables = { collectionHandle: this.pageURL, nQueryElements: this.nQueryElements, lastCursor: this.queryCursor.last, firstCursor: this.queryCursor.first, product__filters: [{ productVendor: "ASPESI", },], };
Thanks to who can help.
This can be done now. This post on the Shopify forum explains it perfectly with the latest API.
In case that post gets deleted, I’m going to put the info below:
We can now filter by metafields but through a collection. https://shopify.dev/custom-storefronts/products-collections/filter-products#query-products-by-metafi...
Requirements:
Discovery app" or the Filters in the Navigation settings.
boolean, numeric_integer, numeric_decimal
2022-10
Knowing that as of today, we have a limit of 5000 products for filters to work in a normal store (see https://help.shopify.com/en/manual/online-store/search-and-discovery/filters)
I decided to test if that restriction applies to the Storefront API, I tested it with a collection with 11769 products and I was able to get filtered results as expected. So it seems that at this stage we don’t have this limitation in the Storefront API
.