aligent / bigcommerce-v3-api-php-client

PHP library to interact with the BigCommerce V3 API (https://developer.bigcommerce.com/api-reference#v3-rest-api)
GNU General Public License v3.0
13 stars 23 forks source link

Missing config values in ProductModifier constructor results in a fatal error #135

Closed awebber-chl closed 2 years ago

awebber-chl commented 2 years ago

For some reason, certain products in both of my test stores come back missing some config values. I have to cast these three values as bool in order to ensure that null values are interpreted as false.

    public function __construct(?stdClass $optionObject = null)
    {
        if (
            !is_null($optionObject) && !empty($optionObject->config)
            && get_class($optionObject->config) !== ProductModifierConfig::class
        ) {
            error_log('config='.json_encode($optionObject->config));
            $this->config = new ProductModifierConfig(
                (bool)$optionObject->config->product_list_adjusts_inventory,
                (bool)$optionObject->config->product_list_adjusts_pricing,
                (bool)$optionObject->config->product_list_shipping_calc
            );
        }

        if (!is_null($optionObject) && isset($optionObject->config)) {
            unset($optionObject->config);
        }

        if (!is_null($optionObject) && isset($optionObject->option_values)) {
            $this->option_values = array_map(function ($v) {
                return ProductModifierValue::buildFromResponse($v);
            }, $optionObject->option_values);
            unset($optionObject->option_values);
        }

        parent::__construct($optionObject);
    }

Here are a few examples of the configs I get back:

config={"file_types_mode":"specific","file_types_supported":["images"],"file_types_other":[],"file_max_size":524288}
config={"checkbox_label":"","checked_by_default":false}
jswift commented 2 years ago

I can see the issue, I'll get some better test data in there and fix asap.