gpt4 book ai didi

bigcommerce 创建订单 PHP 示例

转载 作者:行者123 更新时间:2023-12-04 03:07:02 25 4
gpt4 key购买 nike

我正在使用 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;


?>

我在任何地方都看不到例子。

沃比先生。

最佳答案

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;
}

关于bigcommerce 创建订单 PHP 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23096607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com