You are here:  » Voucher code exclusion


Voucher code exclusion

Submitted by sirmanu on Mon, 2020-11-23 12:31 in

Hi David.

I want to include a small modification into voucher code.

Currently it works great, but I want to add a new feature.

In my case, a merchant is giving a voucher code for all products, except some of them. So I want a new "Match Criteria" that excludes the products specified.

For instance

If I set:

#merchant => Merchant
#match_type => Exact Match (NOT) (*)
#match_field => name
#match_value => product 1, product 2, product 3

All the products from that merchant would be discounted except for product 1, product 2, product 3

(*) This would be new

Thank you!

Submitted by support on Tue, 2020-11-24 08:07

Hi,

To add an "Exact (NOT)" match type, first edit admin/voucher_codes_edit.php and look for the following code at line 377:

      $match_types = array("exact"=>"Exact Match","keyword"=>"Keyword Match");

...and REPLACE with:

      $match_types = array("exact"=>"Exact Match","exactn"=>"Exact Match (NOT)","keyword"=>"Keyword Match");

Edit admin/voucher_codes.php and look for the following code at line 240:

        $match_types = array("exact"=>translate("Exact Match"),"keyword"=>translate("Keyword Match"));

...and REPLACE with:

        $match_types = array("exact"=>translate("Exact Match"),"exactn"=>translate("Exact Match (NOT)"),"keyword"=>translate("Keyword Match"));

Edit includes/tapestry.php and look for the following code at line 196:

                  case "exact":

...and REPLACE with:

                  case "exactn":
                    if ($product[$voucher["match_field"]] != $match_value)
                    {
                      $matched = TRUE;
                    }
                    break;
                  case "exact":

And finally edit search.php and look for the following code at line 198:

                if ($voucher["match_type"]=="exact")

...and REPLACE with:

                if ($voucher["match_type"]=="exactn")
                {
                  $match_wheres[] = " ".$voucher["match_field"]." <> '".database_safe($match_value)."' ";
                }
                elseif ($voucher["match_type"]=="exact")

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Tue, 2020-11-24 13:41

Thank you David! It is awesome how easy is to add features into your software.

But the code provided didn't work at first, because in product details pages, almosts all products were getting discount. The fact is that when you make $matched = True, you don't check sequent products.

I put this code before foreach (and removed the switch for "exactn")

              if (
                $voucher["match_type"] == 'exactn' &&
                $product[$voucher["match_field"]] &&
                !in_array($product[$voucher["match_field"]], $match_values)
              ) {
                  $matched = TRUE;
              }

What do you think? Can be improved?

Submitted by support on Wed, 2020-11-25 08:06

Thank you for your comments!

That alt looks fine - only very minor thing, for efficiency you could put the following foreach(...) block inside an else { } as it doesn't have to be executed if match_type is "exactn", that's all...

Cheers,
David.
--
PriceTapestry.com