OSCOMMERCE SUPPORT CALL 702-453-3332

 

Help - Search - Members - Calendar
Full Version: Sort order by model number in product listing
osCommerce Community Support Forums > osCommerce Online Merchant v2.x > Tips and Tricks
minghoo
Hi guys,

i just figured out how to sort product by model number.

i searched this forum a whole afternoon, didn't get what i want.

index.php find code:

CODE
   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;
       }
     }



you need to change three places;
1. change $i+1 to $i-1,
2. change 'PRODUCT_LIST_NAME' to 'PRODUCT_LIST_MODEL',
3. change order by pd.products_name to order by p.products_model

so the whole code should be:

CODE
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_MODEL') {
         $HTTP_GET_VARS['sort'] = $i-1 . 'a';
         $listing_sql .= " order by p.products_model desc";
         break;
       }
     }


if you only change 2 and 3 place, it won't work on 2 or 3 pages.

If anyone has problem, please just post.
Irin
QUOTE (minghoo @ Aug 22 2005, 09:35 PM)
Hi guys,

i just figured out how to sort product by model number.

i searched this forum a whole afternoon, didn't get what i want.

index.php find code:

CODE
   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;
       }
     }

you need to change three places;
1. change $i+1 to $i-1,
2. change 'PRODUCT_LIST_NAME' to 'PRODUCT_LIST_MODEL',
3. change order by pd.products_name to order by p.products_model

so the whole code should be:

CODE
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_MODEL') {
         $HTTP_GET_VARS['sort'] = $i-1 . 'a';
         $listing_sql .= " order by p.products_model desc";
         break;
       }
     }


if you only change 2 and 3 place, it won't work on 2 or 3 pages.

If anyone has problem, please just post.
*

Hello minghoo,

I did exactly as you say, changed code in all 3 places, but I still get my products listed by products_name on index.php. Did I miss anything?

Thanks,
Irina.
Danbob
The code as shown in the body of the message is correct, the code in the "code" box is incorrrect -- change #3 to p.products_model, NOT p.products_model desc
DAN



[quote=Irin,Aug 25 2005, 10:16 PM]
Hello minghoo,

I did exactly as you say, changed code in all 3 places, but I still get my products listed by products_name on index.php. Did I miss anything?

Thanks,
Irina.
Irin
[quote=Danbob,Sep 5 2005, 11:41 AM]
The code as shown in the body of the message is correct, the code in the "code" box is incorrrect -- change #3 to p.products_model, NOT p.products_model desc
DAN
[quote=Irin,Aug 25 2005, 10:16 PM]
Hello minghoo,

I did exactly as you say, changed code in all 3 places, but I still get my products listed by products_name on index.php. Did I miss anything?

Thanks,
Irina.
*

[/quote]
Unfortunately it doesn't work with neither p.products_model nor p.products_model desc. I tried both of them but nothing changed.

Any other ideas?
Thanks.
H2B2
QUOTE (Irin @ Sep 5 2005, 07:25 PM) *
Any other ideas?

You could take a look a this contribution: Default Search options in categories and Advanced Search. It requires 2 minor changes in index.php and advanced_search_result.php
sporkalicious
am having trouble with this modification not properly organizing products on pages of products other than page 1
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.