[英]shopify storefront api how to list products in a single collection
I am using the following graphql to list all products in all collections, I am trying to modify this now to only list products in a single collection, I know the collection ID already but I cannot figure out where to put it in order to filter on the collection ID.我正在使用以下 graphql 列出所有集合中的所有产品,我现在尝试修改它以仅列出单个集合中的产品,我已经知道集合 ID,但我不知道将它放在哪里以便过滤集合 ID。
{
shop {
collections(first: 10) {
edges {
node {
id
description
products(first: 250) {
edges {
node {
id
description
variants(first: 10) {
edges {
node {
id
sku
price
selectedOptions {
name
value
}
}
}
}
}
}
}
}
cursor
}
pageInfo {
hasNextPage
}
}
}
}
Instead of grabbing all collections and then filtering, you can just grab a collection by its handle.无需抓取所有集合然后过滤,您只需通过其句柄抓取一个集合。
{
shop {
collectionByHandle(handle: "frontpage") {
id
description
products(first: 250) {
edges {
node {
id
description
variants(first: 10) {
edges {
node {
id
sku
price
selectedOptions {
name
value
}
}
}
}
}
cursor
}
pageInfo {
hasNextPage
}
}
}
}
}
Just replace frontpage
with whatever your handle you like.只需用您喜欢的任何句柄替换
frontpage
。
Here is another answer with particular collection id wise
{
shop {
.node(id: <YOUR COLLECTION ID>) {
.onCollection {
.products(first: 10) {
pageInfo {
hasNextPage
}
edges {
node {
id
description
variants(first: 10) {
edges {
node {
id
sku
price
selectedOptions {
name
value
}
}
}
}
}
}
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.