isotope / core

Core repository of Isotope eCommerce, an eCommerce extension for Contao Open Source CMS
https://isotopeecommerce.org
135 stars 107 forks source link

Array to string conversion in the product picker #2340

Closed ameotoko closed 1 year ago

ameotoko commented 2 years ago

Contao 4.13.6, Isotope 2.8.5, PHP 8.1

Exactly the same problem as in #2324. It happens in backend when you go to the related products of a product, and then edit the category.

ErrorException:
Warning: Array to string conversion

  at vendor/contao/core-bundle/src/Resources/contao/classes/DataContainer.php:1715
  at Contao\DataContainer->generateRecordLabel(array('id' => 108, 'pid' => 0, 'images' => 'a:1:{i:0;a:5:{s:3:"src";s:20:"image.jpg";s:3:"alt";s:0:"";s:4:"link";s:0:"";s:4:"desc";s:0:"";s:9:"translate";s:4:"none";}}', ...), 'tl_iso_product')
     (vendor/contao/core-bundle/src/Resources/contao/widgets/Picker.php:296)
  at Contao\Picker->renderLabel(array('id' => 108, 'pid' => 0, 'images' => 'a:1:{i:0;a:5:{s:3:"src";s:20:"image.jpg";s:3:"alt";s:0:"";s:4:"link";s:0:"";s:4:"desc";s:0:"";s:9:"translate";s:4:"none";}}', ...), object(DC_ProductData))
     (vendor/contao/core-bundle/src/Resources/contao/widgets/Picker.php:261)
  at Contao\Picker->generateValues(true)
     (vendor/contao/core-bundle/src/Resources/contao/widgets/Picker.php:123)
  at Contao\Picker->generate()
     (vendor/contao/core-bundle/src/Resources/contao/library/Contao/Widget.php:652)
  at Contao\Widget->generateWithError(true)
     (vendor/contao/core-bundle/src/Resources/contao/templates/backend/be_widget.html5:3)
  at include('/Users/andrey/Sites/schlossakademie/vendor/contao/core-bundle/src/Resources/contao/templates/backend/be_widget.html5')
     (vendor/contao/core-bundle/src/Resources/contao/library/Contao/TemplateInheritance.php:108)
  at Contao\Widget->inherit()
     (vendor/contao/core-bundle/src/Resources/contao/library/Contao/Widget.php:599)
  at Contao\Widget->parse()
     (vendor/contao/core-bundle/src/Resources/contao/classes/DataContainer.php:788)
  at Contao\DataContainer->row('{category_legend},category;{products_legend},products')
     (vendor/contao/core-bundle/src/Resources/contao/drivers/DC_Table.php:1946)
  at Contao\DC_Table->edit()
     (vendor/contao/core-bundle/src/Resources/contao/classes/Backend.php:667)
  at Contao\Backend->getBackendModule('iso_products', null)
     (vendor/contao/core-bundle/src/Resources/contao/controllers/BackendMain.php:168)
  at Contao\BackendMain->run()
     (vendor/contao/core-bundle/src/Controller/BackendController.php:49)
  at Contao\CoreBundle\Controller\BackendController->mainAction()
     (vendor/symfony/http-kernel/HttpKernel.php:152)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:74)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:202)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public/index.php:44)

(irrelevant product data has been cut out)

This happens when Contao tries to render the preview of the picker widget, i.e. this part:

Screenshot 2022-07-24 at 12 09 45

This has been already fixed for product list in https://github.com/isotope/core/commit/175a07f4b3e84fcfee63d48f8eda91f8475cf512, but is not applied here, because rendering labels has been refactored into a separate method in Contao 4.13 (DataContainer::generateRecordLabel()), and the picker widget calls that method directly, which in this case resolves to the parent class, not DC_ProductData.

~You cannot check it in the demo because it uses Isotope 2.7 (no picker widget) and Contao 4.9 (no separate method).~

I'll provide a PR.

aschempp commented 1 year ago

see #2341