I want to show Out of Stock items after in stock items. I found solution here, but its for Magento 1.8. I need same for Magento 2.
Asked
Active
Viewed 1,670 times
2 Answers
0
Please update your code to sort according to current direction (By ASC or By DESC)
$collection = $subject->getCollection();
$collection->getSelect()->joinLeft(
['_inventory_table' => 'cataloginventory_stock_item'],
"_inventory_table.product_id = e.entity_id", ['is_in_stock']
);
$collection->getSelect()->order(['is_in_stock ' . $currentDirection]);
Deepak
- 81
- 1
- 1
- 6
0
This is a module which does exactly this:
https://github.com/tuyennn/magento2-outofstockatlast
I tested in Magento 2.4.3-p2 and confirmed it working.
Akif
- 1,531
- 2
- 24
- 46