使用 API 的 Shopify 产品元字段
Shopify product metafields with API
根据我的阅读,我们应该能够使用类似的类型 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需要更新,它会抛出关于唯一键的错误...
有没有其他方法可以解决这个问题?我在 Product 端点上调用 API,而不是 Metafield 端点。
像这样:
$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
。
根据我的阅读,我们应该能够使用类似的类型 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需要更新,它会抛出关于唯一键的错误...
有没有其他方法可以解决这个问题?我在 Product 端点上调用 API,而不是 Metafield 端点。 像这样:
$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
。