You are here:  » Apply Voucher Codes Ony to Non Discounted Products


Apply Voucher Codes Ony to Non Discounted Products

Submitted by ChrisNBC on Fri, 2017-09-22 22:00 in

Hi David,

I’m really getting into voucher codes now but have come across an issue…I have a number of voucher codes where the merchant stipulates they are not to be applied to already discounted products.

Because, my site config is $config_useVoucherCodes = 2 there is no existing way to prevent the voucher discounts being applied to already discounted products.

I searched the forum for a solution but couldn’t spot anything and wondered if you might know if there is an existing solution on the forum to this issue?

If not, I wondered if it might be feasible to add a flag to the voucher code set up which would then only apply a voucher code to price if price is equal to or greater than RRP.

Would be grateful for any suggestions you might have.

Thanks in advance.

Bets regards
Chris

Submitted by support on Sat, 2017-09-23 09:26

Hi Chris,

Sure - based on your modified code from this comment, where you now have:

    if ($config_useVoucherCodes == 2)
    {
      $importRecordArray = tapestry_applyVoucherCodes(array($importRecord));
      $importRecord = $importRecordArray[0];
    }

...REPLACE with:

    if (
       ($config_useVoucherCodes == 2)
       &&
       (($importRecord["normalprice"] != "0.00") && ($importRecord["price"] >= $importRecord["normalprice"]))
       )
    {
      $importRecordArray = tapestry_applyVoucherCodes(array($importRecord));
      $importRecord = $importRecordArray[0];
    }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Sat, 2017-09-23 23:44

Hi David,

Thanks for the mod above which. Sorry, I should have been clearer in my initial post....I only need to apply the voucher code rule to some voucher codes. If I understand correctly the above will apply the rule to all voucher codes. Would it be possible to add a flag (tick box maybe) to the voucher code set up and to include it in the code above so that the rule could be switched on or off for per voucher code?

Thanks in advance.

Best regards
Chris

Submitted by support on Mon, 2017-09-25 08:48

Hi Chris,

Ah no problem - instead of the above modification then, first to add new `non_discounted` field to the voucher codes table run the following dbmod.php script from the top level folder of your Price Tapestry installation;

<?php
  
require("includes/common.php");
  
$sql "ALTER TABLE `".$config_databaseTablePrefix."vouchers`
            ADD `non_discounted` INT(11) NOT NULL"
;
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

And then edit admin/voucher_codes_edit.php and look for the following code at line 157:

                      valid_to = '%s'

...and REPLACE with:

                      valid_to = '%s',
                      non_discounted = '%s'

And then the following code at line 170:

                      database_safe($_POST["valid_to"])

...and REPLACE with:

                      database_safe($_POST["valid_to"]),
                      (isset($_POST["non_discounted"])?"1":"0")

And then the following code at line 434:

      widget_date("Until","valid_to",(isset($_POST["valid_to"]) ? $_POST["valid_to"] : ""),"-");

...and REPLACE with:

      widget_date("Until","valid_to",(isset($_POST["valid_to"]) ? $_POST["valid_to"] : ""),"-");
      widget_checkBox("Non Discounted Only","non_discounted",FALSE,$_POST["non_discounted"]);

That will enable the checkbox "Non Discounted Only" on voucher codes edit page, and then to apply the validity, edit includes/tapestry.php and look for the following code at line 158:

          $isValid = TRUE;

...and REPLACE with:

          $isValid = TRUE;
          if ($isValid)
          {
            if (
               ($voucher["non_discounted"])
               &&
               (($product["normalprice"] != "0.00") && ($product["price"] < $product["normalprice"]))
               )
            {
              $isValid = FALSE;
            }
          }

Hope this helps!
Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Tue, 2017-09-26 08:55

Thanks David, The code above works beautifully!

Best regards
Chris