You are here:  » Price filter negative values


Price filter negative values

Submitted by D.Tzortzis on Mon, 2014-09-08 19:13 in

Today i noticed that the price filter in search.php [From > To] can take negative values x -1, -2 and etc.
We have any modification to prevent the negative values?

Thanks,
D. Tzortzis

Submitted by support on Mon, 2014-09-08 21:17

Hi!

I just noticed this myself today after a browser update showed new up/down arrows on the min / max price fields as a result of the type='number' attibute, so I want to investigate this further and decide whether an HTML5 type is appropriate in this case - it looks like it should be with the addition of step='any' to the minPrice / maxPrice input fields in html/searchfilters.php which you might like to add, but otherwise to prevent a negative value being input (and treated as 0.00 instead), in search.php look for the following code at line 24:

  $minPrice = sprintf("%.2f",$_GET["minPrice"]);

...and REPLACE with:

  $minPrice = sprintf("%.2f",$_GET["minPrice"]);
  if ($minPrice < 0) $minPrice = 0.00;

And then the following code at line 34:

  $maxPrice = sprintf("%.2f",$_GET["maxPrice"]);

...and REPLACE with:

  $maxPrice = sprintf("%.2f",$_GET["maxPrice"]);
  if ($maxPrice < 0) $maxPrice = 0.00;

Cheers,
David.
--
PriceTapestry.com

Submitted by D.Tzortzis on Sat, 2014-09-13 09:42

Hello,
I have do the modifications into the search.php but again takes negative values:

  $q = (isset($_GET["q"])?tapestry_normalise($_GET["q"],":\."):"");
  $page = (isset($_GET["page"])?intval($_GET["page"]):1);
  $sort = (isset($_GET["sort"])?$_GET["sort"]:"relevance");
  $rewrite = isset($_GET["rewrite"]);
  $merchantFilter = (isset($_GET["merchantFilter"])?$_GET["merchantFilter"]:"");
  $categoryFilter = (isset($_GET["categoryFilter"])?$_GET["categoryFilter"]:"");
  $brandFilter = (isset($_GET["brandFilter"])?$_GET["brandFilter"]:"");
  $priceWhere = "";
  if (isset($_GET["minPrice"]) && $_GET["minPrice"])
  {
    $minPrice = sprintf("%.2f",$_GET["minPrice"]);
  if ($minPrice < 0) $minPrice = 0.00;
  }
  else
  {
    $minPrice = "";
  }
  if (isset($_GET["maxPrice"]) && $_GET["maxPrice"])
  {
   $maxPrice = sprintf("%.2f",$_GET["maxPrice"]);
  if ($maxPrice < 0) $maxPrice = 0.00;
  }
  else
  {
    $maxPrice = "";
  }

Thanks,
D. Tzortzis

Submitted by support on Sat, 2014-09-13 10:25

Hi,

Those changes look fine, but bear in mind this alone won't prevent a negative value from being entered, but it will be treated as 0.00 if so. However, using the new HTML5 min='0' attribute on the minPrice / maxPrice text boxes in html/searchfilters.php will do the trick.... In that file, search for each instance of:

  type='number'

...(lines 133/141) and REPLACE with:

  type='number' step='any' min='0'

Regarding your post about category hierarchy, if I have a chance to reply to that thoroughly I will post over the weekend, otherwise first thing Monday morning of course - I am looking at a category hierarchy editor as a possible update...!)

Cheers,
David.
--
PriceTapestry.com

Submitted by D.Tzortzis on Sat, 2014-09-13 10:40

The trick with
type='number' step='any' min='0' working correct now prevent the text box to go in negative values.

About the category hierarchy i'm waiting your reply :)

The support you provided is incredible and you deserve Well Done.
Keep up the good work David, you're flawless!

Thanks,
D. Tzortzis