Portal | Homepage | Blog

Display on stock product first


#1

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


#2

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


#3

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


#4

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


#5

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