#community-help

Sorting and Grouping Products According to Price

TLDR Valdrin asked how to sort and group products and always display the lowest price. Kishore Nallan clarified internal and global sorting, suggesting client side sorting as a workaround.

Powered by Struct AI
+11
5
8mo
Solved
Join the chat
Jan 12, 2023 (8 months ago)
Valdrin
Photo of md5-598cead4c3e662dc3df10f097e989bf7
Valdrin
10:25 AM
👋 Hello all, I have a question regarding grouping.
My specific case is where I’d like to group certain products and show the lowest price for each group.
So, in order to show the lowest price, I’d have to sort the results like such: sort_by: "amount:asc",. But if the user changes the sort from lowest -> highest to highest -> lowest using one of the widgets, then the value I receive back also changes, and then instead of showing the lowest price it would show the highest price. Let me know if you need any more info or clarification
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:31 AM
The ordering within the group is the same as the overall ordering. So you can't sort globally by descending but sort ascending internally at the moment.
Valdrin
Photo of md5-598cead4c3e662dc3df10f097e989bf7
Valdrin
10:32 AM
Is there a possible workaround to this? Perhaps by querying the endpoint again and searching by that specific id?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:38 AM
Will have to do client side sorting. I can't think of another way. During grouping the global sort order is used to identify which k items to pick per group (when group_limit is used). So even client side sorting would only sort within the group returned on a global order.
Valdrin
Photo of md5-598cead4c3e662dc3df10f097e989bf7
Valdrin
10:39 AM
Alright, thanks for your help!
+11