Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

How to sort line items by item's properties with liquid

How to sort line items by item's properties with liquid

nathdev
Visitor
2 0 1

How can I sort an array of line items (either from the cart, checkout or order objects) according to a property value that the item may have?

 

I've tried:

{% assign sorted_line_items = cart.items | sort: "properties.In Room" %}
and
{% assign sorted_line_items = cart.items | sort: "properties['In Room']" %}
 
But neither of them work. Simply no sort is applied.
 
The 'In Room' key has a string value e.g. 'Main Bathroom, 'Ensuite' etc.
 
Some line items also may not have this property at all.
 
Any suggestions?
Reply 1 (1)

nathdev
Visitor
2 0 1

Anyone?