【问题标题】:How to send products with text options to create order bigcommerce API?如何发送带有文本选项的产品以创建订单 bigcommerce API?
【发布时间】:2015-05-05 00:19:03
【问题描述】:

我在为带有文本选项的产品创建 bigcommerce 订单时遇到问题,api 给出了以下错误:

[
  {
    "status": 400,
    "message": "The options of one or more products are invalid.",
    "details": {
      "errors": [
        {
          "type": "InvalidProductOptionValue",
          "product": {
            "id": 3190,
            "name": "Esprit Knit Tech Gloves.",
            "product_option": {
              "id": 445,
              "option_id": 47,
              "display_name": "Name To Print",
              "value": "moni test",
              "url": "https:\/\/api.bigcommerce.com\/stores\/xxxxxx\/v2\/products\/3190\/options\/445",
              "resource": "\/products\/3190\/options\/445"
            },
            "url": "https:\/\/api.bigcommerce.com\/stores\/xxxxxx\/v2\/products\/3190",
            "resource": "\/products\/3190"
          }
        }
      ]
    }
  }
]

我要发送的产品对象是:

[
  {
    "product_id":"3190",
    "quantity":1,
    "product_options":[
       {
         "id":"445",
         "value":"TEXT option"
       }
     ]
   }
 ]

使用的代码适用于具有下拉选项的产品。我不知道还要发送什么,我在他们的文档中找不到答案。

【问题讨论】:

    标签: bigcommerce


    【解决方案1】:

    必须检查选项是否存在?

    bigcommerce 错误 400 说:发送格式错误的请求时发出。例如由于语法无效或缺少所需数据。注意:在 HTTP 标头中缺少 Content-Type 的 Webhook 请求将返回 400。

    在文档中说“product_options”并且您输入了“product_option”

    bigcommerce create-an-order

    我认为应该是这样的:

    "product": {
                "id": 3190,
                "name": "Esprit Knit Tech Gloves.",
                "product_options": [{
                  "id": 445,
                  "option_id": 47,
                  "display_name": "Name To Print",
                  "value": "moni test",
                  "url": "https:\/\/api.bigcommerce.com\/stores\/xxxxxx\/v2\/products\/3190\/options\/445",
                  "resource": "\/products\/3190\/options\/445"
                }],
                "url": "https:\/\/api.bigcommerce.com\/stores\/xxxxxx\/v2\/products\/3190",
                "resource": "\/products\/3190"
              }
    

    例如: 如果您的产品有两个具有多个值的选项,那么您必须设置两个选项值的组合,并且它们的库存水平 > 0:

    id 为 49 的产品和选项:

    Array
    (
        [0] => stdClass Object
            (
                [id] => 105
                [option_id] => 18
                [display_name] => Size
                [sort_order] => 0
                [is_required] => 1
            )
    
        [1] => stdClass Object
            (
                [id] => 106
                [option_id] => 3
                [display_name] => Color
                [sort_order] => 1
                [is_required] => 1
            )
    
    )
    

    选项1:

    Array
    (
        [0] => stdClass Object
            (
                [id] => 68
                [option_id] => 18
                [label] => XS
                [sort_order] => 0
                [value] => XS
            )
        [1] => stdClass Object
            (
                [id] => 69
                [option_id] => 18
                [label] => S
                [sort_order] => 1
                [value] => S
            )
        [2] => stdClass Object
            (
                [id] => 70
                [option_id] => 18
                [label] => M
                [sort_order] => 2
                [value] => M
            )
        [3] => stdClass Object
            (
                [id] => 71
                [option_id] => 18
                [label] => L
                [sort_order] => 3
                [value] => L
            )
        [4] => stdClass Object
            (
                [id] => 72
                [option_id] => 18
                [label] => XL
                [sort_order] => 4
                [value] => XL
            )
    )
    

    选项2:

    Array
    (
        [0] => stdClass Object
            (
                [id] => 7
                [option_id] => 3
                [label] => Silver
                [sort_order] => 1
                [value] => #cccccc
            )
        [1] => stdClass Object
            (
                [id] => 8
                [option_id] => 3
                [label] => Black
                [sort_order] => 2
                [value] => #000000
            )
        [2] => stdClass Object
            (
                [id] => 9
                [option_id] => 3
                [label] => Purple
                [sort_order] => 3
                [value] => #700170
            )
        [3] => stdClass Object
            (
                [id] => 10
                [option_id] => 3
                [label] => Blue
                [sort_order] => 4
                [value] => #123c91
            )
        [4] => stdClass Object
            (
                [id] => 11
                [option_id] => 3
                [label] => Green
                [sort_order] => 5
                [value] => #0f961e
            )
        [5] => stdClass Object
            (
                [id] => 12
                [option_id] => 3
                [label] => Yellow
                [sort_order] => 6
                [value] => #f0f005
            )
        [6] => stdClass Object
            (
                [id] => 13
                [option_id] => 3
                [label] => Orange
                [sort_order] => 7
                [value] => #e35e20
            )
        [7] => stdClass Object
            (
                [id] => 14
                [option_id] => 3
                [label] => Pink
                [sort_order] => 9
                [value] => #e841c1
            )
        [8] => stdClass Object
            (
                [id] => 39
                [option_id] => 3
                [label] => Red
                [sort_order] => 8
                [value] => #e60c0c
            )
    )
    

    简单的订单示例:

    array(
              "customer_id"=> 0,
              "status_id"=> 1,
              "base_shipping_cost"=> 0,
              "base_handling_cost"=> 0,
              "refunded_amount"=> 0,
              "order_is_digital"=> false,
              "staff_notes"=> "",
              "customer_message"=> "",
              "discount_amount"=> 10,
                "billing_address"=> array(
                    "first_name"=> "Trisha",
                    "last_name"=> "McLaughlin",
                    "company"=> "",
                    "street_1"=> "12345 W Anderson Ln",
                    "street_2"=> "",
                    "city"=> "Austin",
                    "state"=> "Texas",
                    "zip"=> "78757",
                    "country"=> "United States",
                    "country_iso2"=> "US",
                    "phone"=> "",
                    "email"=> "elsie@example.com"
                  ),
                  "products"=> array(
                    array(
                      "product_id" => 49,
                      "quantity"   => 1,
                      "product_options"=> array(
                          array(
                              "id"   => 105,//product option id
                              "value"=> 68  //option value id
                          ),
                          array(
                              "id"   => 106,//product option id
                              "value"=> 7   //option value id
                          )
                      )
                    )
                  )
            ));
    

    回复:

    object(stdClass)[10]
      public 'id' => int 24
      public 'customer_id' => int 0
      public 'date_created' => string 'Wed, 04 Mar 2015 16:55:54 +0000' (length=31)
      public 'date_modified' => string 'Wed, 04 Mar 2015 16:55:54 +0000' (length=31)
      public 'date_shipped' => string '' (length=0)
      public 'status_id' => int 1
      public 'status' => string 'Pending' (length=7)
      public 'subtotal_ex_tax' => string '90.0000' (length=7)
      public 'subtotal_inc_tax' => string '90.0000' (length=7)
      public 'subtotal_tax' => string '0.0000' (length=6)
      public 'base_shipping_cost' => string '0.0000' (length=6)
      public 'shipping_cost_ex_tax' => string '0.0000' (length=6)
      public 'shipping_cost_inc_tax' => string '0.0000' (length=6)
      public 'shipping_cost_tax' => string '0.0000' (length=6)
      public 'shipping_cost_tax_class_id' => int 0
      public 'base_handling_cost' => string '0.0000' (length=6)
      public 'handling_cost_ex_tax' => string '0.0000' (length=6)
      public 'handling_cost_inc_tax' => string '0.0000' (length=6)
      public 'handling_cost_tax' => string '0.0000' (length=6)
      public 'handling_cost_tax_class_id' => int 0
      public 'base_wrapping_cost' => string '0.0000' (length=6)
      public 'wrapping_cost_ex_tax' => string '0.0000' (length=6)
      public 'wrapping_cost_inc_tax' => string '0.0000' (length=6)
      public 'wrapping_cost_tax' => string '0.0000' (length=6)
      public 'wrapping_cost_tax_class_id' => int 0
      public 'total_ex_tax' => string '80.0000' (length=7)
      public 'total_inc_tax' => string '80.0000' (length=7)
      public 'total_tax' => string '0.0000' (length=6)
      public 'items_total' => int 1
      public 'items_shipped' => int 0
      public 'payment_method' => string 'Manual' (length=6)
      public 'payment_provider_id' => null
      public 'payment_status' => string '' (length=0)
      public 'refunded_amount' => string '0.0000' (length=6)
      public 'order_is_digital' => boolean false
      public 'store_credit_amount' => string '0.0000' (length=6)
      public 'gift_certificate_amount' => string '0.0000' (length=6)
      public 'ip_address' => string '' (length=0)
      public 'geoip_country' => string '' (length=0)
      public 'geoip_country_iso2' => string '' (length=0)
      public 'currency_id' => int 1
      public 'currency_code' => string 'USD' (length=3)
      public 'currency_exchange_rate' => string '1.0000000000' (length=12)
      public 'default_currency_id' => int 1
      public 'default_currency_code' => string 'USD' (length=3)
      public 'staff_notes' => string '' (length=0)
      public 'customer_message' => string '' (length=0)
      public 'discount_amount' => string '10.0000' (length=7)
      public 'coupon_discount' => string '0.0000' (length=6)
      public 'shipping_address_count' => int 1
      public 'is_deleted' => boolean false
      public 'ebay_order_id' => string '0' (length=1)
      public 'billing_address' => 
        object(stdClass)[11]
          public 'first_name' => string 'Trisha' (length=6)
          public 'last_name' => string 'McLaughlin' (length=10)
          public 'company' => string '' (length=0)
          public 'street_1' => string '12345 W Anderson Ln' (length=19)
          public 'street_2' => string '' (length=0)
          public 'city' => string 'Austin' (length=6)
          public 'state' => string 'Texas' (length=5)
          public 'zip' => string '78757' (length=5)
          public 'country' => string 'United States' (length=13)
          public 'country_iso2' => string 'US' (length=2)
          public 'phone' => string '' (length=0)
          public 'email' => string 'elsie@example.com' (length=17)
      public 'order_source' => string 'external' (length=8)
      public 'external_source' => null
      public 'products' => 
        object(stdClass)[12]
          public 'url' => string 'https://store-qq6db7r.mybigcommerce.com/api/v2/orders/24/products.json' (length=70)
          public 'resource' => string '/orders/24/products' (length=19)
      public 'shipping_addresses' => 
        object(stdClass)[13]
          public 'url' => string 'https://store-qq6db7r.mybigcommerce.com/api/v2/orders/24/shippingaddresses.json' (length=79)
          public 'resource' => string '/orders/24/shippingaddresses' (length=28)
      public 'coupons' => 
        object(stdClass)[14]
          public 'url' => string 'https://store-qq6db7r.mybigcommerce.com/api/v2/orders/24/coupons.json' (length=69)
          public 'resource' => string '/orders/24/coupons' (length=18)
    

    【讨论】:

    • 感谢您的回答,但您编辑的是来自 bigcommerce API 的答案,而不是我发送给他们的内容...我发送的内容低于该代码,它是一个名为“ product_options”,正如文档所述...您可以在我的问题中找到它,唯一的问题是“值”包含文本而不是选项值 id,就像在他们的示例中一样,因为我的选项不是 SELECT 类型,属于 TEXT 类型。
    • 你必须设置de'option id'和'option value id'
    • 是的,你说的是正确的,我的代码适用于这种情况,但如果选项是 TEXT 类型?意味着它没有一组值,但它是买家在将产品添加到购物车时必须输入的字符串......就像写在衬衫上的个性化文本......那种类型的选项没有一组值,但一个值..买方写的文字...这就是我正在谈论的情况,在这个问题中..
    【解决方案2】:

    我们收到 bigcommerce 的答复,称 API 在创建订单时不支持 TEXT 选项。

    这是他们的答案: “我了解您正在尝试使用文本字段作为选项创建订单。不幸的是,这种类型的产品选项对象是不可能的。对象的 value 属性将只接受整数(选项值的 id 基于选项)。”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-19
      • 1970-01-01
      • 1970-01-01
      • 2014-02-25
      • 1970-01-01
      • 2015-09-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多