Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Storefront API - reduce variants with applied meta filters

Storefront API - reduce variants with applied meta filters

pietvanleeuwen
Shopify Partner
6 0 0

When filtering on metafields, I don't see a clear way of reducing the variants returned, that match the filter(metafield) applied to that variant. For example - 

 

 

 

collection(handle: "all") {
    handle
    products(first: 10, filters: {variantMetafield:{namespace: "filter", key: "colour", value: "Black"}}") {
      edges {
        node {
          id
          variants(first: 10) {
            id
          }
        }
      }
    }
  }

 

 

 

In this case I would expect to get all the products AND variants that match the above criteria? Or is there a way I can determine which variants match the criteria? This is important in order to display the correct image in a collection view. The default liquid templates do this but I can't find a sample using the storefront API.

Reply 1 (1)

pietvanleeuwen
Shopify Partner
6 0 0

This is the available docs on filters, for reference.

https://shopify.dev/api/examples/filter-products