Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Sort by Price in Category listing


ghiggi

Recommended Posts

I am trying to figure out how I can set the default sort in the category listings from the product name to the product price.

 

I want my products to be listed in order from the lowest price to the highest price.

 

I know you can click on the column heading, but can I change it to default to the price column when the page first loads?

 

 

thanks,

ghiggi

Link to comment
Share on other sites

It's been a while since I changed this, so bear with me here. In index.php find this code (near line 191):

    if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
     for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
       if ($column_list[$i] == 'PRODUCT_LIST_NAME') {
         $HTTP_GET_VARS['sort'] = $i+1 . 'a';
         $listing_sql .= " order by pd.products_name";

and change that last line to:

          $listing_sql .= " order by p.products_price";

If that doesn't work properly, try:

          $listing_sql .= " order by p.products_price asc";

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

ok, I got it.

 

You were on the right track.

 

I needed to change:

   if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
    for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
      if ($column_list[$i] == 'PRODUCT_LIST_NAME') {
        $HTTP_GET_VARS['sort'] = $i+1 . 'a';
        $listing_sql .= " order by pd.products_name";

 

to:

   if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
    for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
      if ($column_list[$i] == 'PRODUCT_LIST_PRICE') {
        $HTTP_GET_VARS['sort'] = $i+1 . 'a';
        $listing_sql .= " order by final_price";

 

 

Now it's working like I wanted it.

 

Thanks for the help,

ghiggi

Link to comment
Share on other sites

  • 9 months later...

I figured it out. For future reference you simply place "desc" after "order by price list. The code reads...

 

 if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
   for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
     if ($column_list[$i] == 'PRODUCT_LIST_PRICE') {
       $HTTP_GET_VARS['sort'] = $i+1 . 'a';
       $listing_sql .= " order by final_price desc";

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...