bigcommerce创建订单PHP示例

时间:2014-04-15 23:57:46

标签: bigcommerce

我正在使用PHP从api中提取信息。

我现在需要创建一个订单。从文件中可以得到一个例子:

{
"customer_id": 0,
"status_id": 11,
"date_created": "Thu, 04 Oct 2012 03:24:40 +0000",
"subtotal_ex_tax": 1705,
"subtotal_inc_tax": 1915,
"base_shipping_cost": 0,
"shipping_cost_ex_tax": 0,
"shipping_cost_inc_tax": 0,
"base_handling_cost": 0,
"handling_cost_ex_tax": 0,
"handling_cost_inc_tax": 0,
"base_wrapping_cost": 0,
"wrapping_cost_ex_tax": 0,
"wrapping_cost_inc_tax": 0,
"total_ex_tax": 1705,
"total_inc_tax": 1915,
"refunded_amount": 0,
"order_is_digital": false,
"staff_notes": "",
"customer_message": "",
"discount_amount": 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": "elsie@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": "elsie@example.com"
}
],
"products": [
{
  "product_id": 32,
  "quantity": 2
},
{
  "product_id": 33,
  "quantity": 2,
  "product_options": [
    {
      "id": 87,
      "value": 10
    }
  ]
}
],
"external_source": "POS"
}

我用来从类别中获取产品的代码是:

<?php

$username = 'xxxx'; 
$password = 'xxxxx';
$selectedCategory = '245';//
$selectedCategory = $_GET["selectedCategory"];
//echo 'selectedCategory = '.$selectedCategory;
$url = 'https://store-xxxx.mybigcommerce.com';
$product_url = $url.'/api/v2/products.json?category='.$selectedCategory.'&is_visible=true'; 
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $product_url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_ENCODING, "");
$curlProductData = curl_exec($curl);
curl_close($curl);
echo $curlProductData;


?>

我没有在任何地方看到一个例子。

MrWarby。

1 个答案:

答案 0 :(得分:0)

getorder的功能:

 public function actionCreateorder()
            {
                $data=Array(
                           "status_id"=> 10,
                           "date_created"=> "Thu, 04 Oct 2012 03:24:40 +0000",
                           "subtotal_ex_tax"=> 1705,
                           "subtotal_inc_tax"=> 1915,
                          // "base_shipping_cost"=> 0,
                           "shipping_cost_ex_tax"=> 2,
                           "shipping_cost_inc_tax"=> 5,
                          // "base_handling_cost"=> 0,
                          // "handling_cost_ex_tax"=> 0,
                          // "handling_cost_inc_tax"=> 0,
                          // "base_wrapping_cost"=> 0,
                          // "wrapping_cost_ex_tax"=> 0,
                          // "wrapping_cost_inc_tax"=> 0,
                           // "total_ex_tax"=> 1705,
                           // "total_inc_tax"=> 1915,
                          // "refunded_amount"=> 0,
                          // "order_is_digital"=> false,
                           "staff_notes"=> "abc.com",
                            // "customer_message"=> "",
                            // "discount_amount"=> 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"=> 86,
                                    "quantity"=>1,
                                ],
                                ],

                            "external_source"=> "POS"
                        );
            }

动作:

$resource='orders/';
public function getorder($resource,$config=false) {
            $api_url = 'https://api.bigcommerce.com/stores/'.hash value.'/v2/'.$resource;
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Auth-Client:'clientid,'X-Auth-Token:'tokenvalue,'Accept: application/json', 'Content-Length: 0'));
            curl_setopt( $ch, CURLOPT_URL, $api_url );
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
            curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
            $response = curl_exec( $ch );
            $result = json_decode($response,true);
            return $result;
        }