You are here:  » How to add Time to expiration date on Voucher Codes

Support Forum



How to add Time to expiration date on Voucher Codes

Submitted by Convergence on Thu, 2012-08-30 14:26 in

Greetings,

Discovering more and more merchants stating a TIME on their Voucher Codes.

Example:

"until 09/03/2012 at 9:00PM EST"

Is there a way we can add a time to the expiration date based on the server time?

Thanks!

Submitted by support on Thu, 2012-08-30 15:53

Hi,

This is straight forward since the dates are stored as time() values in the database so no changes required there.

Firstly, to add hour of day to the date widget, look for the following code at line 77 includes/widget.php

    print "</select>";

...and REPLACE with:

    print "</select>";
    $h_default = ($default?@date("G",$default):"");
    print "<select name='".$name."_h'>";
    if ($null_option) print "<option>".$null_option."</option>";
    $y_from = 0;
    $y_to = 23;
    for($i=$y_from;$i<=$y_to;$i++)
    {
      if($h_default) $selected = ($i==$h_default?"selected='selected'":"");
      print "<option value='".($i*3600)."' ".$selected.">".sprintf("%02d:00",$i)."</option>";
    }
    print "</select>";

Next look for the following code at line 80 admin/voucher_codes_edit.php

    $_POST["valid_from"] = $time;

...and REPLACE with:

    $_POST["valid_from"] = $time + (($_POST["valid_from_h"]<>"-")?$_POST["valid_from_h"]:86399);

Next look for the following code at line 96 admin/voucher_codes_edit.php

    $_POST["valid_to"] = $time + 86399;

...and REPLACE with:

    $_POST["valid_to"] = $time + (($_POST["valid_to_h"]<>"-")?$_POST["valid_to_h"]:86399);

And finaly look for the following code at line 93 admin/voucher_codes.php

      print "<td align='center'>".@date("Y-m-d",$voucher["valid_from"])."</td>";
      print "<td align='center'>".($voucher["valid_to"]?@date("Y-m-d",$voucher["valid_to"]):"-")."</td>";

...and REPLACE with:

      print "<td align='center'>".@date("Y-m-d H:00",$voucher["valid_from"])."</td>";
      print "<td align='center'>".($voucher["valid_to"]?@date("Y-m-d H:00",$voucher["valid_to"]):"-")."</td>";

Cheers,
David.
--
PriceTapestry.com

Submitted by BobL on Wed, 2012-10-31 15:17

Bob L.

Hi David.
If I leave the print ""; @ line 77 includes/widget.php
And insert the code below that.
it works for me without giving a lot of error codes.

Is it also possible to set a voucher based on a merchant site wide % off on all products?

Submitted by support on Wed, 2012-10-31 16:22

Hello Bob,

Sure - as you create the new Voucher Code, select the merchant, leave he match fields at default and enter 0.00 as the Minimum Spend, select discount type % and enter the value and that should do the trick!

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Mon, 2012-11-12 15:35

Hi David,

As Bob mentionet about the code for includes/widget.php - the print "</select>"; should remain at the bottom.

Quick question about the mod:

In config.advanced.php we have " $config_useVoucherCodes = 2;" - will the voucher code be removed from our website once the expiration TIME on the expiration date is met? Or, will it only be removed when the next import occurs.

Merchants are wanting expired codes removed immediately upon expiration date/time.

Thanks!

Submitted by support on Mon, 2012-11-12 15:53

Hi,

When using Level 2 integration voucher codes are only removed if expired at import time, so it is important that your automation freqency is sufficient - i.e. daily to ensure that codes are removed upon expiry.

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Mon, 2012-11-12 16:18

Oops - meant to say print "</select>"; should remain at the TOP and not bottom.

Submitted by Convergence on Mon, 2012-11-12 16:24

Hi David,

Thank you for your prompt response.

Unfortunately, there is no way for us to import feeds before every possible voucher code expiration "time". (We currently import 200 feeds twice a day).

We need to use the Level 2 Voucher Code setting so discounted prices show within each module.

Is there a way to show the expiration date as text on the product page when an expiration date/time is set? (Other than in the "Discount Text" field.)

Thanks!

Submitted by support on Mon, 2012-11-12 16:55

Hi,

Code updated, thanks!

When i'm back in the office tomorrow I'll work out a mod to enable a daily cron job to purge expired voucher codes independently of the import process which should do the trick...

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Mon, 2012-11-12 17:17

Hi David,

GREAT! Then we can run the cron hourly for each time zone...

Submitted by support on Tue, 2012-11-13 10:05

Hi,

The most straight forward implementation of this will require 2 additional fields on the `products` table - voucher_original_price (original price prior to computed voucher code discount) and voucher_valid_to (a copy of the valid_to field from the vouchers table).

Firstly, a dbmod.php script to add the new fields:

<?php
  
require("includes/common.php");
  
$sql "ALTER TABLE `".$config_databaseTablePrefix."products`
            ADD `voucher_original_price` DECIMAL(10,2) NOT NULL,
            ADD `voucher_valid_to` INT(11) NOT NULL
            "
;
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

After creating the file, upload to the main Price Tapestry installation folder and browse to dbmod.php once, then delete the file.

Then to populate these fields as voucher codes at level 2 integration are applied during import; look for the following code beginning at line 233 in includes/tapestry.php:

        if ($product["discount_price"] <= $product["price"])
        {
          $products[$k]["price"] = $product["discount_price"];
          $products[$k]["voucher_code"] = $product["voucher_code"];
        }

...and REPLACE with:

        if ($product["discount_price"] <= $product["price"])
        {
          $products[$k]["voucher_original_price"] = $product["price"];
          $products[$k]["voucher_valid_to"] = $voucher["valid_to"];
          $products[$k]["price"] = $product["discount_price"];
          $products[$k]["voucher_code"] = $product["voucher_code"];
        }

Finally, a script that may be executed at any time to purge expired voucher codes and reset the price back to voucher_original_price can be implemented as a single query as follows. Create the following script as scripts/purgevc.php:

<?php
  set_time_limit
(0);
  require(
"../includes/common.php");
  
$sql "UPDATE `".$config_databaseTablePrefix."products` SET
            price = voucher_original_price,
            voucher_code = '',
            voucher_valid_to = '0'
          WHERE voucher_valid_to BETWEEN 1 AND "
.time();
  
database_queryModify($sql,$result);
  exit();
?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com