How to show out of stock products at the end of the list

Iman Emran asked on December 28, 2017 22:35

Hi,

I want to create a filter displaying products sorted according to products' names or products' prices but I always want to show out of stock products at the end of the products list.

I used Smart search filter which is in the document: https://docs.kentico.com/k9/e-commerce-features/configuring-your-store/configuring-product-pages/configuring-product-listings-with-filtering

I changed the Smart search filter properties like this:

               Values:  SKUEnabled DESC, (int)SKUAvailableItems DESC, SKUName;;Product name
                        SKUEnabled DESC, (int)SKUAvailableItems DESC, SKUPrice ASC;;Price ascending
                        SKUEnabled DESC, (int)SKUAvailableItems DESC, SKUPrice DESC;;Price descending

        Filter clause:  None

Filter is conditional:  No (cleared)

but if SKUAvailableItems field has different values the sort result wouldn't be correct.

How can I solve this problem?

Recent Answers


Trevor Fayas answered on December 29, 2017 20:10

You may need to look at lucene syntax up this doesn't work... But if will take SQL, do this

Case when SKUAvailableItems <1 then 0 else 1 end asc

This will give a 0 when 0 or less, 1 else.

0 votesVote for this answer Mark as a Correct answer

Iman Emran answered on December 29, 2017 20:54

Hello Trevor,

In Smart search filter, it is not possible use SQL query for sort search results!

Please give me a real solution for this problem.

Thanks

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on December 29, 2017 21:08

Sadly i don't see much for lucene syntax to do what you are looking to do...one possible work around is to have 2 Smart Search Results, one (top one) with available items, the other that shows not available items.

Sorry i don't have much more time to dive deeper into it, it's a work around for now at least.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.