What's your biggest current challenge? Have your say in Community Polls along the right column.

Order Search Bar Suggestions/Results Alphabetically - Dawn Theme

Order Search Bar Suggestions/Results Alphabetically - Dawn Theme

teoias
Visitor
3 0 0

Hey All

 

I'm using the search bar on the Dawn theme to search pages, but the suggestions/results show in a random order. Does anyone know how to sort them alphabetically? Thanks in advance 🙂

 

LINK TO PREVIEW (We are working on an unpublish theme)

 

Screen Shot 2024-11-15 at 3.01.29 PM.png

 

Reply 1 (1)

steve_michael2
Trailblazer
328 31 39

Hello, @teoias 

1) Go to Online Store
2) Edit Code
3) Find en.default.json file

fetch('/search/suggest.json?q=' + query + '&resources[type]=product')
  .then((response) => response.json())
  .then((data) => {
    let results = data.resources.results.products;

    // Sort results alphabetically by title
    results.sort((a, b) => a.title.localeCompare(b.title));

    renderSearchResults(results); // Function to display sorted results
  });

Thanks!

Crafting exceptional online experiences with innovative design and technology.

Try Big Bulk Discount To Boost Your Store Sales with Volume/Tier Discount