Smile-SA / elasticsuite

Smile ElasticSuite - Magento 2 merchandising and search engine built on ElasticSearch
https://elasticsuite.io
Open Software License 3.0
761 stars 341 forks source link

[swatches] Array to string conversion #2619

Closed sheepfy closed 2 years ago

sheepfy commented 2 years ago
  1. Blank magento with sample data + smile latest version.
  2. go to women/bottoms-women/pants-women (or whatever place with color or swatches)
  3. click a color in order to add ?color=Blue in the url

Expected result: display correct filtered products

Actual result: Array to string conversion: 1 exception(s): Exception #0 (Exception): Warning: Array to string conversion in /magentohome/vendor/magento/module-swatches/Helper/Data.php on line 199

Exception #0 (Exception): Warning: Array to string conversion in /magentohome/vendor/magento/module-swatches/Helper/Data.php on line 199

#1 array_diff_assoc() called at [vendor/magento/module-swatches/Helper/Data.php:199]
#2 Magento\Swatches\Helper\Data->loadFirstVariation() called at [vendor/magento/module-swatches/Helper/Data.php:231]
#3 Magento\Swatches\Helper\Data->loadFirstVariationWithImage() called at [vendor/smile/elasticsuite/src/module-elasticsuite-swatches/Model/Plugin/ProductImage.php:102]
#4 Smile\ElasticsuiteSwatches\Model\Plugin\ProductImage->loadSimpleVariation() called at [vendor/smile/elasticsuite/src/module-elasticsuite-swatches/Model/Plugin/ProductImage.php:48]
#5 Smile\ElasticsuiteSwatches\Model\Plugin\ProductImage->beforeGetImage() called at [vendor/magento/framework/Interception/Interceptor.php:121]
#6 Magento\Catalog\Block\Product\ListProduct\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#7 Magento\Catalog\Block\Product\ListProduct\Interceptor->___callPlugins() called at [generated/code/Magento/Catalog/Block/Product/ListProduct/Interceptor.php:329]
#8 Magento\Catalog\Block\Product\ListProduct\Interceptor->getImage() called at [vendor/magento/module-catalog/view/frontend/templates/product/list.phtml:56]
#9 include() called at [vendor/magento/framework/View/TemplateEngine/Php.php:71]            
sheepfy commented 2 years ago

I have somehow noticed that this can be fixed by replacing src/module-elasticsuite-swatches/Model/Plugin/ProductImage.php::getFilterArray method with the original method, or commenting these lines:

// if (isset($filterArray[$code]) && !is_array($filterArray[$code])) { // $filterArray[$code] = [$filterArray[$code]]; // } // // if ($attribute->getId() && $this->canReplaceImageWithSwatch($attribute)) { // $filterArray[$code][] = $this->swatchHelperData->getOptionIds($attribute, $value); // }

I am not exactly sure what should happen in here. I have not dug that much.

vahonc commented 2 years ago

Hello @sheepfy,

Please provide more details about your environment, such as version of PHP and which exactly version of Magento and the ElasticSuite you are using. Maybe you are using some custom theme in your store?

BR, Vadym

sheepfy commented 2 years ago

@vahonc Hi, it was a clean, latest Magento Commerce edition 2.4.4 (non enterprise, classic), with sample data. No extra products or attributes than what came from sample data and no changes added to the sample data products.

php version: 8.1 smile/elasticsuite 2.10.10 (latest).

vahonc commented 2 years ago

@sheepfy, thanks for your feedback.

It looks like this issue could be linked to PHP 8 compatibility. I'll try to dig into it more.

BR, Vadym

sheepfy commented 2 years ago

@vahonc If you need, we can setup a sharescreen too, just let me know.

vahonc commented 2 years ago

Hi @sheepfy,

Unfortunately, I was not able to reproduce your issue.

I installed fresh Magento 2.4.4 CE with default sample data and ElasticSuite 2.10.10, of course, I use PHP 8.1.

So, when I go to women/bottoms-women/pants-women category and click on blue color in order to add ?color=Blue to the URL It showed me the correct filtered products without any errors. Please look at my screenshot below: Screenshot from 2022-07-04 14-09-24

Have you tried to check how working color filtration before installing the ElasticSuite module, perhaps something is wrong with installed sample data? I checked it before and after installation ES and in both cases I see results which I expected.

Here're my steps for installation (maybe it will be useful for you):

$ composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.4

$ bin/magento sampledata:deploy

$ bin/magento setup:install with params

$ bin/magento setup:upgrade
$ bin/magento setup:di:compile
$ bin/magento setup:static-content:deploy -f
$ bin/magento indexer:reindex
$ bin/magento cache:clean

$ composer require smile/elasticsuite ~2.10.0
$ bin/magento setup:upgrade
$ bin/magento indexer:reindex
$ bin/magento cache:clean

BR, Vadym

sheepfy commented 2 years ago

@vahonc OK, agree. I tried again and seems to work. We can close this, my bad.

evktalo commented 1 year ago

In case it helps someone later, we had this issue (elasticsuite version 2.9.5, Magento version 2.3.7) and the bug was triggered by a configurable's subproduct having no product image. So adding the image solved the issue as a workaround.

evktalo commented 1 year ago

btw the code causing this issue seems to be https://github.com/Smile-SA/elasticsuite/blob/2.10.x/src/module-elasticsuite-swatches/Model/Plugin/ProductImage.php and that is marked as deprecated since Magento 2.1.6 , so I assume it could be removed?

Amadeco commented 6 months ago

btw the code causing this issue seems to be https://github.com/Smile-SA/elasticsuite/blob/2.10.x/src/module-elasticsuite-swatches/Model/Plugin/ProductImage.php and that is marked as deprecated since Magento 2.1.6 , so I assume it could be removed?

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <!-- Smile_ElasticsuiteSwatches -->
    <type name="Magento\Catalog\Block\Product\ListProduct">
        <plugin name="add_product_object_to_image_data_array" disabled="true" />
    </type>
    <type name="Magento\CatalogSearch\Block\SearchResult\ListProduct">
        <plugin name="add_product_object_to_image_data_array" disabled="true" />
    </type>
</config>

Solved my issue on Magento 2.4.7 and with child products with no images.