Jump to content


Corporate Sponsors


Latest News: (loading..)

- - - - -

Product Sort Problem Solved


10 replies to this topic

#1 Dragonkeeper

  • Community Member
  • 42 posts
  • Real Name:Gary

Posted 18 October 2006, 03:51

For several weeks I had been pulling my hair out trying to solve a problem I was having with my
site not sorting correctly. I had seen many other stores that did not seem to have this problem. I
wanted my site to sort products based on the Product Name but, for some reason, it was sorting
based on the date I was entering products into the store. We thought the problem might be
attributed to a contribution we added someplace. But, my smartie web designer discovered that
since I had disabled displaying the Product Name in Admin (I only wanted to use this field for
sorting and not for displaying) osc disregarded the fact that I was using this field altogether so
not sort was performed. Once the field name was changed in the code, the sort works. So, the
tip here is if the disable the Product Name in your Admin, you will lose osc's default sort. At least,
that's what it seems to me.

#2 kerell78us

  • Community Member
  • 2 posts
  • Real Name:Kerwin Ellis

Posted 30 May 2007, 21:17

View PostDragonkeeper, on Oct 18 2006, 03:51 AM, said:

For several weeks I had been pulling my hair out trying to solve a problem I was having with my
site not sorting correctly. I had seen many other stores that did not seem to have this problem. I
wanted my site to sort products based on the Product Name but, for some reason, it was sorting
based on the date I was entering products into the store. We thought the problem might be
attributed to a contribution we added someplace. But, my smartie web designer discovered that
since I had disabled displaying the Product Name in Admin (I only wanted to use this field for
sorting and not for displaying) osc disregarded the fact that I was using this field altogether so
not sort was performed. Once the field name was changed in the code, the sort works. So, the
tip here is if the disable the Product Name in your Admin, you will lose osc's default sort. At least,
that's what it seems to me.


Hey Dragonkeeper,
For months I have been struggling to sort my products by the date they were entered, without any success. Then I stumbled upon your post, would u be so kind to share what exactly was done to have your products sorted by date

#3 enigma1

  • Community Member
  • 8,206 posts
  • Real Name:Mark Samios

Posted 31 May 2007, 00:31

in your catalog\index.php you change this code:

// show the products of a specified manufacturer
	if (isset($HTTP_GET_VARS['manufacturers_id'])) {
	  if (isset($HTTP_GET_VARS['filter_id']) && tep_not_null($HTTP_GET_VARS['filter_id'])) {
// We are asked to show only a specific category
		$listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$HTTP_GET_VARS['filter_id'] . "'";
	  } else {
// We show them all
		$listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m where p.products_status = '1' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'";
	  }
	} else {
// show the products in a given categorie
	  if (isset($HTTP_GET_VARS['filter_id']) && tep_not_null($HTTP_GET_VARS['filter_id'])) {
// We are asked to show only specific catgeory
		$listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['filter_id'] . "' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "'";
	  } else {
// We show them all
		$listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "'";
	  }
	}

	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;
		}
	  }
	} else {

to this:
// show the products of a specified manufacturer
	if (isset($HTTP_GET_VARS['manufacturers_id'])) {
	  if (isset($HTTP_GET_VARS['filter_id']) && tep_not_null($HTTP_GET_VARS['filter_id'])) {
// We are asked to show only a specific category
		$listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_date_added, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$HTTP_GET_VARS['filter_id'] . "'";
	  } else {
// We show them all
		$listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_date_added, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m where p.products_status = '1' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'";
	  }
	} else {
// show the products in a given categorie
	  if (isset($HTTP_GET_VARS['filter_id']) && tep_not_null($HTTP_GET_VARS['filter_id'])) {
// We are asked to show only specific catgeory
		$listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_date_added, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['filter_id'] . "' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "'";
	  } else {
// We show them all
		$listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_date_added, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "'";
	  }
	}

	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 p.products_date_added";
		  break;
		}
	  }
	} else {

so the default sorting is by products_date_added.

Edited by enigma1, 31 May 2007, 00:32.


#4 holwerda

  • Community Member
  • 3 posts
  • Real Name:ellen

Posted 22 June 2007, 16:31

Hi,
I've changed the sort order to

"order by p.products_id asc" so the latest productID (last entered prodcut) comes first.

This is ok on the first page, but if i click to go to page 2 (of three, there are a lot of products and not all displayed on one page) it goes back to sorting ASC again???

any idea where i change that so it does not go back to default sorting?

#5 LarryMac

  • Community Member
  • 14 posts
  • Real Name:Larry

Posted 26 January 2008, 19:54

View Postholwerda, on Jun 22 2007, 04:31 PM, said:

Hi,
I've changed the sort order to

"order by p.products_id asc" so the latest productID (last entered prodcut) comes first.

This is ok on the first page, but if i click to go to page 2 (of three, there are a lot of products and not all displayed on one page) it goes back to sorting ASC again???

any idea where i change that so it does not go back to default sorting?

Has anybody else out there cracked this? I'm having the same problem.

#6 edschaum

  • Community Member
  • 140 posts
  • Real Name:Ed

Posted 28 January 2008, 02:41

I did this on my site a long time ago. I don't remember if there are more changes, but here are the 2 I remember:

In my code I made the following changes:

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

//          $listing_sql .= " order by p.products_price";
          $listing_sql .= " order by p.products_id desc";

Since the new code is differerent, maybe try this:

  $HTTP_GET_VARS['sort'] = 'a';
$listing_sql .= " order by p.products_id desc";

If that doesn't do it, I'll try to find the other changes I made. I also seem to remember that this is a shortcut to doing it right, and that it's hard to get back to this sort after clicking any of the re-sortable headings.

Please back up before making any changes.

Ed

Edited by edschaum, 28 January 2008, 02:43.


#7 LarryMac

  • Community Member
  • 14 posts
  • Real Name:Larry

Posted 21 February 2008, 05:25

It looks like that did it! Thyanks a lot!

#8 bigbuba0

  • Community Member
  • 19 posts
  • Real Name:brad

Posted 10 March 2008, 01:08

View Postedschaum, on Jan 27 2008, 10:41 PM, said:

I did this on my site a long time ago. I don't remember if there are more changes, but here are the 2 I remember:

In my code I made the following changes:

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

//          $listing_sql .= " order by p.products_price";
          $listing_sql .= " order by p.products_id desc";

Since the new code is differerent, maybe try this:

  $HTTP_GET_VARS['sort'] = 'a';
$listing_sql .= " order by p.products_id desc";

If that doesn't do it, I'll try to find the other changes I made. I also seem to remember that this is a shortcut to doing it right, and that it's hard to get back to this sort after clicking any of the re-sortable headings.

Please back up before making any changes.

Ed

I used this to change the sorting of my products by price and it worked great, thanks!

#9 designcraft

  • Community Member
  • 81 posts
  • Real Name:Lindsay
  • Gender:Female

Posted 21 May 2008, 20:25

I have followed everything that the code said and mine just doesn't do anything. I have 5 products. 2 gift certificates and 3 sets of boxed chocolates. This is the order.
gift certificate - $9.25, gift certificate - $14.50, 2-Piece Seed Box - $4.95, 5-Piece Box - $9.25, 8-Piece Box - $14.50. The gift certificates don't have images so they're blank for the moment. I have my products not listed as categories just products. I even looked in mySQL to see if the sort orders matched what I have but I'm not sure what I looking for or how to change things. If anyone can help that would so great. Thanks!

#10 NEMROD34

  • Community Member
  • 42 posts
  • Real Name:NEMROD34

Posted 05 May 2011, 10:48

Hello i use sql with contrib:
ALTER TABLE products ADD `products_sort_order` INT(3);

INSERT INTO configuration (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES (263, 'Display Product Sort Order', 'PRODUCT_SORT_ORDER', '0', 'Do you want to display the Product Sort Order column?', 8, 29, '', '', NULL, NULL);

But:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by p.products_sort_order asc, pd.products_name limit 0, 20' at line 1

select p.products_image, pd.products_name, pd.products_info, p.products_quantity, p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, p.products_sold, p.products_sort_order, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from products_description pd, products p left join manufacturers m on p.manufacturers_id = m.manufacturers_id left join specials s on p.products_id = s.products_id, products_to_categories p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '1' and p2c.categories_id = '459' order by pd.products_name order by p.products_sort_order asc, pd.products_name limit 0, 20

#11 bktrain

  • Community Member
  • 2,093 posts
  • Real Name:Brian
  • Gender:Male
  • Location:On the brink of insanity

Posted 11 May 2011, 02:54

View PostNEMROD34, on 05 May 2011, 10:48, said:

order by pd.products_name order by p.products_sort_order asc, pd.products_name
You can only use order by once.

So the above becomes
order by p.products_sort_order asc, pd.products_name

Remember to backup database, files and pictures.

I reject your reality and substitute my own.
My mind not only wanders, it sometimes leaves completely.
The problem with the gene pool is that there is no lifeguard.
Everyone’s entitled to my opinion.


Links
Security
SSL Help
Basics for design
Basics for design V2.3+
How Do I ...?