Java-Bigcommerce在PHP中创建订单错误api

我想在我的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方法请求时看到此错误,您可以对此问题有任何答案吗,请对此进行指导.

最佳答案
请用下面的数组替换你的数组

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

然后检查它是否可以正常工作.

转载注明原文:Java-Bigcommerce在PHP中创建订单错误api - 代码日志