【问题标题】:Problems using BigCommerce API to generate an order on the store使用 BigCommerce API 在商店中生成订单的问题
【发布时间】:2017-07-29 07:08:15
【问题描述】:

我正在尝试使用 BigCommerce API 在我的 BigCommerce 商店中生成订单。我正在使用下面的代码来完成此操作。我能够很好地 ping BigCommerce,并且在 php 代码中没有错误。问题是它永远不会在我的 Bigcommerce 商店中生成订单。

require('vendor/autoload.php');

use Bigcommerce\Api\Client as Bigcommerce;

Bigcommerce::configure(array(
'store_url' => 'https://my-store.bigcommerce.com/',
'username'  => 'admin',
'api_key'   => 'XXXXXX'
));

$ping = Bigcommerce::getTime();
if ($ping){ echo $ping->format('H:i:s');}

$createFields = array(
"customer_id" => 0,
"date_created" => $today,
"status_id" => 1,
"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"),
"shipping_addresses" => 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"),
"external_source" => "POS",
"products" => array(
        "product_id" => "90",
        "quantity" => "1"));

print_r(Bigcommerce::createOrder($createFields));

我错过了什么?

我是否错误地使用了 BigCommerce API?

任何帮助找出我的代码为什么没有在我的 Bigcommerce 商店中生成订单的任何帮助都很棒!

【问题讨论】:

  • 你得到什么回应?
  • 我没有看到任何错误。只需从 ping 读取时间。有没有办法显示 Bigcommerce 错误?
  • 不是 php 错误。 Bigcommerce Orders API 的响应是什么?
  • 我收到“'产品'字段无效”错误消息。

标签: php api bigcommerce


【解决方案1】:

products 属性需要是一个嵌套数组,其中父 products 数组中的每个单独产品都必须作为自己的数组存在:

"products" => array(
  0 => array(
    "product_id" => int,
    "quantity"   => int
  ),
  1 => array(
    "product_id" => int,
    "quantity"   => int,
  )
),

【讨论】:

    【解决方案2】:

    尝试从 products 数组中的“数量”参数中删除引号。它期待一个 int 而不是一个字符串。

    【讨论】:

    • 感谢您的建议。不幸的是,从“数量”参数中删除引号仍然会导致相同的错误:13:35:24array(1) { [0]=> object(stdClass)#5 (2) { ["status"]=> int(400) ["message"]=> string(32) "The field 'products' is invalid." } }
    • 产品有产品选项吗?如果是这样,您需要传入选项的 ID 以及选定的值。请参阅this documentation 了解更多信息。
    【解决方案3】:
    products'=>array(
    'product'=>array(
    'product_id'=>90
    'quantity'=>1
    
    • product_id 和数量是 int 类型,不应有引号“”
    • 您的 Products 数组中需要一个产品数组

    【讨论】:

      【解决方案4】:

      这样设置你的数组:

      $createFields=Array(
                         "customer_id" => 0,
                         "status_id"=> 10,
                         "billing_address"=> [
                              "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"=> "a@example.com"
                          ],
                          "shipping_addresses"=>[ 
                              [
      
                                  "first_name"=> "Trisha",
                                  "last_name"=> "McLaughlin",
                                  "company"=> "Acme Pty Ltd",
                                  "street_1"=> "566 Sussex St",
                                  "street_2"=> "",
                                  "city"=> "Austin",
                                  "state"=> "Texas",
                                  "zip"=> "78757",
                                  "country"=> "United States",
                                  "country_iso2"=> "US",
                                  "phone"=> "",
                                  "email"=> "a@example.com"
                              ]],
                          "products"=>[
                              [ 
                                  "product_id"=> 90,
                                  "quantity"=>1,
                                    // "name"=> "data",
                              ],
                              ],
      
                          "external_source"=> "POS"
                      );
      

      【讨论】:

        猜你喜欢
        • 2013-07-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多