I am using Magento Enterprise 2.2.10 and I am wanting to show out of stock products and want to have show at the end of the category collection. I thought I could use the event:
catalog_product_collection_load_before but that does not seem to exist in Magento 2 but this event does work:
If I use the
catalog_product_collection_load_after event I can add the fields to the collection ordering but they get added the order default category ordering and does not accomplish what I want to do.
Any ideas how I can go ordering products like this since that event does not fire?
Is there a way to replace the order by query instead of add to it?
Using the event catalog_product_collection_load_after I was able to modify the collection query to order the data the way I want but it does not have any affect on the display of the products in the category.
This is what I came up with which does generate the correct query but why does it not change the order of the product on the category?
$collection ->getSelect() ->joinLeft( array('_inventory_table' => $c "_inventory_table.product_id = array('is_in_stock') ) ->reset('order') ->order('is_in_stock DESC') ->order('cat_index_position ASC');