Jump to content

Sorting in a different way


Recommended Posts

Hi All,

 

I would like to change a bit the way products being presented.

I need two level of sorting:

1. same as we have today - user choose it and default by order or date...

2. products with quantity=0 (not in stock) will always show last.

 

Is it possible to do such sorting?

 

thanks,

Link to comment
Share on other sites

Ok, found it myself.

Just added the following code into classes/Search.php at line 269

replace this:

 

               WHERE p.`id_product` '.$productPool.'               '.($orderBy ? 'ORDER BY  '.$orderBy : '').($orderWay ? ' '.$orderWay : '').'               LIMIT '.(int)(($pageNumber - 1) * $pageSize).','.(int)$pageSize;

 

with :

 

		    WHERE p.`id_product` '.$productPool.'		    '.'ORDER BY CASE p.`quantity` WHEN 0 THEN p.`quantity` END ASC , CASE p.`quantity` WHEN 80 THEN p.`'.$orderBy.'` ELSE p.`'.$orderBy.'` END '.$orderWay.' '.'		    LIMIT '.(int)(($pageNumber - 1) * $pageSize).','.(int)$pageSize;

 

 

One note - From some reason it doesnt work when ordering by name, so i just removed that option (works for me).

Also, This affect only on searches, but not when going to a category (and usually there you would like to keep the original ordering).

 

In case you know how to set the same in categories, please let me know.

 

Thanks

Edited by shimony (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

Hi

 

I finally found the location where to change the sorting in categories.

Line 537 in Classes/category.php

 

The original line to replace is

$sql .= ' ORDER BY '.(isset($orderByPrefix) ? $orderByPrefix.'.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).'

 

But i am not about the line that i need to put instead (as to whitelighter's suggestion) since the syntax here is different.

 

Please help

Link to comment
Share on other sites

It works with this line:

$sql .= ' ORDER BY p.`quantity`>0 DESC,'.(isset($orderByPrefix) ? $orderByPrefix.'.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay);

 

But, the only problem now is when i have in same page products in stock and out of stock - in this case the order is not correct - it goes by the selected order (price for example).

Edited by shimony (see edit history)
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...