简体   繁体   English

shopify storefront api 如何在单个集合中列出产品

[英]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.

相关问题 Shopify Storefront GraphQL 过滤集合内的产品 - Shopify Storefront GraphQL filtering products within a collection 使用Shopify Storefront API来获取集合图像 - Using Shopify Storefront API to fetch Collection Image 如何根据 product_type 过滤使用 shopify 店面 graphQL api 中的 collectionByHandle 检索的产品? - How to filter the products based on product_type, that are retrieved using collectionByHandle in shopify storefront graphQL api? 我们可以使用店面 GQL API 按重量过滤 shopify 产品吗? - Can we filter shopify products by weight using storefront GQL API? shopify店面导航菜单怎么和API搞定? - How to shopify storefront navigation menu get with API? 如何在 shopify 店面 API 上创建购物车 - How to create a cart on the shopify storefront API Shopify Storefront API:从页面或集合中获取元字段 - Shopify Storefront API: Getting metafields from page or collection 如何通过 Shopify API 从 Smart Collection 中检索所有产品? - How to retrieve all products from a Smart Collection through Shopify API? 使用 Storefront API 如何查询特定集合中的产品? - Using the Storefront API how can I query for products within a specific collection? 在Shopify API中,是否可以检索集合中产品的订购? - In the Shopify API, is it possible to retrieve the ordering of products in a collection?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM