Custom Sorting on a Catalog Group Page

Custom Sorting on a Catalog Group Page

This tutorial explains to to create a custom sort for items.

Issue

Within a normal catalog group page, which displays a listing of items, the items are sorted by description. You may need some other method of item ordering.

Solution

The Catalog Code

A catalog group page will take a list of items and iterate through them, displaying them on the page in a list or grid.

Before Code:

#set($groupItems = $group.getItems())
#foreach($item in $groupItems)
   <td><h4>$item.getDescription()</h4>
#end

After Code:

#set($groupItems = $group.getItems())
$formatHelper.sortByAttribute($groupItems, "sort_order", true)
#foreach($item in $groupItems)
   <td><h4>$item.getDescription()</h4>
#end

$formatHelper is available by default, you may simply reference it. By adding line 2, the item list is now sorted by a custom item attribute named 'sort_order'. You could name the attribute anything.

Creating the item attribute

Navigate to:

Click on an item to edit it.
Click on the Catalog tab.



Click the New Attribute button



Fill in the fields as shown below and save

Managing sort_order attributes

Creating a single sort_order attribute is easy. Managing 200 items using the steps above requires too much work. An easier way is to export → update → import your item attributes.

Navigate to:

Download an excel file using settings found below.



Open the spreadsheet and delete all columns except:

  • Item ID
  • Attribute 01 Name (if you have other attributes, sort_order may be a different attribute than 01. Adjust accordingly.)
  • Attribute 01 Value
  • Description (helpful, not needed for re-upload)

Change the sort order as needed.
Save the file.

Select your file you just edited
Match all rows. you may with to unmatch description, since it's not needed.



For Step 4 Options:

  • Check "Only update existing items"
  • Check "Replace Attributes"

That's it. It might look like a lot of steps, but just save your excel spreadsheet. Whenever you need to make a change, just update the sort_order and upload it again. Using this process, one can easily change the entire sorting of items within a few minutes.