Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

How TO Order Products List By Field

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 11-26-2002, 06:03 PM
 
Rondoosh Rondoosh is offline
 

Newbie
  
Join Date: Nov 2002
Posts: 9
 

Default How TO Order Products List By Field

Hello, i have a lot of products on my site and i wish to organize them. How to i arrange them by price...with out having to do it one by one? Thanks.
Reply With Quote
  #2  
Old 11-26-2002, 11:06 PM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

There is a fair amount of info on this on this thread. http://forum.x-cart.com/viewtopic.php?t=677&highlight=

The file to amend is the the customer/products.php file

Line 61 is:

Code:
$search_query = "($sql_tbl[products].categoryid='$cat' or $sql_tbl[products].categoryid1='$cat' or $sql_tbl[products].categoryid2='$cat' or $sql_tbl[products].categoryid3='$cat') and $sql_tbl[products].forsale='Y' group by $sql_tbl[products].productid order by $sql_tbl[products].orderby ".($config["General"]["product_order_reversed"]=="Y"?"desc":"asc")." limit $first_page, ".$config["General"]["products_per_page"];

Change this to:
Code:
$search_query = "($sql_tbl[products].categoryid='$cat' or $sql_tbl[products].categoryid1='$cat' or $sql_tbl[products].categoryid2='$cat' or $sql_tbl[products].categoryid3='$cat') and $sql_tbl[products].forsale='Y' group by $sql_tbl[products].productid order by $sql_tbl[pricing].price ".($config["General"]["product_order_reversed"]=="Y"?"desc":"asc")." limit $first_page, ".$config["General"]["products_per_page"];

I have left this with the product order reversed bit in so that you can set to increase or decrease through the admin centre.

You will also need to amend the featured products php file in the same way if you want that to display in a similar way.

Enjoy.
__________________
ex x-cart guru
Reply With Quote
  #3  
Old 12-02-2002, 05:53 PM
 
Rondoosh Rondoosh is offline
 

Newbie
  
Join Date: Nov 2002
Posts: 9
 

Default

thanks funkydunk, but i can't find the customer/products.php file. step by step how do i get to that template? Thanks for your patience.
Reply With Quote
  #4  
Old 12-02-2002, 10:40 PM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

Sorry,

You cant get to it through the admin area in x-cart, you need to open up the products.php file (either your local version or the one on the server) in a text editor. I use ultraedit (it highlights the php code very well).

You can then make any amendments needed.
__________________
ex x-cart guru
Reply With Quote
  #5  
Old 07-29-2003, 02:11 AM
 
aguy2no aguy2no is offline
 

Advanced Member
  
Join Date: Jan 2003
Location: The Netherlands
Posts: 37
 

Default

I posted a similar question in the MySQL forum, and just found the solution overhere.

Nevertheless, I tried this code in the products.php file and I received this error:

INVALID SQL: 1064 : You have an error in your SQL syntax near 'group by xcart_products.productid limit 45' at line 1
SQL QUERY FAILURE: select xcart_products.*, xcart_categories.category, min(xcart_pricing.price) as price from xcart_products, xcart_pricing, xcart_categories where xcart_pricing.productid=xcart_products.productid and xcart_pricing.quantity=1 and xcart_products.categoryid=xcart_categories.categor yid AND (xcart_categories.membership='' OR xcart_categories.membership='') and (xcart_pricing.membership='' or xcart_pricing.membership='') and (xcart_products.categoryid='46' or xcart_products.categoryid1='46' or xcart_products.categoryid2='46' or xcart_products.categoryid3='46') and xcart_products.forsale='Y' group by xcart_products.productid order by xcart_pricing.price asc limit 0, group by xcart_products.productid limit 45


Please can anybody help me out, cause I am pulling my hair out for the last couple of days!

I really would like to have my products sorted by price!!

thx!
Reply With Quote
  #6  
Old 07-29-2003, 02:18 AM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

what version are you using?

the code posted above was for a really old version and may not work with newer xcarts.
__________________
ex x-cart guru
Reply With Quote
  #7  
Old 07-29-2003, 02:37 AM
 
aguy2no aguy2no is offline
 

Advanced Member
  
Join Date: Jan 2003
Location: The Netherlands
Posts: 37
 

Default

Hi Funkydunk,

Currently I am upgrading form 2.3.0 to 3.4.3 Better to say that I am installing a complete new cart....

My line in teh products.php looks like:

Code:
$search_query = "($sql_tbl[products].categoryid='$cat' or $sql_tbl[products].categoryid1='$cat' or $sql_tbl[products].categoryid2='$cat' or $sql_tbl[products].categoryid3='$cat') and $sql_tbl[products].forsale='Y'";

I added at the end:

Code:
group by $sql_tbl[products].productid order by $sql_tbl[pricing].price ".($config["General"]["product_order_reversed"]=="Y"?"desc":"asc")." limit $first_page, ".$config["General"]["products_per_page"];

but this will result in the error previously described.

First I thought it was the " that was missing at the end...But I received a parse error when adding the quotationmark.

It's puzzling me...

Reply With Quote
  #8  
Old 07-29-2003, 07:58 AM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

Little known secret shhhh...

but you can get it do do an ascending sort by price by adding a link to the product page with additional variable of:

Code:
&orderby=price
Job done

same goes with alphabetically

Code:
&orderby=product

Now for one site I just added a table into the top of the products.tpl such as:

Code:
{* custom mod *} {if $products ne ""} <table border="0" cellspacing="0" cellpadding="2" width="100%"> <tr> <td valign="top" align="center" colspan="4"> Sort by: </td> </tr> <tr> <td valign="top" align="center"> Price </td> <td valign="top" align="center"> Product Name </td> <td valign="top" align="center"> Brand </td> <td valign="top" align="center"> Date Added </td> </tr> </table> {/if} {* end of custom mod *}
Now this uses the brand field in the database but xcart does not have that switched on as standard.

You will also need to add:

Code:
// funkydunk mod - added in so that sorting can carry forward across the pages $smarty->assign("orderby",$orderby);

into the bottom of customer/products.php

and change navigation.tpl to the following so that the orderby variable is carried over to the next page:

Code:
{* $Id: navigation.tpl,v 1.6 2002/10/22 10:27:05 olga Exp $ *} {if $total_pages gt 2} <table cellpadding=0 border=0> <tr height=14> {section name=page loop=$total_pages start=1} {if %page.index% eq 1} <td>{$lng.lbl_result_pages}: </td> {if $navigation_page gt 1} <td valign=middle>[img]{$ImagesDir}/larrow.gif[/img]</td> {/if} {/if} {if %page.index% eq $navigation_page} <td align=center> {%page.index%} </td> {else} <td width=17 background="{$ImagesDir}/page.gif" align=center> {%page.index%} </td> {/if} {if %page.last%} {capture name=total_pages_minus} {math equation="pages-1" pages=$total_pages} {/capture} {if $navigation_page lt $smarty.capture.total_pages_minus} <td valign=middle>[img]{$ImagesDir}/rarrow.gif[/img]</td> {/if} {/if} {/section} </tr></table> {/if}
__________________
ex x-cart guru
Reply With Quote
  #9  
Old 07-29-2003, 12:16 PM
 
aguy2no aguy2no is offline
 

Advanced Member
  
Join Date: Jan 2003
Location: The Netherlands
Posts: 37
 

Default

He Funkydunk,

a million, man! I placed the code in the proper files.

I started with

Code:
&orderby=price

I did not really get it where to place it. What I did is the following:

Code:
$search_query = "($sql_tbl[products].categoryid='$cat' or $sql_tbl[products].categoryid1='$cat' or $sql_tbl[products].categoryid2='$cat' or $sql_tbl[products].categoryid3='$cat') and $sql_tbl[products].forsale='Y' &orderby=price";

As you can see I put it at the end as an argument. Not sure if that's ok....Well I am sure that it is nog OK, because it is not working....

The order by price argument doesn't bring up any errormessage but no products will show up.

I reckon I made a mistake here, ah... What did I do wrong???

The rest of your mods seem to be fine. Thanks a lot...very usefull mods!
[/quote]
Reply With Quote
  #10  
Old 07-29-2003, 01:30 PM
 
aguy2no aguy2no is offline
 

Advanced Member
  
Join Date: Jan 2003
Location: The Netherlands
Posts: 37
 

Default

OK...I got a little bit further....

Now I changed the query in products.php into:

Code:
$search_query = "($sql_tbl[products].categoryid='$cat' or $sql_tbl[products].categoryid1='$cat' or $sql_tbl[products].categoryid2='$cat' or $sql_tbl[products].categoryid3='$cat') and $sql_tbl[products].forsale='Y' &orderby=price &orderby=product ";

This seems to work.... Products will show up alphabetically. When I leave "&orderby=products"... I'll get no searchresults. The same happens when I skip "&orderby=price"....No results...

I am running bazurk!
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 05:31 PM.

   

 
X-Cart forums © 2001-2020