尝试在 Shopify 中添加变体时出错
Posted
技术标签:
【中文标题】尝试在 Shopify 中添加变体时出错【英文标题】:Error when trying to add a variant in Shopify 【发布时间】:2017-02-08 13:42:27 【问题描述】:我正在尝试向现有产品 ID 添加一个变体。 下面是我完成的 JSON 请求。但是我得到一个错误
"errors":"variant":"expected Array to be a Hash"
JSON 请求。
"variant": ["product_id": 10065509898,"title": "XS\/ BROWN","price": 49.05,"sku": "BA1015_BROWN_XS","position": 1,"grams": 0,"inventory_policy": "deny","compare_at_price": null,"fulfillment_service": "manual","inventory_management": "shopify","option1": "BROWN","option2": "XS","option3": null,"taxable": true,"barcode": "800123054849","inventory_quantity": 0,"old_inventory_quantity": 0,"inventory_quantity_adjustment": 1,"weight": 1,"weight_unit": "lb","requires_shipping": true,"product_id": 10065509898,"title": "S\/ BROWN","price": 49.05,"sku": "BA1015_BROWN_S","position": 2,"grams": 0,"inventory_policy": "deny","compare_at_price": null,"fulfillment_service": "manual","inventory_management": "shopify","option1": "BROWN","option2": "S","option3": null,"taxable": true,"barcode": "800123054856","inventory_quantity": 0,"old_inventory_quantity": 0,"inventory_quantity_adjustment": 1,"weight": 1,"weight_unit": "lb","requires_shipping": true,"product_id": 10065509898,"title": "M\/ BROWN","price": 49.05,"sku": "BA1015_BROWN_M","position": 3,"grams": 0,"inventory_policy": "deny","compare_at_price": null,"fulfillment_service": "manual","inventory_management": "shopify","option1": "BROWN","option2": "M","option3": null,"taxable": true,"barcode": "800123054863","inventory_quantity": 0,"old_inventory_quantity": 0,"inventory_quantity_adjustment": 1,"weight": 1,"weight_unit": "lb","requires_shipping": true,"product_id": 10065509898,"title": "L\/ BROWN","price": 49.05,"sku": "BA1015_BROWN_L","position": 4,"grams": 0,"inventory_policy": "deny","compare_at_price": null,"fulfillment_service": "manual","inventory_management": "shopify","option1": "BROWN","option2": "L","option3": null,"taxable": true,"barcode": "800123054870","inventory_quantity": 0,"old_inventory_quantity": 0,"inventory_quantity_adjustment": 1,"weight": 1,"weight_unit": "lb","requires_shipping": true,"product_id": 10065509898,"title": "XL\/ BROWN","price": 49.05,"sku": "BA1015_BROWN_XL","position": 5,"grams": 0,"inventory_policy": "deny","compare_at_price": null,"fulfillment_service": "manual","inventory_management": "shopify","option1": "BROWN","option2": "XL","option3": null,"taxable": true,"barcode": "800123054887","inventory_quantity": 0,"old_inventory_quantity": 0,"inventory_quantity_adjustment": 1,"weight": 1,"weight_unit": "lb","requires_shipping": true,"product_id": 10065509898,"title": "XXL\/ BROWN","price": 49.05,"sku": "BA1015_BROWN_XXL","position": 6,"grams": 0,"inventory_policy": "deny","compare_at_price": null,"fulfillment_service": "manual","inventory_management": "shopify","option1": "BROWN","option2": "XXL","option3": null,"taxable": true,"barcode": "800123054894","inventory_quantity": 0,"old_inventory_quantity": 0,"inventory_quantity_adjustment": 1,"weight": 1,"weight_unit": "lb","requires_shipping": true]
我做错了什么?
【问题讨论】:
您在哪个 URL 上进行 RESTful 调用?是 PUT 还是 POST?产品中是否已经存在任何变体? 【参考方案1】:这是因为您要发送一系列变体。您必须单独add each variant:
POST /admin/products/product_id/variants.json
"variant":
"option1": "BROWN",
"price": "49.05",
"sku": "BA1015_BROWN_XS"
只有当你是creating a new product时,你才能传递一个变体数组。
【讨论】:
您还可以在产品上使用“PUT”添加多个变体。 @HymnZ 要小心,因为它会替换现有的变体。 不。如果您在数组中提供变体 ID,则可以将现有变体与新变体一起保留。一个漂亮的隐藏功能..以上是关于尝试在 Shopify 中添加变体时出错的主要内容,如果未能解决你的问题,请参考以下文章
使用 Shopify 在 Collection 页面上筛选变体
Shopify - 通过多个变体 ID 检索多个变体详细信息