Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
awebber-chl opened this issue Jun 3, 2022 · 1 comment · Fixed by #137 or #138
Closed

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

awebber-chl opened this issue Jun 3, 2022 · 1 comment · Fixed by #137 or #138
Assignees

Comments

@awebber-chl
Copy link

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 jswift self-assigned this Jun 6, 2022
@jswift
Copy link
Collaborator

jswift commented Jun 6, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants