Jump to content



Photo
* * * * * 2 votes

Product listing sort order


This topic has been archived. This means that you cannot reply to this topic.
177 replies to this topic

#41   Snowy_River

Snowy_River
  • Members
  • 23 posts

Posted 30 November 2008 - 19:21

This should end with order by p.products_quantity which it does'nt thats why you don`t get the order you want.

I just reliased why, perhaps I should have realised before but I`ve got lots on right now so cant think of everything.

I bet you havent included products quantity in the column list, that means the line:

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

will always fail, so

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

never gets added

so instead of:

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_QUANTITY') {
		  $HTTP_GET_VARS['sort'] = $i+1 . 'a';
		  $listing_sql .= " order by p.products_quantity";
		  break;
		}
	  }
	} else {
put:

if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('^[1-8][ad]$', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
		  $HTTP_GET_VARS['sort'] = 0 . 'a';
		  $listing_sql .= " order by p.products_quantity";
	 } else {


Hi Sam,

I was having a similar problem to what WoodsWalker was describing. I decided to add four characters to the beginning of each product's model number. The first was a letter to signify the general category of the item, the second and third were the sorting number, and the forth was a hyphen, to separate it from the rest of the model number, for example: A04-######## would be the forth item in the Accessories category. This seems to work great, except for a few products that wouldn't sort in the right order.

So, finding your post, I tried removing the "if ($column_list[$i] ==..." code. Everything sorted fine, then, but my formating vanished. Suddenly, my background wasn't there, much (if not all) of the text formating was gone. Any clues?

For full details:

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


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



Thanks!

Edited by Snowy_River, 30 November 2008 - 19:24.


#42   WoodsWalker

WoodsWalker
  • Members
  • 389 posts

Posted 30 November 2008 - 21:11

Hi Geoffrey!

I'd say, "so far, so good" with your ingenious scheme. The hard part was getting the product order to work. Now we just have to get your formatting back.

I had a similar occurance once when I was twiddling with column widths in shopping_cart.php. I finally got the columns to behave the way I wanted, but the page formatting suddenly went completely bazoo. I went back to my backup copy and tried to recreate the chain of events (had to do this several times).

Finally, I figured out what had happened. I work in Dreamweaver. When I save a page, it usually asks me if I want to "Update Links" - and I usually say no, because I do not know what that does. However, in this instance I had mistakenly said yes. I don't know why Dreamweaver does what it does, but it altered my stylesheet.css (adding an unwanted bit of code to TD.productListing-data).

When I corrected this (or I might have reloaded a backup of stylesheet.css), everything was fine.

I know there's only a chance that this will help you. Let us know how it goes.

~Wendy

#43   WoodsWalker

WoodsWalker
  • Members
  • 389 posts

Posted 30 November 2008 - 21:31

I just wanted to add that if the syntax is off in stylesheet.css by so much as a crumb, the whole stylesheet is non-functional. This is what happened in my case - Dreamweaver added something to stylesheet.css, but it didn't use the right syntax, which brought the whole thing down.

#44   Snowy_River

Snowy_River
  • Members
  • 23 posts

Posted 01 December 2008 - 00:56

Hello Wendy,

Thank you. Because of your comments, I went back and took a copy of the working file, made the edits again and uploaded it. Now I've got formatting and proper sorting. It's all wonderful! Clearly something similar must have happened where my editing program made a change that I didn't want it to. When I went back to the original file, it recovered from whatever the change was.

So, again, thank you!

Geoffrey.

Edited by Snowy_River, 01 December 2008 - 00:58.


#45   WoodsWalker

WoodsWalker
  • Members
  • 389 posts

Posted 01 December 2008 - 01:18

Great to know it's working! /smile.gif' class='bbc_emoticon' alt=':)' />

#46   studioimagen

studioimagen
  • Members
  • 55 posts

Posted 02 December 2008 - 04:20

All my products are named by number, i just want it to list by number and not alphabetically, how do i do that?

Photo 1
Photo 2
Photo 3


Instead of

Photo 1
Photo 10

THANK YOU!
Sincerely,

#47   spooks

spooks
  • Members
  • 7,017 posts

Posted 03 December 2008 - 00:32

More info needed, what have tried yourself?
Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#48   studioimagen

studioimagen
  • Members
  • 55 posts

Posted 03 December 2008 - 23:10

well this is the code i use for calling from a regular database i just dont know how i would change the store script as such: the ABS is what does it

$sql = "SELECT * from homes ORDER BY ABS(floorplan) ASC ";
Sincerely,

#49   spooks

spooks
  • Members
  • 7,017 posts

Posted 03 December 2008 - 23:22

You really dont like giving anything do you!!!

the best I can say from that limited info is:

instead of:

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_QUANTITY') {
		  $HTTP_GET_VARS['sort'] = $i+1 . 'a';
		  $listing_sql .= " order by p.products_quantity";
		  break;
		}
	  }
	} else {

put:

if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('^[1-8][ad]$', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
		  $HTTP_GET_VARS['sort'] = 0 . 'a';
		  $listing_sql .= " order by ABS(floorplan) ";
	 } else {
You'll have to work out the rest yourself, as you refuse to provide proper details.
Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#50   studioimagen

studioimagen
  • Members
  • 55 posts

Posted 04 December 2008 - 00:27

i really appreciate your response. Floorplan doesn't really apply here, i just dont know where to stick the ABS to the existing code

here is where i need it to list in numerical order
http://traciegrant.c...ex.php?cPath=21

Edited by studioimagen, 04 December 2008 - 00:38.

Sincerely,

#51   rexx

rexx
  • Members
  • 16 posts

Posted 04 December 2008 - 12:23

If I understand that question correctly, I have an old trick I use in numbering my pics, and that is to use 3 digits.

photo001
photo002
photo003
and so on, as you will be fine up to 1000 pics, and they will be sorted by your default sort of alphabetically.



All my products are named by number, i just want it to list by number and not alphabetically, how do i do that?

Photo 1
Photo 2
Photo 3


Instead of

Photo 1
Photo 10

THANK YOU!



#52   studioimagen

studioimagen
  • Members
  • 55 posts

Posted 10 December 2008 - 00:45

http://traciegrant.c...ex.php?cPath=21

I would like ALL the products to show on this page, not just 20 per page and you have to click next. and so on, is this obtainable, i have your contribution installed for "Product LIsting Enhancements"
Sincerely,

#53   spooks

spooks
  • Members
  • 7,017 posts

Posted 10 December 2008 - 10:25

Its set in in admin & detailed in that contrib!!!

Search Results.

/rolleyes.gif' class='bbc_emoticon' alt=':rolleyes:' />
Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#54   jasonabc

jasonabc
  • Members
  • 1,964 posts

Posted 24 December 2008 - 01:33

OOPS, did you spot the deliberate mistake? It should be:

Replace with:

if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('^[1-8][ad]$', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
		  $HTTP_GET_VARS['sort'] = 0 . 'd';
		  $listing_sql .=  " order by p.products_date_added DESC, pd.products_name";
	} else {

Thanks Spooks - *exactly* what I was looking for!! ;-)

#55   mycreativewishes

mycreativewishes
  • Members
  • 88 posts

Posted 01 January 2009 - 21:56

This question keeps coming up & people seem to have trouble finding the answer in the forums, so I'll put this here to make it easy.

The product list order is by name as default, that is hard coded within index.php so you must change that to alter.

The product list sort order also depends on what was clicked last, you may have noticed that annoying '+' by 'product name' in the list heading, thats supposed to tell you that clicking on that or 'product name' will change list order on product name, similarly clicking on any other heading will order list by that column.

The code that sets the default order starts aroun 200 of index.php

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 sort by something else you must change 2 lines to the appropriate item

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

change the PRODUCT_LIST_NAME to one of: PRODUCT_LIST_MODEL, PRODUCT_LIST_MANUFACTURER, PRODUCT_LIST_QUANTITY, PRODUCT_LIST_WEIGHT, PRODUCT_LIST_PRICE

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

change the pd.products_name to one of p.products_model, m.manufacturers_name, p.products_quantity, p.products_weight, final_price

If you wish to sort it reverse order you add DESC & change a to d to indicate order.

So if your wanting the default sort to be by price in descending order you would have:

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 . 'd';
$listing_sql .= " order by final_price desc";
break;


Please dont confuse this with sorting product atributes, thats another subject & there is a post in tips dealing with it.

Hope that makes things clear.

/smile.gif' class='bbc_emoticon' alt=':)' />


Maybe I am editing in the wrong lines, but I want the products to be listed in the order I upload them in the catagory. When I edit the lines from names to models, the names of the products disappear in the catagorie view. What can I do to fix this?

#56   spooks

spooks
  • Members
  • 7,017 posts

Posted 05 January 2009 - 20:44

Iether you are not editing the file as specified, or you have a TEMPLATE, all these tips apply to standard osC only
Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#57   spooks

spooks
  • Members
  • 7,017 posts

Posted 10 January 2009 - 22:41

Someone asked 'how to remove the headings':

in includes/modules/product_listing.php

find(68)

$list_box_contents[0][] = array('align' => $lc_align,
									'params' => 'class="productListing-heading"',
									'text' => '&nbsp;' . $lc_text . '&nbsp;');
replace with

/* $list_box_contents[0][] = array('align' => $lc_align,
									'params' => 'class="productListing-heading"',
									'text' => '&nbsp;' . $lc_text . '&nbsp;');  */


[/quote]
Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#58   alphawebs

alphawebs
  • Members
  • 13 posts

Posted 12 March 2009 - 16:07

It's a mystery to me why the sort order was ever set to product name.
On a production site with thousands of products, new products get entered daily and you'll want the newer products to display on the first page.


first off I changed the

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

commented out
$listing_sql .= " order by pd.products_name";
/*$listing_sql .= " order by pd.products_name";*/

and added
$listing_sql .= " order by pd.products_id desc";

under
case 'PRODUCT_LIST_NAME':

commented out
$listing_sql .= " order by pd.products_name " . ($sort_order == 'd' ? 'desc' : '');
/* $listing_sql .= " order by pd.products_name " . ($sort_order == 'd' ? 'desc' : '');*/

and added
$listing_sql .= " order by pd.products_id " . ($sort_order == 'd' ? 'desc' : '');

--------------
Now the newer products display first. This works with multiple column formats as well as single column formats.

#59   spooks

spooks
  • Members
  • 7,017 posts

Posted 12 March 2009 - 16:36

It's always diificult to suit everyone, I'm sure if the default was product_id many would still complain its not what they want.

As many have this issue what would have been better would be sort order selectable within admin.

A word of caution with your edits, they will only work as long as Product Name is in the display list, also would'nt setting by date added be more appropriate (I detailed how ealier in this thread).
Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#60   cesk

cesk
  • Members
  • 2 posts

Posted 12 March 2009 - 16:42

Does anyone know how and where to fix this problem I am having with the Sort Order?:

My pull down menu displays the following: "Product NameAPHA_ORDER" instead of just "Product Name".

And also the selector for "LIST_VIEW/THUMB_VIEW" is NOT displayed in a drop down button but just as a link.

I am using the following contributions: Additional Images v2.1.0, Product Listing Enhancements, Thumbnails & Manufacturer Headings V1.8, export_orders_to_csv_v22, PageHeaders_and_Subheaders and PageHeadersFix

On osCommerce v.2.2ms2 with MySQL 5.045.

Thank you!!

Edited by cesk, 12 March 2009 - 16:43.