tuyennn / magento2-outofstockatlast

Magento 2.4.x module Sort Out Of Stock Product At last the product list
GNU General Public License v3.0
55 stars 12 forks source link

Sort Products based on backorders #31

Closed noshadinfoicon closed 1 year ago

noshadinfoicon commented 1 year ago

I want to display all in-Stock products at the first and backorders product in the last of the page. for example- suppose we have total 5 products. 4 products are In-Stock, so these products will be display first, 5th products will be feature at last as the 5th products is out of stock and we have enabled back-order so it must display at last,

Please help How to accomplice it? Thanks in advance. any help regrading this would be appreciated.,

Note- I am not showing out of stock products on the webshop. I need to display only In Stock prodycts and the backorders products on website. and the backorders products should display in last on categories pages.

tuyennn commented 1 year ago

@noshadinfoicon Thanks for the request but unfortunately it turned out of scope Here we have several status for backorders

$value  = $product->getExtensionAttributes()->getStockItem()->getBackorders();
0 => No Backorders
1 => Allow Qty Below 0
2 => Allow Qty Below 0 and notify customers

Base on this I think you can define how a product is considered as backorder See https://github.com/tuyennn/magento2-outofstockatlast/blob/master/etc/di.xml https://github.com/tuyennn/magento2-outofstockatlast/blob/master/Model/Elasticsearch/Adapter/DataMapper/Stock.php then you can have the way to implement the index key: out_of_stock_at_last for you as preorder_at_last for example.