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?