I want to display In stock products first and out of stock at end of the listing.
I have used below code in
$collection->joinField('stk', 'cataloginventory_stock_item', 'is_in_stock', 'product_id=entity_id', 'qty>=0', 'left')->setOrder('stk','desc');
But I am getting the error:
1 exception(s): Exception #0 (Magento\Framework\Exception\LocalizedException): A joined field with this alias is already declared.
How can I solve this issue?