2

With no apparent reason, product pages do not show for me anymore. Error text:

Warning: Illegal offset type in isset or empty in /path/to/project/vendor/magento/module-eav/Model/Entity/Attribute/Source/AbstractSource.php on line 74

I tried to xdebug it, here is what I found. Error happens in the following method of AbstractSource.php class:

public function getOptionText($value)
{
    $options = $this->getAllOptions();
    // Fixed for tax_class_id and custom_design
    if (sizeof($options) > 0) {
        foreach ($options as $option) {
            if (isset($option['value']) && $option['value'] == $value) {
                return isset($option['label']) ? $option['label'] : $option['value'];
            }
        }
    }
    // Error here
    if (isset($options[$value])) {
        return $options[$value];
    }
    return false;
}

The error occurs because $value is an array: $value = array("is_in_stock" => true, "qty" => 1); whereas Magento expects a scalar that can be used as array key.

All the trouble is caused by product attribute with code quantity_and_stock_status - but it is not my custom attribute, it comes out of the box, and I did not change any of its settings.

I reinstalled my entire app, still got the same result.

So it looks to me that it's a Magento internal bug - but it used to work fine, I did not update codebase in any way. What could be the reason that this bug occurs?

1 Answer 1

1

Thats because you might have the attribute "quantity_and_stock_status" marked as "Visible on Catalog Pages on Storefront" on the admin panel.

The problem is that on line 74:

if (isset($options[$value])) {

$value should not be an array, but for the stock attribute it is an array, therefore this line crashes.

You either switch it back to Non-visible on Catalog Pages, or plugin this method to validate that $value is not an array.

Will be submiting this on on github.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.