如何发送带有文本选项的产品以创建订单 bigcommerce API?

How to send products with text options to create order bigcommerce API?

我在为带有文本选项的产品创建 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 错误 400 说:发送格式错误的请求时发出。例如由于语法无效或缺少所需数据。注意:Webhook 请求在 HTTP header 中缺少 Content-Type 将 return 为 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 在创建订单时不支持 TEXT 选项。

这是他们的回答: "I understand you are attempting to create an order with a text field as an option. Unfortunately, this type of product option object is not possible. The value attribute of the object will only accept integers (the id of the option value based off the option)."