Hi Gavin,
You can use the following code in the hook_post_process.groovy to sort your facets (this will sort them inside the object model):
transaction?.response?.facets.each() {
// Rename 'YourFacet' as per your desired fact name
if (it.name == "YourFacet") {
it.categories.each() { c -> customSort(c) }
}
}
// Recursively sorts FB facet categories using customCompare
def customSort(category) {
category.values.sort { a, b -> customCompare(a, b) }
category.categories.each() { f -> customSort(f) }
}
// Sorts a and b as per a static translation map
def customCompare(a, b) {
def labelOrderMap = [ "january" : "00001",
"february" : "00002",
"march" : "00003",
"april" : "00004",
"may" : "00005",
"june" : "00006",
"july" : "00007",
"august" : "00008",
"september" : "00009",
"october" : "00010"];
def label_a = a.label;
def label_b = b.label;
if (labelOrderMap.containsKey(label_a)) {
label_a = labelOrderMap[label_a];
}
if (labelOrderMap.containsKey(label_b)) {
label_b = labelOrderMap[label_b];
}
label_a.compareTo(label_b);
}
The example static map contains month names, so feel free to modify this as per your needs. Alternatively you could modify the signature of the customCompare function to be passed in the map (so you can pass in different maps for different facets).
Let me know if you have any further issues with this!