Php 使用API对产品元字段进行Shopify

Php 使用API对产品元字段进行Shopify,php,api,shopify,Php,Api,Shopify,据我所知,我们应该能够使用类似类型的JSON批量更新产品元字段,如下所示: $updateInfo = array ( "metafields" => [ [ "namespace" => "product_info", "key" => "available", "value" => $available,

据我所知,我们应该能够使用类似类型的JSON批量更新产品元字段,如下所示:

$updateInfo = array (
        "metafields" => [
              [
                  "namespace" => "product_info",
                  "key" => "available",
                  "value" => $available,
                  "value_type" => "string",
                  "description" => "Planned release date"
              ],
              [
                  "namespace" => "product_info",
                  "key" => "length",
                  "value" => sprintf("%.2f", $indLength),
                  "value_type" => "string",
                  "description" => "Item length"
              ],
                        ....]);
我正在使用PHP Shopify SDK,让任何想知道…现在如果一个字段没有任何元字段…它工作正常,但只要API需要更新,它就会抛出一个关于唯一键的错误

我有没有别的办法?我在产品端点上调用API,而不是元域端点。 像这样:

$rez = $shopify->Product($product['id'])->put($updateInfo);

感谢您的帮助。

一旦创建了元字段,您必须传递元字段ID才能更新它们

$updateInfo = array (
  "metafields" => [
    [
      "id" => $availableMetafieldId,
      "namespace" => "product_info",
      "key" => "available",
      "value" => $available,
      "value_type" => "string",
      "description" => "Planned release date"
    ],
    [
      "id" => $lengthMetafieldId,
      "namespace" => "product_info",
      "key" => "length",
      "value" => sprintf("%.2f", $indLength),
      "value_type" => "string",
      "description" => "Item length"
    ],
]);
用您的值替换
$availableMetafieldId
$lengthMetafieldId