Order Search Bar Suggestions/Results Alphabetically - Dawn Theme

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 :slightly_smiling_face:

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

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!