Juanaco Posted July 28, 2022 Share Posted July 28, 2022 Hi there, we want to change the order of the products in each section, we want to put the products out of stock at the end of the list in each page in our website, any tricks to make it? Thanks Link to comment Share on other sites More sharing options...
lordignus Posted July 28, 2022 Share Posted July 28, 2022 Better to do this with an override instead of modifying the core class, but for the sake of a short answer... in classes/Category.php, in the getProducts function, look for this line: $sql .= ' ORDER BY ' . (!empty($orderByPrefix) ? $orderByPrefix . '.' : '') . '`' . bqSQL($orderBy) . '` ' . pSQL($orderWay) . ' LIMIT ' . (((int) $pageNumber - 1) * (int) $productPerPage) . ',' . (int) $productPerPage; and replace it with this one: $sql .= ' ORDER BY stock.quantity = 0 ASC,' . (!empty($orderByPrefix) ? $orderByPrefix . '.' : '') . '`' . bqSQL($orderBy) . '` ' . pSQL($orderWay) . ' LIMIT ' . (((int) $pageNumber - 1) * (int) $productPerPage) . ',' . (int) $productPerPage; That's in 1.7.8.0, so will depend on your version but the concept is the same, we're just adding stock.quantity = 0 ASC into the ORDER BY clause in the sql query that fetches category products. 2 Link to comment Share on other sites More sharing options...
Ali Samie Posted July 29, 2022 Share Posted July 29, 2022 I found this, Although this is not practical, becasue it sorts based on quantity, and as a shop owner, they need only out of stock at the end of the list Link to comment Share on other sites More sharing options...
Ali Samie Posted July 29, 2022 Share Posted July 29, 2022 I think it is better to be two queries. One to get only available products by default order One to get out of stock products. and then put the result together Link to comment Share on other sites More sharing options...
Rybaris Posted July 22 Share Posted July 22 If anyone will need to solve this, especially for category pages, in Prestashop 1. 7. 8. solution from @lordignus works for me. You can also do it with ps_faceted_search module from Prestashop which is free. There is toggle button which enable you to put all out-of-stock products at the end of product list. I coded mine solution at first, but my overrides did not work. Then I tried lordingus solution and it did not work too. Then I found that there is a module which prevents some method from Category.php to be even called. When I disabled the module, both mine and lordingus worked. His is more elegant so I recommend his solution or already done module. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now