Open navigation

Category Navigation: Preserve Layout for Magento 2.4.5

Note: This only applies to merchants running Magento 2.4.5 using Klevu Smart Category Page Navigation where Ordering & Rendering is set to “Preserve your Magento layout”.

With the release of 2.4.5, Magento made a change to \Magento\Elasticsearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplier . These changes have been removed in the 2.4.6 release. Part of this change removes the order of the product collection, including the sort order set by Klevu.

As this change has been reversed in 2.4.6 and our module supports both versions, we will not be adding a fix for this into our module. We can however advise on how to fix the issue and supply an explanation of the issue along with a sample patch to skip the changes introduced in 2.4.5.

The issue is caused by the getProductIdsBySaleability method (which calls categoryProductByCustomSortOrder) here magento2/SearchResultApplier.php at 2.4.5-p2 · magento/magento2 

As you can see those no longer exist in 2.4.6 magento2/SearchResultApplier.php at 2.4.6 · magento/magento2 

Here is an example diff of one way you could work around this issue by no longer calling that code. As every merchant’s Magento installation is different we will leave it to your developers to decide the best way to overcome this issue. Note this example would also remove the placement of out-of-stock products at the end of the list for sort orders that are not returned from Klevu e.g. order by name/price.

diff --git a/vendor/magento/module-elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php b/vendor/magento/module-elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php
index 97cb92ab3b0..f38333cd328 100644
--- a/vendor/magento/module-elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php
+++ b/vendor/magento/module-elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php
@@ -105,7 +105,12 @@ class SearchResultApplier implements SearchResultApplierInterface

-        $ids = $this->getProductIdsBySaleability();
+        // This functionality was added in Magento 2.4.5 and removed in Magento 2.4.6
+        // It removes the ordering of results set by Klevu.
+        // Results from Klevu will be ordered correctly
+        $ids = []; // $this->getProductIdsBySaleability();

         if (count($ids) == 0) {
             $items = $this->sliceItems($this->searchResult->getItems(), $this->size, $this->currentPage);

This path could be installed using composer patches as outlined here Apply Patches | Adobe Commerce

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.