RE: Sorting product by availability

thumbnail
Gennaro Lippiello, modified 3 Years ago. Junior Member Posts: 39 Join Date: 3/9/22 Recent Posts

Hi all, is there a way to sort products by availability in a search result widget using the sort widget?

thumbnail
Russell Bohl, modified 3 Years ago. Expert Posts: 308 Join Date: 2/13/13 Recent Posts

Hi Gennaro, I haven't worked with Commerce very much, but you can try to find sortbale fields and add the Sort to the Search > Sort widget. So, is "availability" an indexed field? If it is, and if its data type is sortable (see the linked documentation), you can add a sort option (see the same linked documentation).

But there's also a Commerce > Sort widget. I don't know anything about it, but maybe it supports your use case.

thumbnail
Gennaro Lippiello, modified 3 Years ago. Junior Member Posts: 39 Join Date: 3/9/22 Recent Posts

Hi Russell, yes I saw that and already tried to find some fields. Actually I found 2 of them that I thought may work (itemsQuantity and quantity). But when I use them to sort my list all the products disappears.

I also tried the Commerce > Sort widget, but it seems not configurable.

thumbnail
Russell Bohl, modified 3 Years ago. Expert Posts: 308 Join Date: 2/13/13 Recent Posts

So I added a couple of products, and I don't see that they have quantity, or availability, or any similar fields indexed in the returned document. You can see this if you enable "Show Results in Document Form" in the Search Results widget.