So…
Seems to me this should work… lol
{% assign products = selected_collection.products | sort_by: 'price-descending' %}
But it does not…
based on the documentation here, I think I have deeply misinterpreted what this means:
https://shopify.dev/api/liquid/objects#collection-sort_by
So I figured I would try to SET the default_sort_by
https://shopify.dev/api/liquid/objects#collection-sort_by
{% assign products.default_sort_by = 'price-descending' %}
nope… cant do that either. lol
So…
Am I correct here in the following conclusions:
CONCLUSION #1:
There is NO WAY to change the SORT_BY nor the DEFAULT_SORT_BY for a collection array using either of those objects… (seems tragic to me)
- I feel I must be doing it wrong
Perhaps I have been spoiled by all the wonderful array sorting options available in OOP’s like PHP
CONCLUSION #2:
The ONLY WAY I can sort in Liquid is by using the ARRAY FILTERS
https://shopify.dev/api/liquid/filters#sort
Which means I have to do this:
price-ascending (low to high)
{% assign products = selected_collection.products | sort: 'price' %}
price-descending (high to low)
{% assign products = selected_collection.products | sort: 'price' | reverse %}
title-ascending (A-Z)
{% assign products = selected_collection.products | sort: 'title' %}
title-descending (Z-A)
{% assign products = selected_collection.products | sort: 'title' | reverse %}
created-ascending
{% assign products = selected_collection.products | sort: 'created_at' %}
created-descending
{% assign products = selected_collection.products | sort: 'created_at' | reverse %}
sort_by=manual
Simply do not sort in Liquid
sort_by=best-selling
No such thing in Liquid
sort_by=inventory
No such thing in Liquid
*(only possible using first_available_variant.inventory_quantity inside of an elaborate for/loop)*
However, I could do this 1 new thing…
https://shopify.dev/api/liquid/objects#product
Sort by ID -lol ![]()
seems legit and useful…
{% assign products = selected_collection.products | sort: 'id' %}
{% assign products = selected_collection.products | sort: 'id' | reverse %}
As such, if I want to create a drop menu in a featured collection section module
to let the theme user pick the sorting option for a segmented collection
I would need a really long if/else conditional statement to correctly cover all those options (above) instead of a simple drop menu that assigns a clean variable like this
{% assign products = selected_collection.products | sort_by: section.settings.custom_sort %}
*I presume this is impossible*
*I must instead use the items (above) in a long overly elaborate conditional statement [yuk] :(*
*Instead of giving the theme user a simple section setting drop menu (that matches default_sort_by)*
*I must remap all of these concepts into the Liquid array filter (and skip best-selling)*
Are my conclusions correct and true here?
Or… am I just doing this wrong?
Am I doing this in the stupidest way possible because I do not understand the sort_by feature?