Bigcommerce在PHP中创建订单错误api

时间:2018-02-08 13:59:25

标签: java php jquery api bigcommerce

我想在我的bigcommerce商店添加订单,如果您想要我想使用以下代码:

$billing_array = array(array("first_name"=> "MG",
                            "last_name"=> "Shah",
                            "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_array = array(
                           array( "first_name"=> "MG",
                            "last_name"=> "Shah",
                            "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"
                        )
                         ,);
    $products_array= array();
                for($i=0;$i<sizeof($products);$i++)
                {
                    $products_array[] = array(array('product_id' => $products[$i]['products_id'],
                                        'quantity'  => $products[$i]['products_qty']),);
                }
    $createFields= array(
                        "customer_id" => 0,
                        "status_id"=> 10,
                        "billing_address"=> $billing_array,
                        "shipping_addresses"=>$shipping_array,
                        "products"=>$products_array,
                        "external_source"=> "POS"
                    );
    $data_array_jason = json_encode($createFields);
    $products_passed = Bigcommerce::createOrder($data_array_jason);

我收到错误bool(false),我在使用POST方法请求时看到此错误,您可以对此问题有任何答案,请指导我。

1 个答案:

答案 0 :(得分:3)

请用以下数组替换你的数组

$billing_array = array(
    "first_name"=> "MG",
    "last_name"=> "Shah",
    "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_array = array(
    array( "first_name"=> "MG",
    "last_name"=> "Shah",
    "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"
    )
    ,);

$products_array= array();

for($i=0;$i<sizeof($products);$i++){

$products_array[] = array( 'product_id' => $products[$i]['products_id'],
                            'quantity'  => $products[$i]['products_qty']
);

}

$createFields= array(
                        "customer_id" => 0,
                        "status_id"=> 10,
                        "billing_address"=> $billing_array,
                        "shipping_addresses"=>$shipping_array,
                        "products"=>$products_array,
                        "external_source"=> "POS"
                    );
    $data_array_jason = json_encode($createFields);
    $products_passed = Bigcommerce::createOrder($data_array_jason);

然后立即检查它是否正常工作。