You are here:  » Search By Brand and/or Merchant and/or Price range

Support Forum



Search By Brand and/or Merchant and/or Price range

Submitted by lunen on Sat, 2011-09-17 02:49 in

Hi David,

I've been searching the forums looking for a way to do this and there are bits and pieces here and there. It looks like you helped some people do similar things but it was done via email and not on the forum, so I apologize for asking. If you can just get me started in the right direction that would be great.

So on the homepage and on the product pages (at the top just below the menu; basically the banner) I'd like to have three drop down boxes. The first one for Search by Brand, Second By Price Range (0- 200, 200-300, etc), and the search by merchant, and then a search button that executes the search. So the user can input one, two or all three search perimeters. Say the enter brand and price range and not merchant the search will still run.

I'd like to do this on the homepage and on the product pages because I get a lot of long tail search for a product, and I want users to see the simple search function of the website. Also I only have about 7,000 products so this type of search may be slow, but it won't affect the performance because there's not that many products.

Thanks for your help!

Submitted by support on Sat, 2011-09-17 10:00

Hi lunen,

The first step towards this would be to implement the Sidebar Filters mod (info - download) as this will add the necessary merchantFilter, categoryFilter parameters etc. to your search.php. If you don't actually want sidebar filters; rather just the search form as you described on the front page; don't extract the html/searchresults.php file from the download - just update search.php on it's own.

Next, in search.php look for the following code at line 20:

  $priceWhere = "";

...and REPLACE with:

  $priceFilter = ($_GET["priceFilter"]?$_GET["priceFilter"]:"");
  if ($priceFilter)
  {
    $parts = explode("|",$priceFilter);
    $_GET["minPrice"] = $parts[0];
    $_GET["maxPrice"] = $parts[1];
  }
  $priceWhere = "";

With the above mod in place, the following code should be very close to the drop-down search form you want:

<?php
  
print "<form method='GET' action='".$config_baseHREF."search.php'>";
  print 
"<input type='hidden' name='q' value='bw:' />";
  
$sql1 "SELECT DISTINCT(brand) FROM `".$config_databaseTablePrefix."products` WHERE brand <> '' ORDER BY brand";
  if (
database_querySelect($sql1,$rows1))
  {
    print 
"<label form='bf'>Brand:</label><br />";
    print 
"<select style='width:150px;' id='bf' name='brandFilter'>";
    print 
"<option value=''>All</option>";
    foreach(
$rows1 as $row)
    {
      print 
"<option value='".htmlentities($row["brand"],ENT_QUOTES,$config_charset)."' >".$row["brand"]."</option>";
    }
    print 
"</select>";
    print 
"<br /><br />";
  }
  print 
"Price:<br />";
  
$priceFilters["|200.00"]       = "Up to ".$config_currencyHTML."200";
  
$priceFilters["200.00|400.00"] = $config_currencyHTML."200 - ".$config_currencyHTML."400";
  
$priceFilters["400.00|600.00"] = $config_currencyHTML."400 - ".$config_currencyHTML."600";
  
$priceFilters["600.00|"]       = "Over ".$config_currencyHTML."600";
  print 
"<select style='width:150px;' id='mf' name='priceFilter'>";
  print 
"<option value=''>All</option>";
  foreach(
$priceFilters as $priceFilter => $text)
  {
    print 
"<option value='".$priceFilter."'>".$text."</option>";
  }
  print 
"</select>";
  print 
"<br /><br />";
  
$sql1 "SELECT DISTINCT(merchant) FROM `".$config_databaseTablePrefix."products` ORDER BY merchant";
  if (
database_querySelect($sql1,$rows1))
  {
    print 
"<label form='mf'>Merchant:</label><br />";
    print 
"<select style='width:150px;' id='mf' name='merchantFilter'>";
    print 
"<option value=''>All</option>";
    foreach(
$rows1 as $row)
    {
      print 
"<option value='".htmlentities($row["merchant"],ENT_QUOTES,$config_charset)."'>".$row["merchant"]."</option>";
    }
    print 
"</select>";
    print 
"<br /><br />";
  }
  print 
"<input type='submit' value='Search' />";
  print 
"</form>";
?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by lunen on Sat, 2011-09-17 21:08

thanks dave, the dropdown boxes look good, but when I add the new search.php page. All my pages come up blank? After I enter a search and if I used the links. Any ideas?

Submitted by support on Sun, 2011-09-18 06:45

Hi lunen,

Could you email me your modified search.php and I'll check it out...

Thanks,
David.
--
PriceTapestry.com