Cart API V3: Can't create a Cart for product that has options

心不动则不痛 提交于 2019-12-02 09:41:28

If you are adding a product to the cart that has a single modifier associated with it (like a text field) try the POST to the cart API without including the "variant_id" field:

{
  "line_items": [
    {
      "quantity": 1,
      "product_id": 1001,
      "option_selections": [
        {
          "option_id": 123,
          "option_value": "Hello!"
        }
      ]
    }
  ]
}

If your product has one option (like a radio button) associated with it, try this request, using just the variant ID to identify the option:

{
  "line_items": [
    {
      "quantity": 1,
      "product_id": 1001,
      "variant_id": 2331
    }
]
}

If your product has both an option (radio button) and a modifier (text field), this sample request should work. The first option selection corresponds to the radio button option and the second option selection corresponds to the text field modifier. No variant id is included:

{
  "line_items": [
    {
      "quantity": 1,
      "product_id": 101,
      "option_selections": [
        {
          "option_id": 231,
          "option_value": 456
        },

        {
          "option_id": 123,
          "option_value": "Hello!"
        }
      ]
    }
  ]

For context on the v3 terminology, both options and modifiers are terms for lists of choices attached to products, but options are choices that are used to build out variants (SKUs) and modifiers are choices that are not tied to variants at all. This is why a text field would be a modifier, and a radio button would be an option.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!