Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Adding additional filters to product listing


raddygast

Recommended Posts

Is this possible? I'm not sure it is, but I'd like to be able to filter by manufacturers_name, but also by some other fields that I'm adding, say "rarity" or something.

 

Ideally you would be able to apply both filters, so that you could select one, and it'd be filtered, then you select the second one, and it would further filter.

 

This is the code for the manuf. filter -- can someone tell me if it is logically possible to add a second filter in there? And if so, how do I go about finding the variable names I am supposed to use?

 

from catalog/index.php:

 

// optional Product List Filter
   if (PRODUCT_LIST_FILTER > 0) {
     if (isset($HTTP_GET_VARS['manufacturers_id'])) {
       $filterlist_sql = "select distinct c.categories_id as id, cd.categories_name as name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where p.products_status = '1' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and p2c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and p.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "' order by cd.categories_name";
     } else {
       $filterlist_sql= "select distinct m.manufacturers_id as id, m.manufacturers_name as name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_MANUFACTURERS . " m where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$current_category_id . "' order by m.manufacturers_name";
     }
     $filterlist_query = tep_db_query($filterlist_sql);
     if (tep_db_num_rows($filterlist_query) > 1) {
       echo '            <td align="center" class="main">' . tep_draw_form('filter', FILENAME_DEFAULT, 'get') . TEXT_SHOW . ' ';
       if (isset($HTTP_GET_VARS['manufacturers_id'])) {
         echo tep_draw_hidden_field('manufacturers_id', $HTTP_GET_VARS['manufacturers_id']);
         $options = array(array('id' => '', 'text' => TEXT_ALL_CATEGORIES));
       } else {
         echo tep_draw_hidden_field('cPath', $cPath);
         $options = array(array('id' => '', 'text' => TEXT_ALL_MANUFACTURERS));
       }
       echo tep_draw_hidden_field('sort', $HTTP_GET_VARS['sort']);
       while ($filterlist = tep_db_fetch_array($filterlist_query)) {
         $options[] = array('id' => $filterlist['id'], 'text' => $filterlist['name']);
       }
       echo tep_draw_pull_down_menu('filter_id', $options, (isset($HTTP_GET_VARS['filter_id']) ? $HTTP_GET_VARS['filter_id'] : ''), 'onchange="this.form.submit()"');
       echo '</form></td>' . "\n";
     }
   }

Link to comment
Share on other sites

well, this can of course be done :-)

 

you are defining the filter options yourself, and of course you can define two different filters so 2 can be combined.

 

It will need quite a bit of custom coding to adjust all the select statements ... adding a second dropdown will go fast though. You get the variables from the url, like it is done now.

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

well, this can of course be done :-)

 

you are defining the filter options yourself, and of course you can define two different filters so 2 can be combined.

 

It will need quite a bit of custom coding to adjust all the select statements ... adding a second dropdown will go fast though. You get the variables from the url, like it is done now.

 

Forgive me if I'm being dense, but it seemed to me (last night, after I posted) that this will not be easy, because the current Manufacturer filter, as an example, doesn't actually filter on what's already been displayed on the screen. It must do a database query. So if I just copied and pasted that code and changed the field that it works with, it may give me another filter dropdown box, but selecting an item in that box would essentially re-filter the products with only that new field as a filter.

 

What I wanted is to be able to have all filters working together to narrow down the listing.

 

Certainly I know it's possible, but I'm no SQL guru. I wonder if anyone's done this before?

 

And if anyone here knows the correct SQL syntax, or if anyone can figure this out in just a few lines of modification to the code snippet above, I'd be eternally grateful. :)

Link to comment
Share on other sites

Forgive me if I'm being dense, but it seemed to me (last night, after I posted) that this will not be easy, because the current Manufacturer filter, as an example, doesn't actually filter on what's already been displayed on the screen. It must do a database query. So if I just copied and pasted that code and changed the field that it works with, it may give me another filter dropdown box, but selecting an item in that box would essentially re-filter the products with only that new field as a filter.

 

What I wanted is to be able to have all filters working together to narrow down the listing.

 

Certainly I know it's possible, but I'm no SQL guru. I wonder if anyone's done this before?

 

And if anyone here knows the correct SQL syntax, or if anyone can figure this out in just a few lines of modification to the code snippet above, I'd be eternally grateful. :)

 

:-)

 

well like I said the 2 filters will work together if coded correctly, but it's not done just in a few lines ... it would take me a while to get it done correctly!

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...