In Recent Magento 2.4.5 version, on category page out of stock products are not showing, Even magento setting changed in following admin section.
Admin -> stores -> config -> catalog -> inventory -> Display out of stock products => Yes
So to fix this issue you need to update in vendor file with following changes.
vendor/magento/module-elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php
Just change apply function like 2.4.4
public function apply()
{
if (empty($this->searchResult->getItems())) {
$this->collection->getSelect()->where('NULL');
return;
}
//$ids = $this->getProductIdsBySaleability();
//if (count($ids) == 0) {
$items = $this->sliceItems($this->searchResult->getItems(), $this->size, $this->currentPage);
foreach ($items as $item) {
$ids[] = (int)$item->getId();
}
//}
$orderList = implode(',', $ids);
$this->collection->getSelect()
->where('e.entity_id IN (?)', $ids)
->reset(\Magento\Framework\DB\Select::ORDER)
->order(new \Zend_Db_Expr("FIELD(e.entity_id,$orderList)"));
}
