Can sorting by a custom field within Related Products be done, if so, how?
I was checking the forum posts but could not find an answer. I did see Brennan had posted the below here.
Thanks in advance.
I was checking the forum posts but could not find an answer. I did see Brennan had posted the below here.
There is nothing built in to sort by a custom field, but you can do it with some template code.
You'll first need to add the custom field the products array so you can later sort on it. This code should go above your category product list loop.
You'll first need to add the custom field the products array so you can later sort on it. This code should go above your category product list loop.
Code:
<mvt:foreach iterator="product" array="category_listing:products"> <mvt:assign name="g.brand" value="''" /> <mvt:item name="customfields" param="Read_Product_Code( l.settings:product:code, 'brand', g.brand )" /> <mvt:if expr="NOT ISNULL g.brand"> <mvt:assign name="l.settings:product:brand" value="g.brand" /> </mvt:if> </mvt:foreach> <mvt:if expr="g.Sort_By EQ 'Brand'"> <mvt:do file="g.module_library_utilities" name="l.null" value="QuickSortArray(l.settings:products, '', 1)" /> </mvt:if>
Comment