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

PHP 8.1 compatibility #2527

Closed peterjaap closed 2 years ago

peterjaap commented 2 years ago

Installing ElasticSuite 2.10.9.1 using composer with the --ignore-platform-reqs flag got me this on a category page;

Fatal error: During inheritance of IteratorAggregate: Uncaught Exception: Deprecated Functionality: Return type of Smile\ElasticsuiteCore\Search\Adapter\Elasticsuite\Response\QueryResponse::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Response/QueryResponse.php on line 75 in /data/client/magento2/vendor/magento/framework/App/ErrorHandler.php:61
Stack trace:
#0 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Response/QueryResponse.php(27): Magento\Framework\App\ErrorHandler->handler(8192, 'Return type of ...', '/data/client/mag...', 75)
#1 /data/client/magento2/vendor/composer/ClassLoader.php(571): include('/data/client/mag...')
#2 /data/client/magento2/vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile('/data/client/mag...')
#3 [internal function]: Composer\Autoload\ClassLoader->loadClass('Smile\\Elasticsu...')
#4 /data/client/magento2/vendor/magento/framework/ObjectManager/Relations/Runtime.php(38): class_exists('Smile\\Elasticsu...')
#5 /data/client/magento2/vendor/magento/framework/Interception/Config/Config.php(157): Magento\Framework\ObjectManager\Relations\Runtime->has('Smile\\Elasticsu...')
#6 /data/client/magento2/vendor/magento/framework/Interception/Config/Config.php(180): Magento\Framework\Interception\Config\Config->_inheritInterception('Smile\\Elasticsu...')
#7 /data/client/magento2/vendor/magento/framework/Interception/ObjectManager/Config/Developer.php(61): Magento\Framework\Interception\Config\Config->hasPlugins('Smile\\Elasticsu...')
#8 /data/client/magento2/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(47): Magento\Framework\Interception\ObjectManager\Config\Developer->getInstanceType('Smile\\Elasticsu...')
#9 /data/client/magento2/vendor/magento/framework/ObjectManager/ObjectManager.php(56): Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create('Smile\\Elasticsu...', Array)
#10 /data/client/magento2/generated/code/Smile/ElasticsuiteCore/Search/Adapter/Elasticsuite/Response/QueryResponseFactory.php(43): Magento\Framework\ObjectManager\ObjectManager->create('\\Smile\\Elastics...', Array)
#11 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Adapter.php(90): Smile\ElasticsuiteCore\Search\Adapter\Elasticsuite\Response\QueryResponseFactory->create(Array)
#12 /data/client/magento2/vendor/magento/module-search/Model/SearchEngine.php(42): Smile\ElasticsuiteCore\Search\Adapter\Elasticsuite\Adapter->query(Object(Smile\ElasticsuiteCore\Search\Request))
#13 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Search/Request/Product/Coverage/Provider.php(106): Magento\Search\Model\SearchEngine->search(Object(Smile\ElasticsuiteCore\Search\Request))
#14 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Search/Request/Product/Coverage/Provider.php(95): Smile\ElasticsuiteCatalog\Search\Request\Product\Coverage\Provider->loadProductCounts()
#15 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Search/Request/Product/Aggregation/Provider/FilterableAttributes/Modifier/Coverage.php(134): Smile\ElasticsuiteCatalog\Search\Request\Product\Coverage\Provider->getSize()
#16 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Search/Request/Product/Aggregation/Provider/FilterableAttributes/Modifier/Coverage.php(69): Smile\ElasticsuiteCatalog\Search\Request\Product\Aggregation\Provider\FilterableAttributes\Modifier\Coverage->getCoverageRates(1, 'catalog_view_co...', NULL, Array, Array)
#17 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Search/Request/Product/Aggregation/Provider/FilterableAttributes.php(81): Smile\ElasticsuiteCatalog\Search\Request\Product\Aggregation\Provider\FilterableAttributes\Modifier\Coverage->modifyAttributes(1, 'catalog_view_co...', Array, NULL, Array, Array)
#18 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-core/Search/Request/ContainerConfiguration.php(156): Smile\ElasticsuiteCatalog\Search\Request\Product\Aggregation\Provider\FilterableAttributes->getAggregations(1, NULL, Array, Array)
#19 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-core/Search/Request/ContainerConfiguration/Aggregation/Resolver.php(37): Smile\ElasticsuiteCore\Search\Request\ContainerConfiguration->getAggregations(NULL, Array, Array)
#20 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-core/Search/Request/Builder.php(205): Smile\ElasticsuiteCore\Search\Request\ContainerConfiguration\Aggregation\Resolver->getContainerAggregations(Object(Smile\ElasticsuiteCore\Search\Request\ContainerConfiguration), NULL, Array, Array)
#21 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-core/Search/Request/Builder.php(147): Smile\ElasticsuiteCore\Search\Request\Builder->getContainerAggregations(Object(Smile\ElasticsuiteCore\Search\Request\ContainerConfiguration), NULL, Array, Array)
#22 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(625): Smile\ElasticsuiteCore\Search\Request\Builder->create(1, 'catalog_view_co...', 0, 12, NULL, Array, Array, Array, Array)
#23 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(452): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->prepareRequest()
#24 /data/client/magento2/vendor/magento/framework/Data/Collection/AbstractDb.php(343): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->_renderFiltersBefore()
#25 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(509): Magento\Framework\Data\Collection\AbstractDb->_renderFilters()
#26 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/ResourceModel/Product/Fulltext/Collection.php(316): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->_renderFilters()
#27 /data/client/magento2/generated/code/Smile/ElasticsuiteCatalog/Model/ResourceModel/Product/Fulltext/Collection/Interceptor.php(104): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection->getFacetedData('categories')
#28 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/Layer/Filter/Category.php(150): Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection\Interceptor->getFacetedData('categories')
#29 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Model/Layer/Filter/Category.php(197): Smile\ElasticsuiteCatalog\Model\Layer\Filter\Category->_getItemsData()
#30 /data/client/magento2/vendor/magento/module-catalog/Model/Layer/Filter/AbstractFilter.php(159): Smile\ElasticsuiteCatalog\Model\Layer\Filter\Category->_initItems()
#31 /data/client/magento2/vendor/magento/module-catalog/Model/Layer/Filter/AbstractFilter.php(148): Magento\Catalog\Model\Layer\Filter\AbstractFilter->getItems()
#32 /data/client/magento2/vendor/magento/module-catalog/Model/Layer/Category/AvailabilityFlag.php(33): Magento\Catalog\Model\Layer\Filter\AbstractFilter->getItemsCount()
#33 /data/client/magento2/vendor/magento/module-catalog/Model/Layer/Category/AvailabilityFlag.php(23): Magento\Catalog\Model\Layer\Category\AvailabilityFlag->canShowOptions(Array)
#34 /data/client/magento2/vendor/magento/module-layered-navigation/Block/Navigation.php(126): Magento\Catalog\Model\Layer\Category\AvailabilityFlag->isEnabled(Object(Magento\Catalog\Model\Layer\Category\Interceptor), Array)
#35 /data/client/magento2/vendor/smile/elasticsuite/src/module-elasticsuite-catalog/Block/Navigation.php(83): Magento\LayeredNavigation\Block\Navigation->canShowBlock()
#36 /data/client/magento2/app/design/frontend/Client/Hyva/Magento_LayeredNavigation/templates/layer/view.phtml(26): Smile\ElasticsuiteCatalog\Block\Navigation->canShowBlock()
peterjaap commented 2 years ago

Here's a patch I used with vaimo/composer-patches;

@package smile/elasticsuite
@level 0
@link https://github.com/Smile-SA/elasticsuite/issues/2527

Subject: [PATCH] Fix for PHP 8.1 Deprecated Functionality return type mismatch

diff --git src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Response/QueryResponse.php src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Response/QueryResponse.php
index 2b59ce4..79a4554 100644
--- src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Response/QueryResponse.php
+++ src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Response/QueryResponse.php
@@ -64,6 +64,7 @@ class QueryResponse implements ResponseInterface
     /**
      * {@inheritDoc}
      */
+    #[\ReturnTypeWillChange]
     public function count()
     {
         return $this->count;
@@ -72,6 +73,7 @@ class QueryResponse implements ResponseInterface
     /**
      * {@inheritDoc}
      */
+    #[\ReturnTypeWillChange]
     public function getIterator()
     {
         return new \ArrayIterator($this->documents);
romainruaud commented 2 years ago

Hi, this is already fixed by those commits :

https://github.com/Smile-SA/elasticsuite/commit/80fe224f4435f387fe67b0c0b4baf6012a68f5cb

https://github.com/Smile-SA/elasticsuite/commit/6aac311f2f55d94dccbe4990f82c4e0b3af5a89b

But these commits are only on 2.10.x branch for now. We plan to release a 2.10.10 version imminently that will contain all compatibility fixes for Magento 2.4.4. You can begin using the branch right now if you do not want to wait.

Regards

hiteshbalpande commented 2 years ago

@peterjaap , I tried above solutions but it's throwing error for me. Please check error message:

Tried to apply it like in command line:

git apply MAGETWO-ES-244-2022.patch error: module-elasticsuite-core/Search/Adapter/Elasticsuite/Response/QueryResponse.php: No such file or directory

location: root_project_folder\MAGETWO-ES-244-2022.patch with patch code given by you.

Please let me know any suggestion, Thanks!!

romainruaud commented 2 years ago

@hiteshbalpande please use Elasticsuite 2.10.10 if you are using PHP 8.1.

Regards

hiteshbalpande commented 2 years ago

Elasticsuite 2.10.10

@romainruaud , I tried but it's not upgrading to smile/elasticsuite 2.10.10 version. Still it's loading with "smile/elasticsuite": "2.10.9.1" version only.