Hi <@U8X7E86M6> , I’d like to ask about the defaul...
# suitecommerce
m
Hi @Steve Goldberg , I’d like to ask about the default search results on the SC PLP page. Is it possible to sort by multiple fields at the same time? For example, first by category (DESC), then by release date (DESC), and finally by size (ASC)? Or is there any alternative way to achieve this?
s
Kinda. The items API supports multiple sorts but there's no way in the interface to implement this out of the box, so it would have to be a customisation
Essentially, you are using 'master search options' which are added to every request to the item search API
An example could be something like this:
Copy code
mountToApp: function mountToApp (container) {
    var Environment = container.getComponent('Environment');

    if (Environment) {
        Environment.defineSearchMasterOptions('Facets', function (searchApiMasterOptions) {
            searchApiMasterOptions.sort='custitem_search_boost:desc'
            return searchApiMasterOptions
        });
    }
}
In this example, I am telling it to sort results first by custom field on the item – then it will use whatever the customer selects in the UI
This also always applies it, but there's no reason why you couldn't bind these to events (such as buttons in the UI)
m
Thanks for the explanation,that makes sense. Appreciate your guidance!