Sorting an ajax request

Highlighted
Shopify Expert
61 1 6

I'm looking for a list of the options that we can use with the 'sort' array filter: https://shopify.dev/docs/themes/liquid/reference/filters/array-filters#sort

 

I'm using the following liquid in a 'collection.json.liquid' file:

 

{% assign collection = collection.products | sort: 'price' | reverse %}
{% for product in collection %}
{% endfor %}

 

And have the following options:

 

Price - descending

{% assign collection = collection.products | sort: 'price' %}

 

Price - ascending

{% assign collection = collection.products | sort: 'price' | reverse %}

 

Title - descending

{% assign collection = collection.products | sort: 'title' %}

 

Title - ascending

{% assign collection = collection.products | sort: 'title' | reverse %}

 

Are there options for 'manual', 'best-selling' and 'created' like what we have with the 'sort_by'  url filter (https://shopify.dev/docs/themes/liquid/reference/objects/collection#collection-sort_by).

 

Or alternatively, can we include the 'sort_by' url parameter in an ajax call eg.

 

$.ajax({
    url: "/collections/mens?sort_by=price-ascending?view=json',
    type: 'GET'
})
 
0 Likes
Highlighted
Shopify Expert
61 1 6

Does anyone have any idea whether this is possible or not?

0 Likes