Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Sort Products buy price


H20hum

Recommended Posts

Posted

Hi,

 

Is there a straight forward way of sorting products buy price in ascending order, so cheapest first....working its way to most expensive?

 

Thanks in advance for any help whatsoever!

 

Craig :blink:

Posted

for the product listings in your catalog\index.php locate this:

 

if ($column_list[$i] == 'PRODUCT_LIST_NAME') {
	  $HTTP_GET_VARS['sort'] = $i+1 . 'a';
	  $listing_sql .= " order by pd.products_name";
	  break;
	}

 

replace it with:

 

if ($column_list[$i] == 'PRODUCT_LIST_PRICE') {
	  $listing_sql .= " order by final_price";
	  break;
	}

Posted

Thanks for the fast reply!

 

Ive changed the code but my products still are not listed by price?

 

Is there any other page other than the index.php file that I would need to change?

 

Would I need to change any of this code? Im new to PHP, but it looks as tho its sorting by product name here.

 

    } 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_model " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
       case 'PRODUCT_LIST_NAME':
         $listing_sql .= "pd.products_name " . ($sort_order == 'd' ? 'desc' : '');
         break;
       case 'PRODUCT_LIST_MANUFACTURER':
         $listing_sql .= "m.manufacturers_name " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
       case 'PRODUCT_LIST_QUANTITY':
         $listing_sql .= "p.products_quantity " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
       case 'PRODUCT_LIST_IMAGE':
         $listing_sql .= "pd.products_name";
         break;
       case 'PRODUCT_LIST_WEIGHT':
         $listing_sql .= "p.products_weight " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
       case 'PRODUCT_LIST_PRICE':
         $listing_sql .= "final_price " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
     }

 

 

Thanks again! :blink:

Posted

what page is displayed in the address bar of your browser? where you want to the sorting.

Posted

well that's it. It should sort by price by default. So make sure you're updating the files on the right server. For other pages you need to find the sql queries and do the order by whatever price field is there.

Posted

Following the help from above, I was able to get the sorting by price corrected. The only thing is I had to actually close my storefront browser and open a new browser. The sorting wouldn't correct itself by just reloading the page.

 

My new code looks like this:

if ($column_list[$i] == 'PRODUCT_LIST_PRICE') {
         $HTTP_GET_VARS['sort'] = $i+1 . 'a';
         $listing_sql .= " order by final_price";
         break;

  • 1 month later...
Posted

you do:

 

if ($column_list[$i] == 'PRODUCT_LIST_PRICE') {
	  $listing_sql .= " order by final_price desc";
	  break;
	}

  • 3 weeks later...
Posted

I figured it out by myself...

 

For the people who wants to know how:

		if ($column_list[$i] == 'PRODUCT_LIST_MANUFACTURER') {
	  $HTTP_GET_VARS['sort'] = $i+1 . 'a';
	  $listing_sql .= " order by m.manufacturers_name, pd.products_name";
	  break;
	}

Archived

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

×
×
  • Create New...