2017-09-13 137 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