Display on stock product first

Hi,
I have used this post to displayin stock product variants first, and it’s works great :

But now i’m wondering if i can sort in my products listing, the products in-stock first by default.

I tried adding the sort filter in the “product listing” template, but it does not work.
Has anyone ever done that?

Regards,

Damien

Hi Damien,

This could be done using the product_priority field, or the Priority field in PAM if you wanted to manually sort by in-stock.

The essential idea is to set the field to ‘1’ if the item is in stock, or 0 if it’s not. Items with a higher priority number rank higher on the listing pages.

Given that you’re using matrix items, we first need to determine how it should behave with those. Do you want it to count a matrix as “in stock” if any of its child items is in stock?

Regards,
Donogh

Hi @donogh

Thanks for the reply. It’s works great with simple products or products with all matrix in stock with NSync condition.

Now i Would like determine if any of my matrix are in stock to put “1” in product_priority field.

Regards,

Damien

Hi Damien,

we have a solution for you but need to do few tests to check if it’s working correctly. I will get back to you asap. Please bear with me.

Regards,
Sebastian

1 Like

Hi Damien,

This should work fine as a product_priority mapping:

(CASE WHEN (quantity-quantitycommitted) > 0 THEN 1 ELSE 0 END)

You’ll need to ensure ‘Sort my search results by highest priority first’ is enabled (under All Config Options).

Regards,
Donogh