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

magento2magento2.2.3

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

Best Answer

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.

Related Topic