Join us for an upcoming Shopify Partner webinar on February 27, 2024. Discover the latest Checkout Extensibility features, and deep dive on improvements to Shopify Functions and Web Pixels. Register now for either the 10am EST or 2pm EST sessions.

variantOption - Unexpected behavior when using filters in collections

alek07
Visitor
2 0 0

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.

Replies 2 (2)

SomeUsernameHe
Shopify Partner
455 49 83

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. 

Have I helped? Consider putting coffee in my mouth!
Buy Me a Coffee
alek07
Visitor
2 0 0

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.