Jump to content

[SOLVED] Help for double order list


ReactionCode

Recommended Posts

I'm Working whith Prestashop 1.5.6.2

And I'm trying to do an override, to sort by default the product list in a particular way.

I want to sort by manufacturer default (which have already enabled in the settings) and, in the order by manufacturer, we have to sort by product names between manufacturers instead of by ID.

To do this I made ​​an override of the class category.php over "getProducts" function.

We have the following code at line 589 of the original class.

elseif ($order_by == 'manufacturer')
{
 $order_by_prefix = 'm';
 $order_by = 'name';
 //ADDED ADITIONAL VALUES FOR SORT BY NAME IN MANUFACTURER ORDER CASE
 $order_by_prefix_special = 'pl';
 $order_by_special = 'name';
}

Then we have to edit the "ORDER BY" about line 658 of the original Class.

else
 $sql .= ' ORDER BY '.(isset($order_by_prefix) ? $order_by_prefix.'.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way).'
 LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n;

I tried with direct query and works perfectly.

else            
 $sql .= ' ORDER BY m.'.$order_by.' '.$order_way.', pl.name '.$order_way
 .' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n;

But when I insert this code don't work.

else
 $sql .= ' ORDER BY '
 .(isset($order_by_prefix) ? $order_by_prefix.'.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way)
 .(isset($order_by_prefix_special) ? ', '.$order_by_prefix_special.'.`'.pSQL($order_by_special).'` '.pSQL($order_way) : '')
 .' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n;

Maybe I have some to fix or I have to do something more? Yes!!!

 

-------------------------------------------------------------------------------

 

The code was not working because there is a bug in prestashop.

The line with

 

elseif ($ order_by == 'manufacturer')

must be replaced by

elseif ($ order_by == 'manufacturer_name')
Edited by javsmile (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...