Cart API V3: Can't create a Cart for product t

2019-03-04 00:53发布

问题:

When I create a cart with products without options, everything works fine, but if any of the products has product option, it doesn't work Here I got the product options, it has one option with id 21

When I use this option id in creating the API, it doesn't work

回答1:

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.



标签: bigcommerce