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.

Product Filters

Product Filters

AgRachithHegde
Tourist
3 0 3

We are calling product filter query using storefront API, we have followed the same method as mentioned in the document https://shopify.dev/docs/custom-storefronts/building-with-the-storefront-api/products-collections/fi...
But we are not getting all the products which are matching the filter there in our shopify store.

API details:
URL: https://staging-test-imadeya.myshopify.com/api/2023-01/graphql.json
Header: X-Shopify-Storefront-Access-Token
Method: POST
GraphQL: 

 
query ProductFilter {
  collection(handle: "nihonshu") {
    handle
    products(
      first: 250,
      reverse: true,
    filters:[{productMetafield:{namespace:"customfilter",key:"type_of_alcohol",value:"にごり酒"}},{productMetafield:{namespace:"customfilter",key:"type_of_alcohol",value:"貴醸酒"}}]
    ) {
      edges {
        node {
        title
        }
      }
    }
  }
}
 

But from the Storefront API we are getting only: 28 

 

Replies 4 (4)

okur90
Shopify Partner
126 20 18

Hi @AgRachithHegde 

 

It looks like the issue might be related to the filter query you are using in your GraphQL request. The filters you are using seem to be searching for products with custom metafields that match either "にごり酒" or "貴醸酒". However, the products in your collection might not have these exact metafield values.

Code Slingin, Pixel Wranglin - Laugh it up at onlinex.com.au
AgRachithHegde
Tourist
3 0 3

@okur90 Thank you for the reply

We have tried the same thing in our website with Shopify plugin to filter there i can see the proper product count.

okur90
Shopify Partner
126 20 18

@AgRachithHegde 

 

try running the following query to fetch a single product with one of the specified metafield values:

 

query {
  products(first: 1, query: "customfilter:type_of_alcohol:にごり酒") {
    edges {
      node {
        id
        title
      }
    }
  }
}

 

If you're able to fetch a product using this query, it's likely that the issue has to do with the query combining both filter conditions.

 

In that case, consider using a different approach: run two separate queries, one for each filter condition, and then merge the results.

 

query ProductFilterNigoriSake {
  collection(handle: "nihonshu") {
    handle
    products(first: 250, reverse: true, query: "customfilter:type_of_alcohol:にごり酒") {
      edges {
        node {
          title
        }
      }
    }
  }
}

 

query ProductFilterKijoshu {
  collection(handle: "nihonshu") {
    handle
    products(first: 250, reverse: true, query: "customfilter:type_of_alcohol:貴醸酒") {
      edges {
        node {
          title
        }
      }
    }
  }
}

 

Run these two queries separately, and then combine the results in your application code to get the full list of products that match either of the filter conditions.

 

If you're still not getting the correct product count using these queries, double-check the access token and its permissions.

Code Slingin, Pixel Wranglin - Laugh it up at onlinex.com.au
AgRachithHegde
Tourist
3 0 3

@okur90 I have tried individual filter same issue, when the products in a collection are more than 1000 this issue is there. For the filter we are not able to fetch proper product. So we have used reverse: true then also we are not able to get all the products.