3
votes

I am creating a custom storefront using Shopify's BUY SDK.

import Client from 'shopify-buy'

const client = Client.buildClient({
  domain: 'xxxxxxxxxxx.myshopify.com',
  storefrontAccessToken: 'xxxxxxxxxxxxxxxxxe6347d45b08'
})

I have no problem fetching all products:

client.product.fetchAll().then((products) => {
  // Do something with the products
  console.log(products)
})

I also have no problem filtering by tag:

let query = {
  query: "tag:[aeropress,espresso]"
}  
client.product.fetchQuery(query).then((products) => {
  console.log(products)
})

and no problem fetching by product_type:

let query = {
  query: "product_type: Coffe Beans"
}  
client.product.fetchQuery(query).then((products) => {
  console.log(products)
})

where I am running into a problem is filtering with multiple queries (in this case, tag and product_type). I have tried a couple of different ways to structure the query to no avail:

let query = {
  query: "product_type: Coffe Beans, tag: [aeropress, espresso]"
}

let query = {
  query: "{product_type: Coffe Beans, tag: [aeropress, espresso]}"
}

I'm sure there's something simple that I am missing (or maybe its not possible to query with multiple filters?). Has anybody else had success using the Shopify Buy SDK with multiple filters?

For reference, I am following these docs:

https://shopify.github.io/js-buy-sdk/

https://help.shopify.com/api/storefront-api/reference/object/shop#products

https://github.com/Shopify/js-buy-sdk/blob/master/tutorials/MIGRATION_GUIDE.md

1

1 Answers

2
votes

You can try using multiple filters with AND, OR as the following query:

let query = {
  query: "product_type:'Coffe Beans' AND tag:'aeropress' OR tag:'espresso'"
}

So you can add as many items with types with multiple conditions

it looks similar to the storefront search query as described in the following link: https://help.shopify.com/manual/sell-online/online-store/storefront-search

I already test similar thing on the shopify-buy v1.0.2 and it works fine.

Hope this will help.