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

倾然丶 夕夏残阳落幕 提交于 2019-12-23 20:41:46

问题


I'm having trouble creating an order to bigcommerce for products with text options, the api gives these error:

[
  {
    "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"
          }
        }
      ]
    }
  }
]

And what I'm sending for the products object is:

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

The code used works for product with drop down options. I don't know what else to send and I can't find an answer in their documentation.


回答1:


We have received an answer from bigcommerce saying that the API does not support TEXT options when creating orders.

This is their answer: "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)."




回答2:


Have to checked if option exist?.

bigcommerce error 400 say: Issued when a malformed request was sent. Such as due to invalid syntax or missing required data. NOTE: Webhook requests missing Content-Type in the HTTP header will return a 400.

In the documentation say 'product_options' and you have typed 'product_option'

bigcommerce create-an-order

i think it should be so:

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

For example: if you product have two option with several values, then you have to set the two options values combination, and they have the stock level > 0:

product with id 49 and options:

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
        )

)

option1:

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
        )
)

option2:

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
        )
)

simple order example:

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
                      )
                  )
                )
              )
        ));

response:

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)


来源:https://stackoverflow.com/questions/28847203/how-to-send-products-with-text-options-to-create-order-bigcommerce-api

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