Development discussions around Shopify APIs
I am using the js-buy-sdk (https://shopify.github.io/js-buy-sdk/index.html) and the following code is not returning tags with the products.
client.collection.fetchWithProducts(collectionId).then((collection) => { // Do something with the collection console.log(collection); console.log(collection.products); });
Is there something I need to add?
Thanks
Solved! Go to the solution
This is an accepted solution.
I found the answer. It seems like you can't do that with fetchWithProducts(), but if you make a custom query you can. Here is the code I found
const query = client.graphQLClient.query((root) => { root.addConnection('products', { args: { first: 250, query: "collection_type:{{name of collection}}" } }, (Product) => {
Product.add('title'); Product.add('tags');// Add fields to be returned Product.addConnection('variants', { args: { first: 250 } }, (variants) => {
variants.add('product'); variants.add('title'); variants.add('price'); variants.add('sku'); }); });
}); client.graphQLClient.send(query).then(({ model, data }) => { console.log(model); });
Hope this helps anyone else.
This is an accepted solution.
I found the answer. It seems like you can't do that with fetchWithProducts(), but if you make a custom query you can. Here is the code I found
const query = client.graphQLClient.query((root) => { root.addConnection('products', { args: { first: 250, query: "collection_type:{{name of collection}}" } }, (Product) => {
Product.add('title'); Product.add('tags');// Add fields to be returned Product.addConnection('variants', { args: { first: 250 } }, (variants) => {
variants.add('product'); variants.add('title'); variants.add('price'); variants.add('sku'); }); });
}); client.graphQLClient.send(query).then(({ model, data }) => { console.log(model); });
Hope this helps anyone else.
Helpful answer but frustrating that there isn't a way to do it with fetchAll(). looks like I'll have to refactor my code to graphQL (shopify are pretty much forcing this to happen)
As an FYI you have to do the same for metafields (one you have Whitelisted them)
https://help.shopify.com/en/api/guides/metafields/storefront-api-metafields#expose-metafields-to-the...
product.addConnection('metafields', {args: {first: 20}}, (metafield) => { metafield.add('namespace') metafield.add('key') metafield.add('value') });
Ehy @Joe_Tacconelli well done about the solution but can you please be more precise about:
query: "collection_type:{{name of collection}}"
With name I guess you mean the slug. Filtering by category-slug for us is really important because doing so we avoid fetch all products.
Btw I can't implement your example as-is.
Supposing we have a cat. slug best-products how should I implement it?
Something like query: "collection_type:{{best-products}}" or query: "collection_type: best-products"
Without query prop. is working fine of course.
Thanks!
I created a package here that is just a fork of the original SDK with tags on products by default. Everything else is exactly the same.
No need to do all the other crap. Just install this.
User | RANK |
---|---|
10 | |
4 | |
3 | |
3 | |
3 |
As a business owner, have you ever wondered when your customer's first impression of yo...
By Skye Jun 6, 2023We're excited to announce improvements to the threaded messaging experience in our communi...
By TyW May 31, 2023Thank you to everyone who participated in our AMA with Klaviyo. It was great to see so man...
By Jacqui May 30, 2023