Jump to content

Sort products by 'id_product'


Solaris

Recommended Posts

I would like to order my products (in every category) by the product id (id_product).

 

Could anyone point me to the right file? I have tried to add the following to product-sort.tpl:

 

 

<option value="id_product:asc" {if $orderby eq 'id_product' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Product ID: ASC'}</option>

 

But that did only show the option in the front end, but it doesn't sort when selected.

 

- How can I change the above code so it works?

- How can I modify the shop so I can set the default sort order in the backend?

- If none of the above works, can I "dirty-hack" a SQL query so it order by 'id_product' ?

 

Thanks a lot for your inputs!

Link to comment
Share on other sites

You need to add an extra item in Tools.php > getProductsOrder(). For some reason, they missed out id_product in the array. Just change:

 

$list = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity');

 

to the following:

 

$list = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity', 7=>'id_product');

 

Your extra option button would be something like:

 

<option value="{$link->addSortDetails($request, 'id_product', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'id_product' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Product ID: low to high'}</option>

Link to comment
Share on other sites

Thank you both VERY much for your replies!

 

I cannot get it to work unfortunately. I have inserted the code into the two pages (Tools.php and product_sort.tpl), and the sort order can now be selected. However it doesn't sort.

 

So I made it display the value of the two sort order variables ("",""), which switch to Name,desc or _asc when I select to order by product ID.

 

Could it be there's a problem with Smarty's Sort feature and the field "id_product" ? I see that the Front Controller gives the sort command to Smarty using public function productSort().

 

Or doesn't PS know about the 'id_product'? When I use the URL that is being returned by the addSortDetails function, it doesnt sort either (http://www.tomandi.ch/2013/index.php?id_category=3&controller=category&id_lang=2&id_lang=2&orderby=id_product&orderway=desc)

 

So if anyone is _still_ willing to help, it would be much appreciated. Thanks!

Link to comment
Share on other sites

Or doesn't PS know about the 'id_product'? When I use the URL that is being returned by the addSortDetails function, it doesnt sort either (http://www.tomandi.c...t&orderway=desc)

 

It looks like it's working ok for descending but not ascending. What is the code you pasted in product_sort.tpl for the ascending option? It should be:

 

<option value="{$link->addSortDetails($request, 'id_product', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'id_product' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Product ID: low to high'}</option>

<option value="{$link->addSortDetails($request, 'id_product', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'id_product' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='Product ID: high to low'}</option>

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

  • 6 months later...
  • 1 year later...

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