Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Change default sort on product page?


Bryan

Recommended Posts

I'd like to list my products from the highest price on down on the product display pages of each category. I see from the query string that 'sort=3d' is appended. Where can I add that so that the categories all have that appended as a default?

Link to comment
Share on other sites

Well, you know you can click the titles to change the sort order to which ever order you want on the product listing.

 

What you need to do is change the default order that is being used.

 

Something like this in the start of default.php works:

 

if ( !$HTTP_GET_VARS['sort'] ) {

 $HTTP_GET_VARS['sort'] = '4d';

 $sort_order='d';

}

Link to comment
Share on other sites

I just took this bit of code in default.php starting on line 210:

if ( (!$HTTP_GET_VARS['sort']) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'],0,1) > sizeof($column_list)) ) {

     for ($col=0; $col<sizeof($column_list); $col++) {

       if ($column_list[$col] == 'PRODUCT_LIST_NAME') {

         $HTTP_GET_VARS['sort'] = $col+1 . 'a';

         $listing_sql .= " order by pd.products_name";

         break;

 

and changed the fourth and sixth lines to what I want it to sort by. Price sort example below:

if ( (!$HTTP_GET_VARS['sort']) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'],0,1) > sizeof($column_list)) ) {

     for ($col=0; $col<sizeof($column_list); $col++) {

       if ($column_list[$col] == 'PRODUCT_LIST_PRICE') {

         $HTTP_GET_VARS['sort'] = $col+1 . 'a';

         $listing_sql .= " order by final_price";

         break;

Link to comment
Share on other sites

gevans, I did what you did but added a 'desc' in the query as I wanted the most expensive on down.

 

Now, while on that page the price column defaults to "Price +" which if you click on that it just shows the same page:) How can I get it so that is shows "Price -" and the link goes to 'a' and not 'd'? This way they can sort from least expensive to most expensive without having to click that link twice:)

Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...
Well, you know you can click the titles to change the sort order to which ever order you want on the product listing.

 

What you need to do is change the default order that is being used.

 

Something like this in the start of default.php works:

 

if ( !$HTTP_GET_VARS['sort'] ) {

 $HTTP_GET_VARS['sort'] = '4d';

 $sort_order='d';

}

 

Linda I tried this in my store as I want to sort everything by price descending but it seems to do nothing. Did something change in Nov 2.2 snapshot.

Link to comment
Share on other sites

Place an echo in your file for $HTTP_GET_VARS['sort'] and then click on the title of the method you want to use and see what the results are.

 

Mine was 4d your's could be 2d ... :shock:

Link to comment
Share on other sites

Anyone know of a way (or a contribution) to allow sorting of products similar to sorting of categories, where you could enter the sort order in the product description and sort them anyway you wish with number entries (e.g. 1, 2, 3, etc.)?

 

Seems like a pretty big hack.

 

Thanks,

 

Mark

Link to comment
Share on other sites

  • 3 weeks later...

Laura,

 

I was able to get the desired results by changing the code in default.php to:

 

if ( (!$HTTP_GET_VARS['sort']) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'],0,1) > sizeof($column_list)) ) {

     for ($col=0; $col<sizeof($column_list); $col++) {

       if ($column_list[$col] == 'PRODUCT_LIST_PRICE') {

         $HTTP_GET_VARS['sort'] = $col+1 . '3a';

         $listing_sql .= " order by final_price desc";

         break;

       }

     }

 

This now lists products from the highest price on down the sort column at the top will show Price- for those that want to reverse the sort and change the display to least expensive on down.

Link to comment
Share on other sites

Anyone know of a way (or a contribution) to allow sorting of products similar to sorting of categories, where you could enter the sort order in the product description and sort them anyway you wish with number entries (e.g. 1, 2, 3, etc.)?

 

Seems like a pretty big hack.

 

Thanks,

 

Mark

 

I asked the above about three weeks and since put together a contribution to do this. Anyone that is interested in having product sort capability similar to category sort, you can find the contribution here:

 

http://www.oscommerce.com/community/contributions,911

 

Mark

Link to comment
Share on other sites

I found Linda's example to be just the bit i needed as i also wanted to start from most expensive down to cheapest.

 

I found a slight snag...

 

When i clicked the "Next" button it altomaticly reverted back to cheapest first...

 

LOL, got a big ticking off from my client for that.

 

I noticed that the "next" button was creating an extra "3".

 

So "3d" would become "33d" on the "next" button click.

 

 

All I did was remove the "3" from the "3d" it worked fine. I am not sure where the "3" comes from but it worked for me.

 

My client is happy now and I am a happy bunny again.

Link to comment
Share on other sites

  • 2 months later...

(Been awhile since I posted in this thread), but I wanted to thank both Duncan & Bryan for the solution to the sort order. I needed both tips and they worked like a charm...Thank you!

 

Laura

Link to comment
Share on other sites

  • 9 months later...
  • 1 year later...
Hey there,

I've looked everywhere for the "default.php" file so that I can sort Most Expensive to Least Expensive and cannot find it :unsure: . Is there any chance someone could Post the path?

 

Thanks in advance,

BD

osC 2.2 m2

 

Like me (and others, you are now looking for "index.php"

Still trying (no luck) to creack this one for 2.2ms2 AND the price break contrib.

Any luck since this post?

damsbo

Link to comment
Share on other sites

Hey there,

I've looked everywhere for the "default.php" file so that I can sort Most Expensive to Least Expensive and cannot find it :unsure: . Is there any chance someone could Post the path?

 

Thanks in advance,

BD

osC 2.2 m2

Boulder et.al.

Got it!

In index.php find the following

 

if ($column_list[$i] == 'PRODUCT_LIST_NAME') {

$HTTP_GET_VARS['sort'] = $i+1 . 'a';

$listing_sql .= " order by pd.products_name";

 

 

I've changed in first line _NAME to _MODEL

and in third line pd.products_name to p.products_model

 

Wonder if this wouldnt work for PRICE too??

BACK-UP, then give it a try :-)

damsbo

Link to comment
Share on other sites

  • 5 weeks later...
In index.php find the following

 

        if ($column_list[$i] == 'PRODUCT_LIST_NAME') {

          $HTTP_GET_VARS['sort'] = $i+1 . 'a';

        $listing_sql .= " order by pd.products_name";

I've changed in first line _NAME to _MODEL

and in third line pd.products_name to p.products_model

 

I am trying to sort descending by product name and I have tried to chane the above 'a' to 'd', '2d' and '4d' but that doesn't change the sorting, it just changes the status of the little + or minus next to the product list title....it's like it thinks it is listing in desc now, and offers you to sort by asc, but it IS sorting in ASC anyway.

 

Can anyone suggest a solution?

Link to comment
Share on other sites

  • 3 weeks later...
I am trying to sort descending by product name and I have tried to chane the above 'a' to 'd', '2d' and '4d' but that doesn't change the sorting, it just changes the status of the little + or minus next to the product list title....it's like it thinks it is listing in desc now, and offers you to sort by asc, but it IS sorting in ASC anyway.

 

Can anyone suggest a solution?

 

I changed this code in catalog/index.php (line 191 on mine)

 

 

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";

break;

 

 

to this

 

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 final_price desc";

break;

 

if you want lowest price first, then dont use 'desc'

 

it worked for me :D

 

:thumbsup:

 

If you want product name desc then just adding 'desc' should work for you on the line

$listing_sql .= " order by pd.products_name";

 

change it to

 

$listing_sql .= " order by pd.products_name desc";

 

not tested tho' I wanted it by price.. and it worked...

Link to comment
Share on other sites

  • 1 month later...

Hi,

 

I tried this to sort by model descending, using

 

$listing_sql .= " order by p.products_model desc";

 

which works fine, except the product name column heading still has the little + next to it. How can I set this properly?

 

thanks

 

:blink:

 

I changed this code in catalog/index.php (line 191 on mine)

    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";

          break;

to this

 

    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 final_price desc";

          break;

 

if you want lowest price first, then dont use 'desc'

 

it worked for me :D

 

:thumbsup:

 

If you want product name desc then just adding 'desc' should work for you on the line

$listing_sql .= " order by pd.products_name";

 

change it to

 

$listing_sql .= " order by pd.products_name desc";

 

not tested tho' I wanted it by price.. and it worked...

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...