当我更新具有多个变体的产品时,我收到错误响应:
{"errors":{"base":["Options are not unique"]}}
或者有时:
{"errors":{"variants":["is invalid"], "base":["Options are not unique"]}}
我正在向 /admin/products/122821632.json 之类的东西发出 PUT 请求,其中包含以下数据:
{"product":{"id":"122821632",
"body_html":"test",
"vendor":"Acme",
"title":"Monkey T-Shirt",
"variants":[{"option1":"LARGE",
"sku":"test-sku-2",
"product_id":"122821632",
"id":"282988194",
"price":"21.99",
"grams":"200"},
{"option1":"TINY",
"sku":"test-sku-1",
"product_id":"122821632",
"id":"282990692",
"price":"21.99",
"grams":"200"}],
"options":[{"position":1,
"name":"Size",
"product_id":"122821632"}]}}
但是我注意到,如果我放置一个变体,然后放置多个变体数据 JSON,它就可以工作。这确实意味着删除一个变体并重新创建它,我认为这对于插件来说是不可接受的行为,特别是因为我没有存储有关变体的所有数据,因此无法投入生产。
为此,我提出了这些 PUT 请求:
{"product":{"id":"122821632",
"body_html":"test",
"vendor":"Acme",
"title":"Monkey T-Shirt",
"variants":[{"option1":"LARGE",
"sku":"test-sku-2",
"product_id":"122821632",
"id":"282988194",
"price":"21.99",
"grams":"200"}],
"options":[{"position":1,
"name":"Size",
"product_id":"122821632"}]}}
返回 200。其次是:
{"product":{"id":"122821632",
"body_html":"test",
"vendor":"Acme",
"title":"Monkey T-Shirt",
"variants":[{"option1":"LARGE",
"sku":"test-sku-2",
"product_id":"122821632",
"id":"282988194",
"price":"21.99",
"grams":"200"},
{"option1":"TINY",
"sku":"test-sku-1",
"product_id":"122821632",
"id":"282990692",
"price":"21.99",
"grams":"200"}],
"options":[{"position":1,
"name":"Size",
"product_id":"122821632"}]}}
返回 200。其次是:
{"product":{"id":"122821632",
"body_html":"test",
"vendor":"Acme",
"title":"Monkey T-Shirt",
"variants":[{"option1":"LARGE",
"sku":"test-sku-2",
"product_id":"122821632",
"id":"282988194",
"price":"21.99",
"grams":"200"},
{"option1":"TINY",
"sku":"test-sku-1",
"product_id":"122821632",
"id":"282990692",
"price":"21.99",
"grams":"200"}],
"options":[{"position":1,
"name":"Size",
"product_id":"122821632"}]}}
这给了我错误。我删除并重新创建的变体的 ID 也发生了变化(我可以通过获取请求来判断):
{"product":{"body_html":"test",
"handle":"69",
"images":[],
"template_suffix":null,
"product_type":"Shirts",
"updated_at":"2013-03-07T11:36:51-05:00",
"variants":[{"position":1,
"option1":"LARGE",
"option2":null,
"option3":null,
"updated_at":"2013-03-07T07:30:15-05:00",
"inventory_quantity":1,
"title":"LARGE",
"product_id":122821632,
"created_at":"2013-03-06T11:03:36-05:00",
"compare_at_price":"24.99",
"fulfillment_service":"manual",
"inventory_management":"",
"sku":"test-sku-2",
"taxable":true,
"requires_shipping":true,
"price":"21.99",
"inventory_policy":"deny",
"id":282988194,
"grams":200},
{"position":2,
"option1":"TINY",
"option2":null,
"option3":null,
"updated_at":"2013-03-07T11:36:51-05:00",
"inventory_quantity":1,
"title":"TINY",
"product_id":122821632,
"created_at":"2013-03-07T11:36:51-05:00",
"compare_at_price":null,
"fulfillment_service":"manual",
"inventory_management":null,
"sku":"test-sku-1",
"taxable":true,
"requires_shipping":true,
"price":"21.99",
"inventory_policy":"deny",
"id":283397624,
"grams":200}],
"title":"Monkey T-Shirt",
"created_at":"2013-02-22T05:35:02-05:00",
"options":[{"id":147204272,
"name":"Size",
"position":1,
"product_id":122821632}],
"vendor":"Acme",
"id":122821632,
"published_at":"2013-02-22T05:35:02-05:00",
"tags":"mens t-shirt example"}}
我的印象是,对相同 URL 的相同数据的第二次 PUT 请求应该不会导致任何变化。
我究竟做错了什么?这是 Shopify API 中的错误吗?