如何在 Shopify 中更新产品变体中的产品选项?

How to update product options in product variant in Shopify?

我们在更新产品变体中的产品选项时面临挑战,因为 GraphQL 和 Rest API 中的选项字段完全不同。下面是 screen-shot:

GraphQL:

休息 API秒:

我们正在使用 GraphQL 改变产品变体。所以我们的挑战是,我们如何向产品变体发送三种不同的选项(例如,大、蓝色、纸),使一种变体只需要一个 [String!] 值。而在 REST API 中,有三个不同的选项(选项 1、选项 2、选项 3)以及默认标题。

此外,如果可能的话,任何人都可以为此分享一个虚拟突变请求吗?

以下是我们所指的链接:

更新产品变体:https://shopify.dev/docs/admin-api/graphql/reference/mutation/productvariantupdate?api[version]=2020-04

更新产品:https://shopify.dev/docs/admin-api/graphql/reference/mutation/productupdate?api[version]=2020-04

嗯,它实际上需要一个字符串数组 ([String!]),而不是单个字符串值。所以你需要像这样传递它 ["Large", "Blue", "Paper"],请参阅下面的详细变异请求:

查询

mutation productVariantUpdate($input: ProductVariantInput!) {
  productVariantUpdate(input: $input) {
    productVariant {
      id,
      selectedOptions {
          name,
          value
      }
    }
    userErrors {
      field
      message
    }
  }
}

变量

{
  "input": {
    "id": "gid://shopify/ProductVariant/31886472609857",
    "options": ["Large", "Blue", "Paper"]
  }
}