Jump to content

Put products out of stock at the end of the list


Juanaco

Recommended Posts

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.

  • Like 2
Link to comment
Share on other sites

  • 2 years later...

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

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...