Forums / General Questions / Product natural order

Product natural order

Locked

Views: 1,593

Results 1 to 11 of 11
This thread is locked. New replies are disabled.
26 Sep 2007, 6:28 AM
#1
densys avatar

densys

New Zenner

Join Date:
Sep 2007
Posts:
2
Plugin Contributions:
0

Product natural order

Hi there,

We have helped a client setup zen cart, all is ok except for the order of products.

The product names are numbered:
Product 1
Product 2
Product 3
etc

When viewing a category the order is not natural
eg 20 is before 3
Product 1
Product 2
Product 20
Product 3

I know padding the number with 0 in front will fix it, but i don't want to do this with all products already entered.

Is there a way to change this behaviour?

Thanks for your help

26 Sep 2007, 4:48 PM
#2
spbennett avatar

spbennett

Zen Follower

Join Date:
Feb 2007
Location:
Leicester UK
Posts:
230
Plugin Contributions:
0

Re: Product natural order

Last box on the page where you enter/edit Product Information is called "Sort Order:"

Give it a number relating the sort order you require.

26 Sep 2007, 5:22 PM
#3
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Product natural order

Product 1
Product 2
Product 20
Product 3

Please remember, SQL is comparing string to string, and it is doing that by comparing character by character: P= P, e = e, ....etc, then 2 < 3, so Product 20 is before Product 3. That make sense right?

I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

26 Sep 2007, 7:55 PM
#4
rstevenson avatar

rstevenson

Totally Zenned

Join Date:
Nov 2006
Location:
Dartmouth, NS Canada
Posts:
2,400
Plugin Contributions:
0

Re: Product natural order

Not wishing to be argumentative, but I would have to reply by saying (paraphrasing Mr. Spock) The needs of the user outweigh the needs of the programmer.

Users are humans and count like humans and sort like humans. So any list of numbers that comes out sorted programmatically as 1, 2, 20, 3, ... is flawed, whether or not it makes sense in programming terms.

It would be a simple matter to use a backend routine to pad out all numbers as they leave the database to some arbitrary length using zeros on the left, then sort them, then display the results without the padding. Human beans :P need never know this is happening. Why, after a half-century of programming, this is not standard is just one of those things best left unexamined.

:smartalec:

Rob

Breakfast: the most important donut of the day.

26 Sep 2007, 7:58 PM
#5
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Product natural order

Exactly what I'm doing. I name my products "BR001 blah blah", "BR002 blah blah".

I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

26 Sep 2007, 8:03 PM
#6
rstevenson avatar

rstevenson

Totally Zenned

Join Date:
Nov 2006
Location:
Dartmouth, NS Canada
Posts:
2,400
Plugin Contributions:
0

Re: Product natural order

Me too. But not everyone is as smart as we are. :laugh:

A note to the OP: Zen Cart doesn't mind if you use zeros to pad your numbers. My model numbers start with zeros where needed and they all come out fine in the wash. Unlike Excel, say, where they get stripped out by a program that insists it knows better than I what should be done.

Rob

Breakfast: the most important donut of the day.

26 Sep 2007, 8:05 PM
#7
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Product natural order

To dig in a bit, the models are stored as string, that's why you can pad all the 0 you want. If you use EasyPopulate and has Excel truncates all the leading 0, set the whole model column to text instead of number.

G'Luck

I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

26 Sep 2007, 8:13 PM
#8
rstevenson avatar

rstevenson

Totally Zenned

Join Date:
Nov 2006
Location:
Dartmouth, NS Canada
Posts:
2,400
Plugin Contributions:
0

Re: Product natural order

Yeah, I know. But Excel (to continue getting off topic) can be very stubborn. When I paste (or import) the whole EP file into Excel it strips out the zeros even if I preset the column to Text.

I recently tried to use Excel to graph 3 cols of data, all of which were numbers. I wanted the first col as the x-axis labels and the other 2 as lines on the chart. Even formatting the first col as Text didn't help. Excel still drew all 3 cols as lines. I finally added a letter to each value in the first col, created the chart, then took the letter out. That worked.

Rob

Breakfast: the most important donut of the day.

26 Sep 2007, 8:42 PM
#9
aginv avatar

aginv

New Zenner

Join Date:
Sep 2007
Posts:
5
Plugin Contributions:
0

Re: Product natural order

Speaking of the product "sort order:" field, does anyone know the name of the directory and file that does the SQL read of the product info before displaying it in the cart? I want to modify it so it reads it in "sort order:" order, or at least add some code so the products are sorted using that field. There are so many directories and progarm files it could take me all year to find it. Plus my PHP skills aren't very good.

I had a guy modify the cart interface so it's possible that ZenCart would have used the "sort order:" field initially, but it's not now. The products come out in the cart in what seems to me to be random order. But if I can find the file that does the SQL read I can probably figure out how to modify the code to make it work the way I want.

(In case anyone cares I'm selling online guitar lessons and it doesn't make sense to have the 300+ products sorted by name. The products appear in the correct order in the admin area but not when displayed in the cart. There are less than 90 products per category so I just use numbers from 10-99 for the values in the product "sort order:" field.)

Thanks a million if anyone knows the answer to this. I wonder if the ZenCart book has the answer to this question?

26 Sep 2007, 9:14 PM
#10
densys avatar

densys

New Zenner

Join Date:
Sep 2007
Posts:
2
Plugin Contributions:
0

Re: Product natural order

OK, so I understand what all of you are saying, so I have no choice but to rename all the products and add leading 0's?

26 Sep 2007, 9:24 PM
#11
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Product natural order

  1. You can change all the product names with a single query:
    sample:
    UPDATE table_name SET column_name = REPLACE(column_name,"original_string","replace_string")

  2. You can set the default sort to use the date the products were added, it's somewhere in the admin panel.

I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me