Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Product_Listing.php sort order problem


macrosupport

Recommended Posts

Posted

I have a modified version of OSC up and running but am having trouble changing what value the products are sorted by. I don't really need the products sort contrib, just want them to sort by either date added or product ID. I want it to show the last product added, first.

 

Can someone give me a hand, I am sure that its something simple. Let me know and I will send you the appropriate file.

 

Here is the page I need to change the sort for product listing

Posted

in my index.php have code responsible for sort order

 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';
	  [b]$listing_sql .= " order by pd.products_name";[/b]
	  break;

 

I changed it to sort by price (in my case)

try to play with this code ($listing_sql) maybe it is not that complicated.

p.s. I am not that good at php at all , just give you an example from my shop

Posted

I have that code, but changing it to p.products_id doesnt do the trick. How do I get it to sort descending instead of ascending?

 

Here is my 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_NAME') {

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

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

break;

}

}

} else {

$sort_col = substr($HTTP_GET_VARS['sort'], 0 , 1);

$sort_order = substr($HTTP_GET_VARS['sort'], 1);

$listing_sql .= ' order by ';

switch ($column_list[$sort_col-1]) {

case 'PRODUCT_LIST_MODEL':

$listing_sql .= "p.products_id " . ($sort_order == 'd' ? 'desc' : '');

break;

case 'PRODUCT_LIST_NAME':

$listing_sql .= "p.products_id " . ($sort_order == 'd' ? 'desc' : '');

break;

case 'PRODUCT_LIST_MANUFACTURER':

$listing_sql .= "p.products_id " . ($sort_order == 'd' ? 'desc' : '');

break;

case 'PRODUCT_LIST_QUANTITY':

$listing_sql .= "p.products_id " . ($sort_order == 'd' ? 'desc' : '');

break;

case 'PRODUCT_LIST_IMAGE':

$listing_sql .= "p.products_id desc";

break;

case 'PRODUCT_LIST_WEIGHT':

$listing_sql .= "p.products_id " . ($sort_order == 'a' ? 'desc' : '');

break;

case 'PRODUCT_LIST_PRICE':

$listing_sql .= "p.products_id " . ($sort_order == 'a' ? 'desc' : '');

break;

}

}

 

I tried to change it across the board

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...