johnc Posted July 16, 2003 Share Posted July 16, 2003 I am trying to change the default sort column on the product listing page (i.e first page in a category) to make it use the model as the default sort order instead of the product name. I have changed var - model to type for my purpose and I need the product_listing.php that is accessed when I select a category (sandwiches) to sort the results array by type (model) not the product name as is default, this will allow me to list all vegetarian sandwiches, meat etc together by default not ascending alpha by product name, which is going to be confusing for the customer Anybody help ??? Any ideas ??, I am new to OSCommerce?.I have a really bad internet connection as well so it is not easy to search the forum, sorry if it is here already somewhere. :? Link to comment Share on other sites More sharing options...
ZAP Posted July 16, 2003 Share Posted July 16, 2003 This is a pretty easy change to make, which should make you happy. Open default.php (or index.php, depending upon your osC version). Look for this code (or something similar) around line 200: if ( (!$HTTP_GET_VARS['sort']) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'],0,1) > sizeof($column_list)) ) { for ($col=0, $n=sizeof($column_list); $col<$n; $col++) { if ($column_list[$col] == 'PRODUCT_LIST_NAME') { $HTTP_GET_VARS['sort'] = $col+1 . 'a'; $listing_sql .= " order by pd.products_name"; break; } } } else { All you have to do is change the two references to the product name to model instead. Your altered code should look something like this: if ( (!$HTTP_GET_VARS['sort']) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'],0,1) > sizeof($column_list)) ) { for ($col=0, $n=sizeof($column_list); $col<$n; $col++) { if ($column_list[$col] == 'PRODUCT_LIST_MODEL') { $HTTP_GET_VARS['sort'] = $col+1 . 'a'; $listing_sql .= " order by pd.products_model"; break; } } } else { I am sorting my list by price right now, but I may change to sorting by "model" (which I am not showing and don't actually use) and then use the "model" field as a way to manually sort my list. Link to comment Share on other sites More sharing options...
johnc Posted July 16, 2003 Author Share Posted July 16, 2003 Thanks ZAP, If I had looked there in the first place I may have found it sooner.... Your code had one small error in it for anybody else that looks, but you took me 99.9% of the way there in the last line of the new code it should read as follows " order by p.products_model" not " order by pd.products_model" thankyou for your quick response and solution... Link to comment Share on other sites More sharing options...
ZAP Posted July 16, 2003 Share Posted July 16, 2003 Cool! Glad to help. Sorry about the typo. Link to comment Share on other sites More sharing options...
chirpy36 Posted August 10, 2003 Share Posted August 10, 2003 This tweak was just what I needed to manually order the products in a category. However, the only way I could get it to work was to change the last line of the referenced code, but not change PRODUCT_LIST_NAME, like this: if ( (!$HTTP_GET_VARS['sort']) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'],0,1) > sizeof($column_list)) ) { for ($col=0, $n=sizeof($column_list); $col<$n; $col++) { if ($column_list[$col] == 'PRODUCT_LIST_NAME') { $HTTP_GET_VARS['sort'] = $col+1 . 'a'; $listing_sql .= " order by p.products_model"; break; } } } else { Now it's working great! Otherwise it was sorting by product ID, I think. Link to comment Share on other sites More sharing options...
Mark the Harp Posted September 5, 2003 Share Posted September 5, 2003 I love this way of changing the default sort order - it works perfectly. However, advanced search will still list your products in a fairly random order, so you need to change this php file too. To specify the default order of search results: 1) open catalog/advanced_search_result.php 2) change the following line (~ line 305): $order_str = ' order by pd.products_name'; to $order_str = ' order by p.products_price'; You can choose other attributes if you want to sort other than by price. 3) test it out. If you get an error message, check that you've changed the pd.products to p.products as well as changing _name to _price I don't think there are any other files to change but if there are others which give product listings and they're not in the order you want, open up the corresponding file and find a similar line to those above.[/b] Link to comment Share on other sites More sharing options...
Frank_NL Posted September 12, 2003 Share Posted September 12, 2003 I got a question. This doesn't work for sorting on price. This is the product in refering about I want to have all the fields default price. Not pay more. Can anyone help me here? Link to comment Share on other sites More sharing options...
Ken Wood Posted May 12, 2005 Share Posted May 12, 2005 I tried both ways. The one where you change it twice doesn`t work. The other does, except if you split the product listing page: as soon as you go to the next page the sort by model seems not to apply anymore. Can this be fixed? Thanks! Ken Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.