You are here:  » Price Range Filter


Price Range Filter

Submitted by support on Sat, 2006-09-30 11:50 in

Hi Everyone,

Here's a new filter i've just written for one of my own sites that may come in handy if you only wish to feature products within a certain price range. Simply paste the code into includes/filter.php just before the closing PHP tag:

  /*************************************************/
  /* priceRange */
  /*************************************************/
  $filter_names["priceRange"] = "Price Range";
  function filter_priceRangeConfigure($filter_data)
  {
    print "Min:<br />";
    print "<input type='text' name='min' value='".widget_safe($filter_data["min"])."' />";
    widget_errorGet("search");
    print "<br /><br />";
    print "Max: (leave blank for no upper limit)<br />";
    print "<input type='text' name='max' value='".widget_safe($filter_data["max"])."' />";
    widget_errorGet("replace");
  }
  function filter_priceRangeValidate($filter_data)
  {
    if ($filter_data["min"])
    {
      if (!is_numeric($filter_data["min"]))
      {
        widget_errorSet("min","must be numeric");
      }
    }
    if ($filter_data["max"])
    {
      if (!is_numeric($filter_data["max"]))
      {
        widget_errorSet("max","must be numeric");
      }
    }
  }
  function filter_priceRangeExec($filter_data,$text)
  {
    global $filter_dropRecordFlag;
    if ($filter_dropRecordFlag) return $text;
    $price = tapestry_decimalise($text);
    if ($filter_data["min"] && $filter_data["max"])
    {
      $filter_dropRecordFlag = (($price < $filter_data["min"]) || ($price > $filter_data["max"]));
    }
    elseif ($filter_data["min"])
    {
      $filter_dropRecordFlag = ($price < $filter_data["min"]);
    }
    elseif ($filter_data["max"])
    {
      $filter_dropRecordFlag = ($price > $filter_data["max"]);
    }
    return $text;
  }

Cheers,
David.

Submitted by clare on Sun, 2006-10-01 18:38

I have been reading the old forum posts where others asked about including a price range search facility on their sites, and read that it was being worked on.

Does this new filter mean that there is a way now to create a price range search for users on a website. So they can view all products between 1-10 for example, in whatever category?

I can see how I can use it to import products from any price range, but is it now also possible to do some price range function for users?

Thanks

Submitted by support on Mon, 2006-10-02 07:30

Hi Clare,

This filter only affects what is imported, it does now allow users to specify a price range.

If you want the mods let me know and i'll email the changed files to you; but bear in mind that it is not recommended for use on a large site because it adds a WHERE clause into the search SQL against a field that is not indexed; and this could make searching very slow on a large database!

Cheers,
David.

Submitted by clare on Mon, 2006-10-02 08:35

Hi
Is it only the price range search that is slow, other searches would remain ok?

I would like the files, thankyou, I will see whether it is ok on my site, as it isnt so large as of yet.

Thanks
Clare

Submitted by support on Mon, 2006-10-02 09:04

> Is it only the price range search that is slow, other searches would remain ok?

Yes - the price range boxes are optional.

I'll send the files over now...

Cheers,
David.

Submitted by thepricesite on Mon, 2006-10-02 09:10

David - could i also have a copy of the files please?

Michael @ ThePriceSite

Submitted by clare on Mon, 2006-10-02 09:11

I suppose I could set up price tapestry in a diff directory for each price range, as well as having a full catalog. And so instead of importing the feed just once, import it a few times, using various filters.It wouldnt actually take much time once it was set up, to import using the filters, as well as in full.

Then direct users to the specific page for each price range. Where they can see the filtered priced products in each category, merchant etc.

Does this sound reasonable to you, before I do it? Can you see any problem with that?

Submitted by clare on Mon, 2006-10-02 09:13

Thankyou for the files, just received them, will try that first I think.