Mo2323
1
I want to sort it using liquid like that to be able to make the available product at the start of the collection. how can I do that?
{% assign sorted_array = collection.products | sort: 'available' %}
but it’s not paginationable , and I tried this way too.
{% assign sorted_array = "array of objects" %}
{% for product in collection.products %}
{% if product.available %}
{% assign sorted_array = sorted_array | push: product %}
or
{% assign aval_prod = prodcut %}
{% assign sorted_array = sorted_array | push: product %}
{%endif%}
{%endfor%}
Hello , @Mo2323
You can do like this
{% for product in collection.products %}
{% if product.available %}
/* This will display all the available products first */
{% endif %}
{% endfor %}
{% for product in collection.products %}
{% unless product.available %}
/* This will display all the unavailable products after the available products */
{% endunless %}
{% endfor %}
Mo2323
3
@jaydeep_312
I did that before, but it just sorts each page not the whole collection because of the pagination
Please try to put paginate above both for loops
like this
{% paginate collection.products by 20 %}
{% for product in collection.products %}
{% if product.available %}
/* This will display all the available products first */
{% endif %}
{% endfor %}
{% for product in collection.products %}
{% unless product.available %}
/* This will display all the unavailable products after the available products */
{% endunless %}
{% endfor %}
{% endpaginate %}
Mo2323
5
@jaydeep_312
It’s exactly like that, the two loops inside the pagination. but it works for page by page
Did you find a solution? I am attempting the exact same thing at the moment.