I have a requirement to sort an array of objects by multiple properties in a BigCommerce Stencil theme using their built in helpers before iterating over the properly sorted list.
Can anyone please help me?
My current code example:
{{#each (sortBy (after customer.addresses 1) "last_name")}}
<div class="panel panel--address">
<div class="panel-body">
<li>{{company}}</li>
<li>{{address1}}</li>
<li>{{address2}}</li>
<li>{{city}}{{#if state}}, {{state}}{{/if}} {{zip}}</li>
<li>{{country}}</li>
</div>
</div>
{{/each}}
Here I am iterating over a list of addresses in the customer's address book. I omit the first address, then sort the rest of the addresses by last name, then iterate over the sorted list to display some information about each address in a panel.
This all works great. What I now need to do is add first_name and address1 as the second and third properties. This way if the user has multiple addresses with the same names the code should then sort the duplicates by address.
I was hoping for something as simple as
{{#each (sortBy (after customer.addresses 1) "last_name, first_name, address1")}}
But separating the string with commas or spaces just returns the unsorted list.
Documentation for reference:
https://developer.bigcommerce.com/stencil-docs/2a56bda466a81-handlebars-helpers-reference