Focusing on managing products, variants, and collections through the API.
Hey all, I'm trying to filter the products variants of my collections using the filters and variantOption properties. I have been following this guide from the official doc https://shopify.dev/docs/custom-storefronts/building-with-the-storefront-api/products-collections/fi... and this is the query I'm testing to fetch my data
query getCollection($idCollection: ID) {
collection(id: $idCollection) {
id
title
products(
first: 10
filters: { variantOption: { name: "Color", value: "Black" } }
) {
edges {
node {
id
title
description
totalInventory
variants(first: 5) {
edges {
node {
id
title
price {
amount
}
compareAtPrice {
amount
}
selectedOptions {
name
value
}
}
}
}
featuredImage {
url
}
}
}
}
}
}
However, in my response, I get all the product variants and not just the one that I'm filtering with the variant options. I just want to know if there is something missing in my query or if there is some other way to achieve this.
I found a similar issue here: https://github.com/Shopify/storefront-api-feedback/discussions/120
Looks like it was solved by these steps:
Did you enable the product type in the "Collection and search filters" section in the Shopify admin?
That was it. Steps to solve.
Open Store Admin -> Sales Channels -> Online Store -> Navigation
Add "Search & Discovery App" by Shopify
Now you can edit "Collection and search filters" in the app settings.
Let me know if this helped, if not I will try and recreate this.
Just add the "Search & Discovery App" in my Shopify admin but there is not a "Collection and search filters" option, there is just a filters option and I added the Color and Warehouse options in there but when testing the query it still returning all variants.