Jump to content

Sorting products on the home page


Peter.31

Recommended Posts

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...