Troubleshooting for Preserve Layout Conflict in Magento2

If you have enabled the Preserving your theme layout option for the search results page and you do not see any results on the catalog search results page, please rebuild the Magento Indices as this is likely to solve the problem.

If rebuilding the indices does not solve the issue, please follow the instructions below to debug the issue further:

If the product count is not matching with the Klevu output:

  1. Once the preserve layout option is chosen from the Klevu configurations, this mismatch of product count can be investigated by comparing the results on the Klevu based template layout search page i.e.
     <MAGENTO-URL>/search/?q=<search-term>

    and the default Magento Catalog Search page i.e.

    <MAGENTO-URL>/catalogsearch/result/?q=<search-term>.
  2. If product counts are not matching, firstly, please execute the following MySQL query in PHPMyAdmin:
    SELECT * FROM `catalog_product_index_eav` WHERE `entity_id` = <PRODUCT-ID> AND `store_id` = <STORE-ID>

    Where the PRODUCT-ID refers to the specific product id and STORE-ID refers to store Id of the store.

Magento Indexer Issue

  1. If no output is returned after executing the MySQL query, there seems to be the issue with indexing process at the Magento website level and please check it further on your end to fix this issue.

Stock Management Issue

  1. If the returned output has some data, it could be some issue with stock management. In this case, please compare the stock settings on the website as well on the Klevu Merchant Center(KMC).
  2. To check the stock setting from the KMC, please follow the below guide:
    https://support.klevu.com/knowledgebase/out-of-stock-products-in-search-results/
  3. To check stock settings from the Magento, please go to Admin → Stores → Configuration → Catalog → Inventory → Stock Options → Display Out of Stock Products.
  4. Both the setting should be the same and if not, please select the appropriate setting as per the requirements.

If product counts are correct but products are not sorted as per the Klevu’s relevance

The Klevu sorting can be checked by comparing results on the Auto-suggestions and preserve layout catalog search page. If there are some issues with results sorting, it can be conflict of Klevu module with some third-party module. To resolve this, please apply the below changelog:

  1. Add below line in Magento-root/vendor/klevu/module-productsearch/etc/di.xml
    <type name="Magento\Catalog\Block\Product\ProductList\Toolbar">
    <plugin name="Klevu_Search::setRelevance" type="Klevu\Search\Model\ResourceModel\Fulltext\Collection" 
     sortOrder="101"/>
    </type>
  2. Add attached Collection.php file to the directory location <Magento-root>/vendor/klevu/module-productsearch/Mode/ResourceMode/Fulltext/
  3. Run the DI, compilation, clear the cache and rebuild Magento Indexes.

If the website is using the Amasty module

Recently, we have faced conflict of Amasty module with Klevu module and as a solution, we have created a changelog for the Amasty Xlanding module, Here are the instructions to apply the below changelog:

  1. Go the to the file <magento-root>/app/code/Amasty/Xlanding/Plugin/ProductListToolbar.php
  2. Find for the function afterSetCollection and the below code:
     return $toolbar->getCollection()->setOrder('entity_id', 'DESC');
  3. Comment this code as
    //return $toolbar->getCollection()->setOrder('entity_id', 'DESC');

Please note, if the website is not using the Xlanding module, please refer to the changelog of Klevu module that is referred in the previous topic.