You are here:  » Add extra field


Add extra field

Submitted by wesse249 on Wed, 2015-08-12 09:20 in

Hello David,

What is the right topic to add an extra import field? Which i visitor also can filter on the front?

I see several topics but don't know which one is richt.

I use 15/01A

Greetings Jan Roel

Submitted by support on Wed, 2015-08-12 09:50

Hello Jan,

The standard instructions for adding a new custom field can be found at the top of this thread.

Having added a new custom field, simply duplicate all instances of code relating to "brandFilter" across search.php and html/searchfilters.php for your new field. So let's say you have added a new field "colour", the following modifications would add a filter for the new field:

Edit search.php and look for the following code at line 18:

  $brandFilter = (isset($_GET["brandFilter"])?$_GET["brandFilter"]:"");

...and REPLACE with:

  $brandFilter = (isset($_GET["brandFilter"])?$_GET["brandFilter"]:"");
  $colourFilter = (isset($_GET["colourFilter"])?$_GET["colourFilter"]:"");

Then look for the following code at line 72:

  if ($brandFilter)
  {
    $priceWhere .= " AND brand = '".database_safe($brandFilter)."' ";
  }

...and REPLACE with:

  if ($brandFilter)
  {
    $priceWhere .= " AND brand = '".database_safe($brandFilter)."' ";
  }
  if ($colourFilter)
  {
    $priceWhere .= " AND colour = '".database_safe($colourFilter)."' ";
  }

THen look for the following code at line 421:

      if ($brandFilter)
      {
        $sortHREF .= "brandFilter=".urlencode($brandFilter)."&";
      }

...and REPLACE with:

      if ($brandFilter)
      {
        $sortHREF .= "brandFilter=".urlencode($brandFilter)."&";
      }
      if ($colourFilter)
      {
        $sortHREF .= "colourFilter=".urlencode($colourFilter)."&";
      }

And finally the following code at line 539:

    if ($brandFilter)
    {
      $sort .= "&brandFilter=".urlencode($brandFilter);
    }

...and REPLACE with:

    if ($brandFilter)
    {
      $sort .= "&brandFilter=".urlencode($brandFilter);
    }
    if ($colourFilter)
    {
      $sort .= "&colourFilter=".urlencode($colourFilter);
    }

To generate the filter drop down, use the following code within html/searchfilters.php:

  $sql1 = "SELECT DISTINCT(colour) FROM `".$config_databaseTablePrefix."products` WHERE ".$where.$priceWhere." AND colour <> '' ORDER BY colour";
  if (database_querySelect($sql1,$rows1))
  {
    print "<div class='small-12 medium-2 columns'>";
    print "<label>Colour<<br />";
    print "<select name='colourFilter'>";
    print "<option value=''>".translate("All")."</option>";
    foreach($rows1 as $row)
    {
      $selected = ($colourFilter==$row["colour"]?"selected='selected'":"");
      print "<option value='".htmlspecialchars($row["colour"],ENT_QUOTES,$config_charset)."' ".$selected.">".$row["colour"]."</option>";
    }
    print "</select>";
    print "</label>";
    print "</div>";
  }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by wesse249 on Wed, 2015-08-12 09:55

Hi david,

Thank you. And replace in this code everything with brand into colour?

Submitted by support on Wed, 2015-08-12 10:20

Sorry Jan, yes - that's absolutely right, I forgot to make the replacement when pasting in the code - corrected above...

Cheers,
David.
--
PriceTapestry.com