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

时间:2020-05-19 13:27:20

标签: graphql shopify shopify-api

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

GraphQL: enter image description here

REST API: enter image description here

我们正在使用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

1 个答案:

答案 0 :(得分:2)

好吧,它实际上需要一个字符串数组([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"]
  }
}