【问题标题】:Bigcommerce API PHP creating order with optionsBigcommerce API PHP 创建带有选项的订单
【发布时间】:2017-09-13 00:02:23
【问题描述】:

以下代码成功创建订单。 id 为“3889”的项目具有三种尺寸:“7”、“8”、“9”。 但是添加到订单中的这个项目没有通过的尺寸“7”。 结果大小未指定。 Bigcommerce 没有错误。

问题:如何将产品的尺寸传递给订单?

<?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,
            )
          )
    );

【问题讨论】:

  • 您确定您的产品选项具有正确的id 值吗?
  • @ProEvilz 我就是这样做的:我使用管理面板手动将 ID 为“3889”的项目添加到订单中。然后我从这个订单中请求产品选项信息。我得到了所有 id 的数组: [id] => 7178 [option_id] => 1240 [order_product_id] => 9939 [product_option_id] => 1267 [display_name] => Size [display_value] => Silver [value] => 7 .我尝试了其他ID。出现 BG 错误。

标签: php bigcommerce


【解决方案1】:

选项的 ID 值错误! 而是给出了 7 号的“银”字。 因为 [display_value] => 银。这是我从订单中获得的信息。

以下代码获取产品选项(不是选项本身)的 id 和选项(不是产品)的 value

$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

【讨论】:

    猜你喜欢
    • 2015-05-05
    • 1970-01-01
    • 1970-01-01
    • 2015-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-25
    • 2017-11-30
    相关资源
    最近更新 更多