Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[Contribution] Product Sort Order


Mark Russell

Recommended Posts

I guess it is in index.php

 

somewhere in sthis section

 

    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') {
// BOF Product Sort	
	  $HTTP_GET_VARS['sort'] = 'products_sort_order';
         $listing_sql .= " order by p.products_sort_order asc";
// EOF Product Sort
         break;
       }
     }
   } else {
     $sort_col = substr($HTTP_GET_VARS['sort'], 0 , 1);
     $sort_order = substr($HTTP_GET_VARS['sort'], 1);

     switch ($column_list[$sort_col-1]) {
       case 'PRODUCT_LIST_MODEL':
         $listing_sql .= " order by p.products_model " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
       case 'PRODUCT_LIST_NAME':
         $listing_sql .= " order by pd.products_name " . ($sort_order == 'd' ? 'desc' : '');
         break;
       case 'PRODUCT_LIST_MANUFACTURER':
         $listing_sql .= " order by m.manufacturers_name " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
       case 'PRODUCT_LIST_QUANTITY':
         $listing_sql .= " order by p.products_quantity " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
       case 'PRODUCT_LIST_IMAGE':
         $listing_sql .= " order by pd.products_name";
         break;
       case 'PRODUCT_LIST_WEIGHT':
         $listing_sql .= " order by p.products_weight " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
       case 'PRODUCT_LIST_PRICE':
         $listing_sql .= " order by final_price " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
// BOF Product Sort	
	case 'PRODUCT_SORT_ORDER':
         $listing_sql .= "p.products_sort_order " . ($sort_order == 'd' ? "desc" : '') . ", pd.products_name";
         break;
// EOF Product Sort

 

But i am not a programmer so if someone can help me out,

 

Greetings,

 

Jasper

Link to comment
Share on other sites

  • Replies 106
  • Created
  • Last Reply

Top Posters In This Topic

  • 4 months later...

Thanks for this contribution. It is working fine, except for an error in New Product or Edit Existing Product pages in admin. Each of these gives the error:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/glbc00/public_html/catalog/admin/includes/functions/database.php on line 99

Anybody able to shed light on this?

TIA.

Cheers,

Doug

Link to comment
Share on other sites

  • 11 months later...

Great contribution - I've installed version 1.4 and working great.

 

We have a lot of products which are used in more than one category and so we need to be able to order the position of a product within each category seperately. So I've stored the order ranking on the products_to_categories table and altered the index.php code accordingly.

 

I'm afraid our code is a bit too far off standard to release as a contribution, but if it helps anyone, just drop me a line,

 

cheers,

 

Dave

 

 

Hi Dave,

 

this is quite some time after you posted your comment, but maybe you are still somwhere around.

I would be greatefull if you could shine some light about how to achieve sorting in situation you described - some products being used in more than one category, and in need to being sorted differently for each of them.

 

 

Or maybe someone else might help with this...

Link to comment
Share on other sites

Ver 1.7.8.

And - there is another problem I run into.

When using the individual product sort page, I can choose whatever string (letters and digits) for sorting.

BUT when trying to use the SORT module/option from Administrator menu, I get an error

 

1054 - Unknown column 'TRAEG0B' in field list

UPDATE products SET products_sort_order = TRAEG0B WHERE products_id = 422

 

The sort_order is set for CHAR (also tried VARCHAR, TEXT) with same outcome. When using the digits only - it works OK. Where could be the problem and how to solve it ?

Link to comment
Share on other sites

Any chance that a 2.3.1-compatible version is on the horizon? This would solve a huge problem for me, but after using winmerge to compare, my guess is that this won't work with 2.3.1 in current form.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...