SKU & # 8594; Options
Having a small issue with the Bigcommerce API while trying to access an array of ProductUU "Parameters" objects.
I can access everything else in the SKU object, just not Options
- executing print_r
in $sku->options
doesn't display the returned data, but var_dump does '(bool)false'
. Here is my code:
$filter = array('sku' => '940801DB');
$skus = Bigcommerce::getSkus($filter);
foreach ( $skus as $sku ){
echo '<pre>';
print_r( $sku->options );
echo '</pre>';
}
Any ideas on accessing this array / object?
Additional Information:
If I print_r ($ sku) I get:
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
(
)
)
)
source to share
This looks like a Bigcommerce API bug. I installed it using composer, if you look at the Bigcommerce API source code, inside 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;
}
See that it gets $ this-> fields-> options-> resource, but there is no resource in the options array. In products it looks like this:
"options": {
"url": "https://store-et7xe3pz.mybigcommerce.com/api/v2/products/32/options.json",
"resource": "/products/32/options"
},
but in this case it is:
"options": [
{
"product_option_id": 15,
"option_value_id": 18
},
{
"product_option_id": 16,
"option_value_id": 26
}
]
seems like a mistake to me.
source to share