Custom sort order for the Search Results

Use a custom sort order for the Search Results page

By default, the sort order of the products on the Search Results page is based on the setting on the Settings & Tools > Web Store > Webstore Settings page (Default sort order for product listings setting).

If you want to sort the search results differently, you can modify the search results template to do this.

In the templates/cms/search_results.template.html file, make the following changes.

Code Sample

Just above [%THUMB_LIST type:'products' show_rating:'1' limit:'24'%] add the line:

[%set [@my_sort_order@]%][%if [@form:sortby@] eq ''%]popular[%else%][@form:sortby@][%/if%][%/set%]

If you want a different sort order, you can change popular with another option. See the sortby attribute in the thumb_list function.

In the THUMB_LIST, add sortby:'[@my_sort_order@]'. The line should look like this:

[%THUMB_LIST type:'products' show_rating:'1' limit:'24' sortby:'[@my_sort_order@]'%]

Then look for the drop down sort selector:

<select name="sortby" onChange="return this.form.submit();" class="form-control">
    <option value="popular" [%SORTBY type:'products' if:'eq' value:'popular'%]selected[%END SORTBY%]>
        Most Popular
    </option>
    <option value="name" [%SORTBY type:'products' if:'eq' value:'name'%]selected[%END SORTBY%]>
        Name
    </option>
    <option value="SKU" [%SORTBY type:'products' if:'eq' value:'SKU'%]selected[%END SORTBY%]>
        SKU
    </option>
    <option value="lowest_price" [%SORTBY type:'products' if:'eq' value:'lowest_price'%]selected[%END SORTBY%]>
        Lowest Price
    </option>
    <option value="highest_price" [%SORTBY type:'products' if:'eq' value:'highest_price'%]selected[%END SORTBY%]>
        Highest Price
    </option>
</select>

The the select options to:

<select name="sortby" onChange="return this.form.submit();" class="form-control">
    <option value="popular" [%if [@my_sort_order@] eq 'popular'%]selected[%/if%]>
        Most Popular
    </option>
    <option value="name" [%if [@my_sort_order@] eq 'name'%]selected[%/if%]>
        Name
    </option>
    <option value="SKU" [%if [@my_sort_order@] eq 'SKU'%]selected[%/if%]>
        SKU
    </option>
    <option value="lowest_price" [%if [@my_sort_order@] eq 'lowest_price'%]selected[%/if%]>
        Lowest Price
    </option>
    <option value="highest_price" [%if [@my_sort_order@] eq 'highest_price'%]selected[%/if%]>
        Highest Price
    </option>
</select>

Was this article useful?

Be notified when this page is updated. Optional.