Javascript function string to sort product results to best sellers, or just show manual results.

gabeo
New Member
2 0 0

On our store https://nudebarre.com/collections/fishnet-tights (upon viewing this pae you may see a best sellers sorting tab, but that's actually not configured properly). We are trying to add in a best sellers tab to our sorting list, but the issue is the people who designed the theme made the sorting system reliant on GraphQL, rather than the standard sort_by functions. Thus, here's the tabs they provided in our theme.bundle.js file, and the functions behind the labels you see on the page:

gabeo_0-1624285998191.jpeg

 

case 17:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var b=[{label:"Newest Arrival",sortFunction:function(e,t){return new Date(t.createdAt.replace(" ","T").split(" ")[0])-new Date(e.createdAt.replace(" ","T").split(" ")[0])}},{label:"A - Z",sortFunction:function(e,t){var n=e.title.toLowerCase(),r=t.title.toLowerCase();return n<r?-1:n>r?1:0}},{label:"Z - A",sortFunction:function(e,t){var n=e.title.toLowerCase(),r=t.title.toLowerCase();return n>r?-1:n<r?1:0}},{label:"Price Low to High",sortFunction:function(e,t){return e.prices.low-t.prices.low}},{label:"Price High to Low",sortFunction:function(e,t){return t.prices.high-e.prices.high}}]

 

tl;dr: I can't for the life of me figure out the function to call and sort out all top selling products within this same sortFunction structure, and if any of you could provide some assistance that would be super appreciated. If you don't know about how to get it to sort to best sellers, can you help me figure out how to make it sort based on the manual configuration on the collection backend?

0 Likes