QuickSortArray
can be used to sort by any field in the structure.
What if the sort field doesn't exist?
Scenario: Sort shipping methods from low to high while including the name so that shipping fees are grouped from via provider from low to high, such as UPS, USPS, FED EX, etc...
Note: We'll be using the miva_array_copy_ref(...)
method so we don't need to create a second array.
Create a new field in the shipping methods array specifically for sorting, set up a temporary array, then move data to original array.
<mvt:assign name="l.ok" value="miva_array_copy_ref(l.settings:shippingmethods,1,miva_array_elements(l.settings:shipping_methods),l.settings:smethods,1)" />
<mvt:foreach iterator="method" array="smethods">
<mvt:assign name="l.settings:method:sort" value="l.settings:method:name $ l.settings:method:price" />
</mvt:foreach>
<mvt:do file="g.Module_Library_Utilities" name="l.success" value="QuickSortArray(l.settings:shippingmethods, ':sort', 'asc')" />
Now when you roll through the array, the methods are sorted by the :sort
field.