簡體   English   中英

Bigcommerce產品SKU - >選項

[英]Bigcommerce Product SKU's -> Options

在嘗試訪問Product SKU的“選項”array_object時遇到Bigcommerce API的問題。

我可以訪問SKU對象中的所有其他內容,而不是Options - 在$sku->options上執行print_r不顯示任何返回的數據,var_dump顯示'(bool)false' 這是我的代碼:

$filter = array('sku' => '940801DB');
$skus = Bigcommerce::getSkus($filter);

foreach ( $skus as $sku ){
    echo '<pre>';
    print_r( $sku->options );
    echo '</pre>';
}

任何想法如何訪問此數組/對象?

更多信息:

如果我print_r($ sku)我得到:

Array
(
    [0] => Bigcommerce\Api\Resources\Sku Object
    (
        [ignoreOnCreate:protected] => Array
            (
                [0] => product_id
            )

        [ignoreOnUpdate:protected] => Array
            (
                [0] => id
                [1] => product_id
            )

        [fields:protected] => stdClass Object
            (
                [id] => 1
                [product_id] => 225
                [sku] => 940801DB
                [cost_price] => 0.0000
                [upc] => 
                [inventory_level] => 0
                [inventory_warning_level] => 0
                [bin_picking_number] => 
                [options] => Array
                    (
                        [0] => stdClass Object
                            (
                                [product_option_id] => 1
                                [option_value_id] => 834
                            )

                        [1] => stdClass Object
                            (
                                [product_option_id] => 2
                                [option_value_id] => 829
                            )

                        [2] => stdClass Object
                            (
                                [product_option_id] => 3
                                [option_value_id] => 827
                            )

                    )

            )

        [id:protected] => 1
        [ignoreIfZero:protected] => Array
            (
            )

        [fieldMap:protected] => Array
            (
            )

    )
)

不確定為什么你無法訪問該變量。 這看起來更像是PHP的問題而不是Bigcommerce。

但是,解決方法是自己獲取選項數據。 只需向以下端點發送GET請求:

/products/{{product_id}}/options.json

這似乎是Bigcommerce API的一個錯誤。 我使用composer安裝它,如果你看一下Bigcommerce API的源代碼,在vendor / bigcommerce / api / src / Bigcommerce / Api / Resources / Sku.php中:

public function options()
{
    $options = Client::getCollection($this->fields->options->resource, 'SkuOption');

    foreach ($options as $option) {
        $option->product_id = $this->product_id;
    }

    return $options;
}

看到它獲得$ this-> fields-> options-> resource,但options數組中沒有資源。 在產品中它是這樣的:

"options": {
    "url": "https://store-et7xe3pz.mybigcommerce.com/api/v2/products/32/options.json",
    "resource": "/products/32/options"
  },

但在sku這是這樣的:

"options": [
      {
        "product_option_id": 15,
        "option_value_id": 18
      },
      {
        "product_option_id": 16,
        "option_value_id": 26
      }
    ]

對我來說似乎是個錯誤。

選項位於字段下方

嘗試

print_r($sku->fields->options);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM