2

I need to show out of stock products on at the end of listings using ElasticSearch on Magento 2.4.*.

I was able to order without ElasticSearch, but once I enable ElasticSearch it won't work.

It feels like something applies order after the collection orders are set.

Just to let you know:

  • This cannot be done using an attribute and enabling sorting because it will be added to any frontend listing at the same time other order is applied;

Thanks!!!!

2
  • 1
    Was you able to solve it? I'm facing the same problem
    – jefferson
    Commented Oct 22, 2021 at 3:04
  • Hello @jefferson ! Unfortunately I couldn't find a solution yet. Commented Oct 22, 2021 at 23:11

1 Answer 1

0

It's happening because you indeed need to change the collection sorting from the ElasticSearch module, in case you use ElasticSuite, there's a customization to do too.

You can use or refer to this module below where you see an around plugin created to "flag" those products during the Magento\Elasticsearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplier load.

https://github.com/tuyennn/magento2-outofstockatlast/blob/master/Plugin/Model/ResourceModel/Fulltext/Collection/SearchResultApplierPlugin.php

1
  • Cool, thank you very much for your response, I will test that. Commented Mar 26, 2023 at 22:57

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.