codefog / contao-haste

Haste is a collection of tools and classes to ease working with Contao
http://codefog.pl/extension/haste.html
MIT License
42 stars 24 forks source link

Cart: str_contains(): Argument #1 ($haystack) must be of type string, array given #210

Closed AlexanderWillner closed 1 year ago

AlexanderWillner commented 1 year ago

Description: In Isotope Cart: str_contains(): Argument #1 ($haystack) must be of type string, array given Version: Contao 4.25.25 / Isotope 2.8 / Haste 4.25.25 URL: https://localhost/warenkorb.html

Steps that will reproduce the problem?

  1. Contao / Isotope Backend: define a product with a multi-select attribute
  2. Contao / Isotope Frontend: select multiple values in said attribute + add to cart

What is the expected result? Product in cart.

What happens instead? str_contains(): Argument #1 ($haystack) must be of type string, array given

Possible workaround In /vendor/codefog/contao-haste/library/Haste/Util/Format.php:166:

- if (isset($arrField['eval']['csv']) && str_contains($varValue, $arrField['eval']['csv'])) {
+ if (isset($arrField['eval']['csv']) && !is_array($varValue) && str_contains($varValue, $arrField['eval']['csv'])) {

Any additional information:

Screenshot of product in frontend:

image

Stack Trace:

in vendor/codefog/contao-haste/library/Haste/Util/Format.php (line 166)
in vendor/codefog/contao-haste/library/Haste/Util/Format.php str_contains (line 166)
in vendor/codefog/contao-haste/library/Haste/Util/Format.php :: dcaValueFromArray (line 132)
in vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Isotope.php :: dcaValue (line 484)
in vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Model/ProductCollection.php :: formatOptions (line 1682)
in vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Model/ProductCollection.php -> generateItem (line 1645)
in vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Model/ProductCollection.php -> addItemsToTemplate (line 1492)
in vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Module/AbstractProductCollection.php -> addToTemplate (line 85)
in vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Module/Cart.php -> compile (line 53)
in vendor/contao/core-bundle/src/Resources/contao/modules/Module.php -> compile (line 214)
in vendor/codefog/contao-haste/library/Haste/Frontend/AbstractFrontendModule.php -> generate (line 52)
in vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Module/Module.php -> generate (line 115)
in vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Module/AbstractProductCollection.php -> generate (line 59)
in vendor/contao/core-bundle/src/Resources/contao/elements/ContentModule.php -> generate (line 98)
in vendor/contao/core-bundle/src/Resources/contao/library/Contao/Controller.php -> generate (line 621)
in vendor/contao/core-bundle/src/Resources/contao/modules/ModuleArticle.php :: getContentElement (line 197)
in vendor/contao/core-bundle/src/Resources/contao/modules/Module.php -> compile (line 214)
in vendor/contao/core-bundle/src/Resources/contao/modules/ModuleArticle.php -> generate (line 70)
in vendor/contao/core-bundle/src/Resources/contao/library/Contao/Controller.php -> generate (line 549)
in vendor/contao/core-bundle/src/Resources/contao/library/Contao/Controller.php :: getArticle (line 391)
in vendor/contao/core-bundle/src/Resources/contao/pages/PageRegular.php :: getFrontendModule (line 190)
in vendor/contao/core-bundle/src/Resources/contao/pages/PageRegular.php -> prepare (line 60)
in vendor/contao/core-bundle/src/Resources/contao/controllers/FrontendIndex.php -> getResponse (line 320)
in vendor/symfony/http-kernel/HttpKernel.php -> renderPage (line 163)
in vendor/symfony/http-kernel/HttpKernel.php -> handleRaw (line 75)
in vendor/symfony/http-kernel/Kernel.php -> handle (line 202)
Kernel->handle(object(Request))
in web/index.php (line 44)
qzminski commented 1 year ago

@aschempp wdyt?

beegegroup commented 1 year ago

Same in formatter on line 135. I prepended a $value = (String) $value; before the if statement.

fritzmg commented 1 year ago

I think it should rather be investigated why $varValue is (already) an array at this point.

aschempp commented 1 year ago

Fixed in b48ed49c2b78ad05128696dbbde697ceb22ba4b6