0

We have created a category page and assigned some products to that category page.

We have also assigned some out-of-stock products.

But when we sort products by price the out-of-stock products show at end of the list.

How can we show the out-of-stock product in the proper position based on the sort order?

enter image description here

2
  • The same issue I am facing, if you get answer please let me know ?
    – Dotsquares
    Commented Jan 19, 2023 at 12:36
  • @Dotsquares Yes, I have found the issue, Check my answer. Commented Feb 25, 2023 at 7:23

1 Answer 1

1

I just found this issue, There is a default is_salable sort order added in elasticsearch that's why out-of-stock products showing at end of the listing.

You can able to remove that sort order by overriding the below file and removing line #213.

vendor/magento/module-elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php

On line #213 the below code was added in elasticsearch

$sortOrders = array_merge(['is_salable' => \Magento\Framework\DB\Select::SQL_DESC], $sortOrders);

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.