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

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