Peter.31 Posted December 3, 2022 Share Posted December 3, 2022 Hallo The home page displays various product categories, including discounted products and popular products. The problem is that usually out-of-stock products are displayed first, followed by products that are in stock. Eg: A total of 5 products are displayed and 4 products are sold out. Can anyone tell me how to sort the products so that the products that are in stock are displayed first and then the products that are out of stock? PrestaShop: v1.7.8.5 Link to comment Share on other sites More sharing options...
compsoul.dev Posted December 3, 2022 Share Posted December 3, 2022 Link to comment Share on other sites More sharing options...
juanrojas Posted December 4, 2022 Share Posted December 4, 2022 Hello, check the configuration you have in this route store parameters > product configuration > pagination > order products Link to comment Share on other sites More sharing options...
Peter.31 Posted December 4, 2022 Author Share Posted December 4, 2022 4 minutes ago, juanrojas said: Hello, check the configuration you have in this route store parameters > product configuration > pagination > order products I already checked that. This setting is only for categories, not the home page. Link to comment Share on other sites More sharing options...
juanrojas Posted December 4, 2022 Share Posted December 4, 2022 Do you use the default prestashop theme? Link to comment Share on other sites More sharing options...
Peter.31 Posted December 4, 2022 Author Share Posted December 4, 2022 Just now, juanrojas said: Do you use the default prestashop theme? No. Link to comment Share on other sites More sharing options...
Peter.31 Posted December 4, 2022 Author Share Posted December 4, 2022 This helped me. I made the change in the .php file. This code: $query->setSortOrder(new SortOrder('product', 'position', 'asc')); I have to replace with this code: $query->setSortOrder(new SortOrder('product','quantity','DESC')); Now I would need random products to be displayed, but only those that are in stock. Link to comment Share on other sites More sharing options...
juanrojas Posted December 4, 2022 Share Posted December 4, 2022 mmm ok, and can you know which one? Link to comment Share on other sites More sharing options...
Peter.31 Posted December 4, 2022 Author Share Posted December 4, 2022 12 minutes ago, juanrojas said: mmm ok, and can you know which one? In the module's main file. For example: Module: "Products in the same category" in the file ps_categoryproducts.php. line: 288 This code: $query->setSortOrder(SortOrder::random()); Change to this: $query->setSortOrder(new SortOrder('product','quantity','DESC')); 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