2

I am getting following error on product detail page for multiselect attributes.

Warning: strpos() expects parameter 1 to be string, array given in /home/xxxxx/public_html/vendor/magento/module-eav/Model/Entity/Attribute/Source/Table.php on line 160

Exception #0 (Exception): Warning: strpos() expects parameter 1 to be string, array given in /home/xxxxx/public_html/vendor/magento/module-eav/Model/Entity/Attribute/Source/Table.php on line 160

0 [internal function]: Magento\Framework\App\ErrorHandler->handler(2, 'strpos() expect...', '/home/xxxx...', 160, Array)

1 /home/xxxxx/public_html/vendor/magento/module-eav/Model/Entity/Attribute/Source/Table.php(160): strpos(Array, ',')

2 /home/xxxxx/public_html/vendor/magento/module-eav/Model/Entity/Attribute/Frontend/AbstractFrontend.php(331): Magento\Eav\Model\Entity\Attribute\Source\Table->getOptionText(Array)

3 /home/xxxxx/public_html/vendor/magento/module-eav/Model/Entity/Attribute/Frontend/AbstractFrontend.php(176): Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend->getOption(Array)

4 /home/xxxxx/public_html/vendor/magento/module-catalog/Block/Product/View/Attributes.php(84): Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend->getValue(Object(Magento\Catalog\Model\Product\Interceptor))

5 /home/xxxxx/public_html/app/design/frontend/xxxx/xxxx/Magento_Catalog/templates/product/view/attributes.phtml(19): Magento\Catalog\Block\Product\View\Attributes->getAdditionalData();

I am using magento 2.2.3 please help

2
  • add multiselect product attribute create code Commented Jun 18, 2018 at 11:22
  • @Pradeep Sanku Did you find a solution? I am having this issue also Commented Apr 4, 2019 at 16:12

2 Answers 2

1

I ran into this issue in Magento 2.3.0 and was able to get it fixed by changing the Table.php file.

Before I explain what I did, let me preface it with you should never change core Magento file and should extend any changes into a custom module. But for me this is a small change that is needed due to an issue with the core code so it makes sense for to make the change directly, still not recommended.

Okay, so I needed to make two changes, one mentioned in another answer which is to change line 152 from

if(strpos($value, ',') !== false){`

to

if (is_array($value)) {

and then comment out line 154

//value = explode(',',$value);

as the explode function cannot accept an array as it's second parameter.

After making these changes I was able to browse again. I'm not entirely sure of any possible issues that this may bring up, but it has been working for me.

-1

This is magento2 bug. we should update following code

public function getOptionText($value)
{
    $isMultiple = false;
    if (is_array($value)) {
        $isMultiple = true;
        $value = explode(',', $value);
    }

    $options = $this->getSpecificOptions($value, false);

    if ($isMultiple) {
        $values = [];
        foreach ($options as $item) {
            if (in_array($item['value'], $value)) {
                $values[] = $item['label'];
            }
        }
        return $values;
    }

    foreach ($options as $item) {
        if ($item['value'] == $value) {
            return $item['label'];
        }
    }
    return false;
}

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.