You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.
This mod is done to ./cgi-bin/library/modules/ste_prod.pl in the routine 'ste_prod_disp' to return products in a particular order when displaying them as related products, products with categories or products on pages like splash, new items, specials, best sellers, etc.
Be aware that this mod orders by product name (product_name field), but with the modification of the line with the ORDER BY clause in it, you could order by other fields like the product id (product_id field).
Here's how to do it:
In the file ./cgi-bin/library/modules/ste_prod.pl in the routine 'ste_prod_disp', right below:
if ($tables_data_source{'product'} eq "CSV") { $sql_limit_string = "$csv_limit_syntax"; } elsif ($tables_data_source{'product'} eq "ALT") { $sql_limit_string = "$alt_limit_syntax"; } ######### End of if statement.
Add:
$sql_limit_string = "ORDER BY product_name $sql_limit_string";
Then replace:
if ($related ne "" && $prodxcat_count >= "$first_row" && $prodxcat_count <= "$last_row") {
With:
if ($related ne "") {
Then replace:
if ($related ne "" && $prodxprod_count >= "$first_row" && $prodxprod_count <= "$last_row") {
With:
if ($related ne "") {
Then replace:
$sql_statement = " $sql_select_string WHERE $prodxcat_sql ";
With:
$sql_statement = " $sql_select_string WHERE $prodxcat_sql $sql_limit_string ";
Then replace:
$sql_statement = " $sql_select_string WHERE $prodxprod_sql ";
With:
$sql_statement = " $sql_select_string WHERE $prodxprod_sql $sql_limit_string ";
That's all there is to it. Just be sure to make all changes exactly as they are listed above.
Offline
You can just copy and paste the code right from the forum!!
This Forum is Code Friendly!!!
Offline
If you add a user field in product called product_sortorder, then populate this field for each product within a category (such as A01, B01, C01,D01 to order 4 different products) you can force a sort order "behind the scenes" for each product-category.
I have used this method since we cannot sort by product_id, product_name or any other "visible" field.
Larry
Offline
Nick, I've been hopping for a mod like this, Thank you.
But, I know nothing is never enough. My products either are sorted on product_number or product_name. I'm using Larry's (last post) idea and created a new field product_sort.
The mod is working fine but I'm either entering the number or name in the prodcut_sort field. Could you give me your mod in an if/else script.
like
IF product_number = "A" sort on product_name else on "N" product_number
This way I can save on my product file size.
Can this also be easily made into a choice that the customer can make?
Thank you -Steve
Offline
I made these changes to display products by product_id field but it doesn't seem to work... do I need to delete products and re-enter them into store catalogue?
Offline
No - you don't need to delete them and re-enter them. This code is ordering by product_name - are you sure your displays aren't ordering by that field? Did you double-check to make sure the ste_prod.pl file on the server was overwritten with all the changes?
Offline
Doh! What I wanted was product rather than id which was what I had entered. thanks for your help
Offline
Ok I followed this to the letter and it still will not list my products are now in order, but categories still aren't Any ideas?
Offline
How would I get my products listed in order by prod ref string on my admin-->manage products page?
Offline
That would be done by editing the file ./cgi-bin/library/modules/adm_iud.pl. In the 'adm_iud_list_disp' subroutine, look for:
if ($sql_limit_string ne "") { $sql_limit_string =~ s/start/$fd_startrow/gs; $sql_limit_string =~ s/rows/$admin_rows_to_return_per_page/gs; } ######### End of if statement.
And right below it, add:
if ($tablename eq "product") { $temp_string = "ORDER BY product_id"; $sql_limit_string = "$temp_string $sql_limit_string"; } ######### End of if statement.
Offline
Thank you! This has been very helpful.
But now here's a toughie.. would it be possible to have products arranged by different orders on separate categories?
for example, products in one category listed by item number, products in another category listed by item name.
this seems a bit more difficult but would it be possible?
thanks
Offline
I added another field to my product table. called product_sort. I deal in books and in some categories I want them listed by book number and in others by titles.
I enter either the title or the book number in the product_sort field.
I then use
$temp_string = "ORDER BY product_sort";
instead of:
$temp_string = "ORDER BY product_id";
Offline
sounds good
however, I have some products that will be in multiple categories..
and was wondering if it would be possible for different categories be ordered not just by one custom field but actually ordered based on different fields (depending on the category).
basically we are selling CDs, and my goal is to have things like "CDs by release date" and "CDs by artist" as separate categories (basically the same list products with a different order).
or maybe there's a better solution?
Offline
I just want to thank all those guys who post solutions on the forums that help all the newbies like myself. I would not be able to make any of the changes I do without your knowledge and guidance. Thanks again.
Offline
I implemented this sorting by product_number. It seems to work, but i noticed some new errors showing up in logs:
cp-app.cgi: DBD::mysql::st execute failed: You have an error in your SQL syntax near 'ORDER BY product_number LIMIT 0, 30
Can someone tell me what this means, and what i might do to rectify it?
I am also getting this error at the exact same time:
cp-app.cgi: ' at line 5 at /**my path to ccp installation**/cgi-bin/library/common/database.pl line 623.
Offline
Thanks for this mod!
Is there any way to list by REVERSE product_number? In other words, I would like items with higher numbers to be listing first in categories.
Thanks!
Jess
Offline
Nick, I used your code as described and it worked, except that I'm sorting by 'product_regprice' and the problem is that prices over $100 are being sorted first, so 100, 140, 250, 250, 32, 33, 35, 44, 66 - I guess it's sorting 'alphabetically' rather than numerically. How can I have it sorted by price from lowest to highest?
Thanks,
James...
Offline
It's sorting numerically but it doing it number by number from left to right:
100
140
250
32
33
35
44
if you look at it like this 1 is equal to 1 but 0 is smaller than 4 and so on, when it finds a number smaller than the one it is comparing it orders it first. You will have to get it to look at the number as a hole. I ran into the same problem with the mode to do a search by price that is posted in this forum "Searching With Min/max Prices" . I don't think that that solution will work in this case but it is the general idea of getting the script to compare the hole number. Mabe a sprintf statement may make the amouts into a decimal which will make the script compare the number as a hole but I'm realy not shure.
John
Offline
I understand why it's doing it, I just don't know how to fix it
James....
Offline
John, I checked out the referenced post but i don't care about searching, it's just sorting the products by price in a category from lowest to highest that I want...I'm SHOCKED that this hasn't come up before and been addressed.
James...
Offline
See correct solution further down thread.
Offline