Display In-Stock products first? How?

5 months ago
NC 3.90

I want to display those products which are in stock first at the top of the category or search page, but keep the default sorting. Those products which are out of stock must go to the end.

How could I do it in .cshtml?

I mean something like this...:
@if (stockMessage.Equals(localizationService.GetResource("Products.Availability.OutOfStock")))
    {
      What do I write in here? :)
    }


Thanks for your help in advance!
5 months ago
I don't think it can't be "easily" or "properly" done in .cshtml, because the page uses AJAX to get products, and the "order by" is handled on the server (controller).  So two issues:
1) you'd have to handle the AJAX return event to reorder the products (JavaScript)
2) if you try to re-order the products in .cshtml page, you are only ordering the products that are returned by the AJAX ordering which are limited by page size.   If you do adjust the page size (e.g. 9999), then if you have many products it could take a long time to retrieve them from the server (to then be reordered in JavaScript)


(Alternately / possibly: consider using SQL to UPDATE the DisplayOrder column)
5 months ago
Yeah, i'm doing UPDATE via SQL to Display products on stock first

Example: https://genelec.ba/desktopc-101
5 months ago
musoviich wrote:
Yeah, i'm doing UPDATE via SQL to Display products on stock first

Example: https://genelec.ba/desktopc-101


How do you do it? Do you just manually change the Display Order column?