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

Exception #0 (Exception): Warning: strpos() expects parameter 1 to be string, array given in /home/equpo/public_html/demo/vendor/magento/module-eav/Model/Entity/Attribute/Source/Table.php on line 157
#0 [internal function]: Magento\Framework\App\ErrorHandler->handler(2, 'strpos() expect...', '/home/equpo/pub...', 157, Array)
#1 /home/equpo/public_html/demo/vendor/magento/module-eav/Model/Entity/Attribute/Source/Table.php(157): strpos(Array, ',')
#2 /home/equpo/public_html/demo/vendor/magento/module-eav/Model/Entity/Attribute/Frontend/AbstractFrontend.php(331): Magento\Eav\Model\Entity\Attribute\Source\Table->getOptionText(Array)
#3 /home/equpo/public_html/demo/vendor/magento/module-eav/Model/Entity/Attribute/Frontend/AbstractFrontend.php(176): Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend->getOption(Array)

when i open prouduct details page for all products

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

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

    if (!is_array($value)) {
        $value = [$value];
    }
    $optionsText = [];
    foreach ($options as $item) {
        if (in_array($item['value'], $value)) {
            $optionsText[] = $this->escaper->escapeHtml($item['label']);
        }
    }

how i can solve this???

8
  • What will you get in the $value ?
    – aravind
    Commented Feb 25, 2019 at 10:59
  • don't know bro.... Commented Feb 25, 2019 at 11:02
  • From where did u call this function ? please share the code
    – aravind
    Commented Feb 25, 2019 at 11:06
  • i did not call this function Commented Feb 25, 2019 at 11:29
  • Have you created any attribute ? what type of attribute is that?
    – aravind
    Commented Feb 25, 2019 at 11:35

1 Answer 1

0

This looks like the same issue as strpos() expects parameter 1 to be string, array given in vendor/magento/module-eav/Model/Entity/Attribute/Source/Table.php on line 160

As mentioned on the solution of the attached link it is a magento2 bug and the code should look like the following:

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.