Guzappum Posted April 27, 2015 Share Posted April 27, 2015 Hi, I have a working dropdown box in my categories where customers can choose to short by price, manufacturer or name. What is the easiest way to add "sort by date" to the dropdown? This is the code that creates the dropdown, how should I modify? // Additional Products Sort echo '<td align="center" class="main">' . tep_draw_form('sort', FILENAME_DEFAULT, 'get') . '<b>Rendezés '; if (isset($HTTP_GET_VARS['manufacturers_id'])) { echo tep_draw_hidden_field('manufacturers_id', $HTTP_GET_VARS['manufacturers_id']); } else { echo tep_draw_hidden_field('cPath', $cPath); } $sort_list = array('2a' => 'Name A-Z', '2d' => 'Name Z-A', '6d' => 'Manufacturer A-Z', '6a' => 'Manufacturer Z-A', '4a' => 'Cheapest first', '4d' => 'Expensive first'); foreach($sort_list as $id=>$text) { $sort_range[] = array('id' => $id, 'text' => $text); } echo tep_draw_pull_down_menu('sort', $sort_range, (isset($HTTP_GET_VARS['sort']) ? $HTTP_GET_VARS['sort'] : ''), 'onchange="this.form.submit()"'); echo tep_draw_hidden_field('filter_id', (isset($HTTP_GET_VARS['filter_id']) ? $HTTP_GET_VARS['filter_id'] : '')); echo '</form></td>' . "\n"; // End Additional Products Sort I can add an entry to the box by placing a line like so: '7d' => 'Cheapest first', But none of the possible fields(1d,3d,...,20d,etc) call for the date of the product (tep.products_date_added). So what should I put in '??' instead of 7d? Please help me out as I don't really know php, but really hoping to add this ability to the site. Regards Link to comment Share on other sites More sharing options...
♥ecartz Posted May 3, 2015 Share Posted May 3, 2015 This is not the main code that you need to change. You have to change the code that processes the drop down, not the display. Once you find that code, it will be easier to tell you what to write instead of 7d or 7a (those might even be correct). Note that the a/d part looks to be just ascending/descending. It's the number processing that will need to change. I'm guessing that you'll have to write new code for it. Always back up before making changes. Link to comment Share on other sites More sharing options...
Guzappum Posted July 29, 2015 Author Share Posted July 29, 2015 Hi, Thank you for the reply earlier @@ecartz, I have been trying to work this out ever since, but I lack PHP knowledge, so it was mostly guesswork with trial-and-error. Finally could only come up with a rather rude workaround. Here is what I did: OsC has a date added column, which is already used on products_new.php to sort new items by date. It is:p.products_date_addedIn index.php there is a part of code that lists the different columns products could be sorted by. I hoped if I added the code below I could get the option to sort by date: case 'PRODUCT_LIST_DATE': $listing_sql .= " order by final_price " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name"; break; This, however does not work. As no "number" got assigned to it as far as I could tell, I could not make sort by date accessible in the dropdown. Now comes the rude workaround part: Turns out there is a sort by image option in the list, which I can't imagine has user-end functionality (and has number 1 assigned to it). I changed this to use p.products_date_added for sorting the products instead of pd.products_name. In short I did the following: in catalog/index.php --- FIND THIS case 'PRODUCT_LIST_IMAGE': $listing_sql .= " order by p.products_date_added " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name"; break; REPLACE WITH case 'PRODUCT_LIST_IMAGE': $listing_sql .= " order by pd.products_name"; break; --- ADD THIS TO TOP OF DROPDOWN LIST OPTIONS AFTER $sort_list = array( '1d' => 'New products first', I would prefer to do it properly. Can any one of you more qualified gentlemen tell me where/how the numbers are assigned? More specifically, how could I assign a number to a new sort method? (And could I have ruined something by getting rid of 'sorting by image' that I did not notice?) Many thanks in advance! Regards: Denes Link to comment Share on other sites More sharing options...
♥ecartz Posted August 4, 2015 Share Posted August 4, 2015 The easiest way would probably be to change if ( (!isset($HTTP_GET_VARS['sort'])) || (!preg_match('/^[1-8][ad]$/', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {to something like if (isset($HTTP_GET_VARS['sort']) && ('9' == substr($HTTP_GET_VARS['sort'], 0, 1))) { $listing_sql .= " order by p.products_date_added " . (substr($HTTP_GET_VARS['sort'], 1) == 'd' ? 'desc' : '') . ", pd.products_name"; } else if ( (!isset($HTTP_GET_VARS['sort'])) || (!preg_match('/^[1-8][ad]$/', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) { And then add your new menu item as 9d. So long as you don't allow more than eight columns, this will work without interfering with the existing configuration. Always back up before making changes. Link to comment Share on other sites More sharing options...
Guzappum Posted August 9, 2015 Author Share Posted August 9, 2015 Thank you Matt, this solution works well! What is your opinion on the 'sort by image' feature? Could replacing that part of the code have any ill effects? Regards: Denes Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.