0

After filling in all field in an attribute (id160) i get an error on the frontend when loading this page.

(Exception): Notice: Array to string conversion in /vendor/magento/module-catalog/Block/Product/View/Attributes.php on line 84

It has to do with this piece of code:

public function getAdditionalData(array $excludeAttr = [])
    {
        $data = [];
        $product = $this->getProduct();
        $attributes = $product->getAttributes();
        foreach ($attributes as $attribute) {
            if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
                $value = $attribute->getFrontend()->getValue($product);

                if (!$product->hasData($attribute->getAttributeCode())) {
                    $value = __('N/A');
                } elseif ((string)$value == '') {
                    $value = __('No');
                } elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
                    $value = $this->priceCurrency->convertAndFormat($value);
                }

                if (($value instanceof Phrase || is_string($value)) && strlen($value)) {
                    $data[$attribute->getAttributeCode()] = [
                        'label' => __($attribute->getStoreLabel()),
                        'value' => $value,
                        'code' => $attribute->getAttributeCode(),
                    ];
                }
            }
        }
        return $data;
    }

and line 84 is } elseif ((string)$value == '') {

When i comment this line and the next line the problem is fixed for now.

But what does this line do? And is there a other way to solve it?

I have magento 2.1.7ce

1 Answer 1

1

If you want to convert $value to string, you just need a little PHP twist on line 84:

} elseif (implode("", $value) == '') {
4
  • Hi, I am not a programmer. Could you tel me in normal language why this is needed?
    – Ronny
    Jul 10, 2017 at 5:38
  • It can convert an array to string. But wait, what is the data type of id160?
    – PY Yick
    Jul 10, 2017 at 5:45
  • This attribute has a lot (200+) sizes. Numbers, letters, braces () and a combination of these. Like 122-128 (7-8y)
    – Ronny
    Jul 10, 2017 at 5:56
  • And this error only shows with products who use this attribute. When an other product uses an other size attribute nothing is wrong)
    – Ronny
    Jul 10, 2017 at 5:57

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.