购物车API V3:无法为具有选项的产品创建购物车 [英] Cart API V3: Can't create a Cart for product that has options

查看:80
本文介绍了购物车API V3:无法为具有选项的产品创建购物车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建带有不带选项的产品的购物车时,一切正常,但是,如果其中任何一个产品都带有产品选项,那么它将不起作用 在这里,我得到了产品选项,它有一个ID为21的选项.

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

当我在创建API时使用此选项ID时,它不起作用

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

推荐答案

如果您要向购物车中添加具有单个修饰符的产品(例如文本字段),请尝试对购物车API进行POST,而无需添加"variant_id"字段:

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!"
        }
      ]
    }
  ]
}

如果您的产品具有与其相关的一个选项(如单选按钮),请尝试使用此请求,仅使用变体ID来标识该选项:

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
    }
]
}

如果您的产品同时具有一个选项(单选按钮)和一个修饰符(文本字段),则此示例请求应该有效.第一个选项选择对应于单选按钮选项,第二个选项选择对应于文本字段修饰符.不包含变体ID:

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!"
        }
      ]
    }
  ]

对于v3术语的上下文,选项和修饰词都是产品附加选项列表的术语,但是选项是用于构建变体(SKU)的选择,修饰词是根本不与变体相关联的选择.这就是为什么文本字段是修饰符,单选按钮是选项的原因.

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.

这篇关于购物车API V3:无法为具有选项的产品创建购物车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆