You are here:  » Voucher Match Criteria

Support Forum



Voucher Match Criteria

Submitted by chrisst1 on Fri, 2013-01-18 14:22 in

Hi David

I've added extra match types to voucher_codes_edit.php and other files as per the mod on the forum.

$match_types = array("exact"=>"Exact Match","keyword"=>"Keyword Match","regexp"=>"If Regular Expression","notregexp"=>"If Not Regular Expression");

The match works in price results in products.php for all of the above methods, but when using the link

oursite/search.php?q=voucher:Harveys:AFFJAN13

it will display all products if no match type entered ok and "keyword" match type works but not the "exact" "regexp" "notregexp" match types.

Does this have something to do with (code below) in search.php, will I need to add extra code per match type:

if ($voucher["match_value"])
  {
    if ($voucher["match_type"]=="exact")
    {
      $where .= " AND ".$voucher["match_field"]." = '".database_safe($voucher["match_value"])."' ";
    }
    else
    {
      $where .= " AND ".$voucher["match_field"]." LIKE '%".database_safe($voucher["match_value"])."%' ";
    }
  }

Thanks

Chris

Submitted by support on Sat, 2013-01-19 11:15

Hi Chris,

Yes - that will be it - but luckily MySQL has REGEXP parsing built in. REPLACE the section that you identified as follows:

  if ($voucher["match_value"])
  {
    switch($voucher["match_type"])
    {
      case "exact":
        $where .= " AND ".$voucher["match_field"]." = '".database_safe($voucher["match_value"])."' ";
        break;
      case "keyword":
        $where .= " AND ".$voucher["match_field"]." LIKE '%".database_safe($voucher["match_value"])."%' ";
        break;
      case "regexp":
        $where .= " AND ".$voucher["match_field"]." REGEXP '".database_safe($voucher["match_value"])."' ";
        break;
      case "notregexp":
        $where .= " AND ".$voucher["match_field"]." NOT REGEXP '".database_safe($voucher["match_value"])."' ";
        break;
    }
  }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by chrisst1 on Tue, 2013-01-22 20:46

Hi David

Thanks for looking at that for us, all works fine.

Chris