使用BigCommerce API在商店上生成订单时出现问题

时间:2015-09-18 16:10:40

标签: php api bigcommerce

我正在尝试使用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商店生成订单的帮助都会很棒!

4 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

products'=>array(
'product'=>array(
'product_id'=>90
'quantity'=>1
  • product_id和数量是int类型,不应该有引号""
  • 您需要在Products数组中使用产品数组

答案 3 :(得分:0)

像这样设置你的数组:

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