2017-09-13 87 views
0

以下代碼成功創建訂單。 ID爲「3889」的商品有三種尺寸:「7」,「8」,「9」。 但是這個項目添加到一個訂單沒有傳遞的大小「7」。 只在未指定結果大小。 Bigcommerce沒有錯誤。Bigcommerce API PHP使用選項創建訂單

pic how it looks in admin panel

問題:如何通過規模爲產品的順序?

<?php 
require 'C:\wamp64\www\bigcommerceDemo\vendor\autoload.php'; 
require 'C:\wamp64\www\bigcommerceDemo\bg_api_connection\scripting.php'; 

use Bigcommerce\Api\Client as Bigcommerce; 
Bigcommerce::verifyPeer(false); 

$first_name = "example"; 
$last_name = "example"; 
$company = ""; 
$street_1 = "example"; 
$street_2 = ""; 
$city = "example"; 
$state = "example"; 
$zip = "example"; 
$country = "United States"; 
$country_iso2 = ""; 
$phone = "example"; 
$email = "example"; 

$object = array(
    "customer_id" => "12610", 
    "status_id" => "7", 
    "date_created" => "Mon, 11 Sep 2017 19:26:23 +0000", 
     "billing_address" => array(
     "first_name" => $first_name, 
     "last_name" => $last_name, 
     "company" => $company, 
     "street_1" => $street_1, 
     "street_2" => $street_2, 
     "city" => $city, 
     "state" => $state, 
     "zip" => $zip, 
     "country" => $country, 
     "phone" => $phone, 
     "email" => $email), 
     "products" => array(
      0 => array(
       "product_id" => 3889, 
       "quantity" => 1, 
       "product_options" => array(
       0 => array(
        "id" => 1267, 
        "value" => 7 
       ) 
      ) 
      ), 
      1 => array(
       "product_id" => 15805, 
       "quantity" => 1, 
      ) 
     ) 
    ); 
+0

你確定你有正確的'ID產品選擇的價值? – ProEvilz

+0

@ProEvilz它是這樣做的:我使用管理面板手動添加了ID爲「3889」的項目。然後我從這個訂單請求產品選項信息。而我得到了陣列的所有ID:[ID] => 7178 [option_id] => 1240 [order_product_id] => 9939 [product_option_id] => 1267 [DISPLAY_NAME] =>大小 [DISPLAY_VALUE] =>銀 [價值] => 7. 我試過其他的ID。有BG錯誤。 –

回答

0

ID該選項的值錯了! 它代之以7號字「銀」。 因爲[display_value] =>銀色。這個信息我從訂單中得到。

下面的代碼,把產品選項(不是選項本身)和選項(而不是產品)的ID

$product_options_array = Bigcommerce::getProductOptions($product_id); 
$product_option_id_array = array_map(create_function('$id', 'return $id->id;'), $product_options_array); 
$product_option_id = implode(" ", $product_option_id_array);//in "product_options" => array it goes to "id" => 1267 

$product_one_option_values_array = Bigcommerce::getOption($product_option_id); 
$values_array = $product_one_option_values_array->values; 
$value_label_array = array_map(create_function('$value', 'return $value->value;'), $values_array); 
$value_id_array = array_map(create_function('$id', 'return $id->id;'), $values_array);//in "product_options" => array it goes to "value" => 4975