4

After I created some product in magento backend, there is an error.

Method Magento\Ui\TemplateEngine\Xhtml\Result::__toString() must not throw an exception, caught Error: Call to undefined method Magento\Framework\Data\Collection::__sleep() in /var/www/vhosts/plchk/vendor/magento/module-ui/Component/Wrapper/UiComponent.php on line 0

By searching the net, I found Magento 2 Impossible To Trace Admin Grid Error: Fatal error: Method Magento\Ui\TemplateEngine\Xhtml\Result::__toString() must not throw an exception.

Using this method, I found that the 'product.form.configurable.matrix' is the cause of problem.

I changed

    protected function _toHtml()
{
    foreach ($this->getChildNames() as $childName) {
        $childBlock = $this->getLayout()->getBlock($childName);
        if ($childBlock) {
            $wrapper = $this->blockWrapperFactory->create([
                'block' => $childBlock,
                'data' => [
                    'name' => 'block_' . $childName
                ]
            ]);
            $this->component->addComponent('block_' . $childName, $wrapper);
        }
    }

    $result = $this->component->render();
    return (string)$result;
}

to

 protected function _toHtml()
    {
        foreach ($this->getChildNames() as $childName) {
            $childBlock = $this->getLayout()->getBlock($childName);
            if ($childBlock) {
                $wrapper = $this->blockWrapperFactory->create([
                    'block' => $childBlock,
                    'data' => [
                        'name' => 'block_' . $childName
                    ]
                ]);
                if($childName != 'product.form.configurable.matrix'){
                    $this->component->addComponent('block_' . $childName, $wrapper);
                } else {
                }


                //var_dump($childName);
            }
        }
        $result = $this->component->render();
        return  (string) $result;
    }

Now, I can load the admin/product/edit page but I cannot save the product. Anyone got a solution?

1 Answer 1

0

I have also face this issue, then I run commands

c:flush;c:clean;setup:upgrade;setup:di:compile

But still face the same Issue, then I have to remove the generated folder then it resolved.

In the magento root directory run this

rm -rf generated/*

Hope it help

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.