简体   繁体   English

Shopify Graphql 如何根据位置获取特定集合的可用产品

[英]Shopify Graphql how to get available products for specific collection based on location

Shopify GraphQL. I want to have a list of products for specific collection based on location. Shopify GraphQL。我想要一个基于位置的特定集合的产品列表。

Expectrd list of products.期望的产品列表。 I tried:我试过了:


query($collectionId: ID!, $locationId: ID!) {
  collection(id: $collectionId) {
    products(first: 50) {
      edges {
        node {
          id
          title
          availableForSale
          images(first: 50) {
            edges {
              node {
                id
                altText
                originalSrc
              }
            }
          }
          variants(first: 50, query: "location_id:$locationId") {
            edges {
              node {
                id
                title
                inventoryQuantity
                sku
              }
            }
          }
        }
      }
    }
  }
}

But I have an error for variants not support query但是对于不支持查询的变体我有一个错误

It is true.是真的。 Variants do not in fact have a location.变体实际上没有位置。 But they do have an inventory item ID.但他们确实有一个库存项目 ID。 And when you leverage that, you'll find you can get the inventory levels of any particular inventory item ID at locations.当您利用它时,您会发现您可以获得位置处任何特定库存项目 ID 的库存水平。

So if you were to extract the availability of an item at a location, ie) a variant, you would also know that the product the variant belongs to, is stocked at that location.因此,如果您要提取某项商品在某个位置的可用性,即变体,您还会知道该变体所属的产品在该位置有库存。

Your approach of starting with a collection, and then getting the products in that collection, and then getting the variants of each product, and then checking if the variant is stocked at one or more locations, is really really clunky.您从一个集合开始,然后获取该集合中的产品,然后获取每个产品的变体,然后检查该变体是否存放在一个或多个位置的方法确实非常笨拙。

I think instead you should extract the inventory at each location.我认为您应该提取每个位置的库存。 That would then give you products.那会给你产品。 With those products you might be able to create a collection to hold them.使用这些产品,您可以创建一个集合来保存它们。 But since location is not a criteria, you're going to have to make up something.但是由于位置不是标准,因此您将不得不编造一些东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM