cancel
Showing results for 
Search instead for 
Did you mean: 

How to change result order in search?

How to change result order in search?

How to change result order in search?

 

Hello,

 

Let me explain, currently when searching for a product these return by default the most relevant in ascending order, as a result the products appear but for example the first one is "available" and the next one is "coming soon" being those their labels.

 

How can I make it return the products, for example, first all the "available" ones and then the "coming soon" ones?

Currently I have the "changeCollection" function as seen in the image where the collection that returns the order is, for example, changing it instead of "ranking_summaries" to "available" does not change it and the search engine query continues with "ranking_summaries".

 

Any idea why it overwrites it or how or where this can be changed?

Beforehand thank you very much.

 

Captura de pantalla de 2022-09-13 18-17-53.png

1 REPLY 1

Re: How to change result order in search?

MyHealthAtVanderbilt Help

Create a file named catalogsearch_result_index.xml at Venodr\Module\view\frontend\layout and paste the following code

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<referenceBlock class="Magento\CatalogSearch\Block\SearchResult\ListProduct" name="search_result_list">
<action method="setDefaultDirection">
<argument name="dir" xsi:type="string">
asc
</argument>
</action>
</referenceBlock>
</referenceContainer>
</body>
Now setDefaultDirection accordingly