You are here:  » Additional data to vouchers

Active Forum Topics


Additional data to vouchers

Submitted by sirmanu on Mon, 2018-09-10 15:18 in

Hi David.

I am looking for add new columns to pt_vouchers table.
I want to have a button which allow me to choose if a voucher is public or not (appearing into vouchers.php). Sometimes there are a lot of activated vouchers, but some of them are useless (by default would be yes).
Secondly, is any way to add a new field called landing_page into pt_vouchers or something like that? Some merchants provide a page where you can find more products promoted. I can show this information along the voucher code.

Thank you!

Submitted by support on Tue, 2018-09-11 12:18

Hi,

Check out this thread for a modification to add a specific link for the voucher code.

The mod as it stands would replace the link to search results for that voucher code (modification to vouchers.php line 17) however if you'd like to leave that as-is, you could just add the link to the description, in which case look for the following code at line 56:

      $vouchers[$k]["text"] .= " ".translate("using voucher code")." <strong>".$voucher["code"]."</strong>";

...and REPLACE with something like;

      $vouchers[$k]["text"] .= " ".translate("using voucher code")." <strong>".$voucher["code"]."</strong>";
      if ($voucher["link"])
      {
        $vouchers[$k]["text"] .= " <a href='".$voucher["link"]."'>More info...</a>";
      }

Let me know once that aspect is working how you'd like, and I'll work out the mods for an enable / disable checkbox...

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Thu, 2018-09-20 16:27

Easy peasy David. Working as expected.
Prior for the mod for an enable / disable checkbox, I would need another small modification.
I already have the filter_ccConfigure (pricetapestry.com/node/4910)

My site is all in euros. However, one merchant has their vouches codes at pounds. How can I add a new option in "discount type" for pounds? What solution do you think is feasible?

The idea is that the 'Minimum Spend' and 'Discount Value' that I introduce are in pounds just for this merchant. Then, tapestry_applyVoucherCodes should convert this currency, but I don't know how.
Thanks.

Submitted by support on Fri, 2018-09-21 10:19

Hi,

It should be straight forward to add a #GBP discount type but wanted to check a couple of things first;

- are you using voucher codes integration level 2? (discounts calculated at import time)

- does your filter_ccExec() function (includes/filter.php) contain this line;

      copy("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml",$filename);

...in which case, would you be able to modify and test by removing this line, and instead setting up an Automation Tool job to fetch

https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml

...and Save As:

cc_rates.xml

...in order that the real time conversion on the voucher codes page doesn't result in fetching the currency conversion feed every time?

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Fri, 2018-09-21 10:52

No, I always use voucher codes integration level 1 (on the flight) as sometimes some vouchers are cancelled and I must disable them without any delay.

Secondly. Ok, I have commented out that line. Nice trick. I'm waiting new instructions. Regards

Submitted by support on Fri, 2018-09-21 13:12

Great - have a go as follows to add the discount type "GBP"...

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

      else

...and REPLACE with:

      elseif ($voucher["discount_type"]=="G")
      {
        print "<td class='pta_num'>GBP".$voucher["discount_value"]."</td>";
      }
      else

Edit admin/voucher_codes_edit.php and look for the following code at line 414:

      $discount_types = array("#"=>html_entity_decode($config_currencyHTML,ENT_QUOTES,$config_charset),"%"=>"%","S"=>"Other");

...and REPLACE with:

      $discount_types = array("#"=>html_entity_decode($config_currencyHTML,ENT_QUOTES,$config_charset),"G"=>"GBP","%"=>"%","S"=>"Other");

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

          $isValid = TRUE;

...and REPLACE with:

          if ($voucher["discount_type"]=="G")
          {
            $filter_data = array("cc_from"=>"GBP","cc_to"=>"EUR");
            $voucher["min_price"] = filter_ccExec($filter_data,$voucher["min_price"]);
            $voucher["discount_value"] = filter_ccExec($filter_data,$voucher["discount_value"]);
            $voucher["discount_type"]="#";
          }
          $isValid = TRUE;

Edit vouchers.php and look for the following code at line 21:

        case "#":

...and REPLACE with:

        case "G":
          require_once("includes/filter.php");
          $filter_data = array("cc_from"=>"GBP","cc_to"=>"EUR");
          $voucher["discount_value"] = filter_ccExec($filter_data,$voucher["discount_value"]);
          $voucher["min_price"] = filter_ccExec($filter_data,$voucher["min_price"]);
          // pass through to case "#"
        case "#":

And finally edit includes/filter.php and look for the following code within the filter_ccExec() function:

      $filename = $config_feedDirectory."cc_rates.xml";

...and REPLACE with:

      $filename = $config_feedDirectory."cc_rates.xml";
      if (!file_exists($filename))
      {
        $filename = "feeds/cc_rates.xml";
      }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Fri, 2018-09-21 15:05

Thanks, but I get this error: "PHP Notice: Undefined variable: voucher in tapestry.php"

Should I move this code inside the next foreach?(foreach($tapestry_voucherCodes[$product["merchant"]] as $voucher)

{code saved}

Submitted by support on Fri, 2018-09-21 15:17

Spot on - sorry about that, i've corrected the modification above...

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Fri, 2018-09-21 15:24

Oki! I am testing. It seems that I need require_once (PHP Fatal error: Uncaught Error: Call to undefined function filter_ccExec()

          if ($voucher["discount_type"]=="G")
          {
            require_once("includes/filter.php");
            $filter_data = array("cc_from"=>"GBP","cc_to"=>"EUR");
            $voucher["min_price"] = filter_ccExec($filter_data,$voucher["min_price"]);
            $voucher["discount_value"] = filter_ccExec($filter_data,$voucher["discount_value"]);
            $voucher["discount_type"]=="#";
          }
          $isValid = TRUE;

Is this right?

Also, in voucher.php I need to convert min_price

        case "G":
          require_once("includes/filter.php");
          $filter_data = array("cc_from"=>"GBP","cc_to"=>"EUR");
          $voucher["discount_value"] = filter_ccExec($filter_data,$voucher["discount_value"]);
          $voucher["min_price"] = filter_ccExec($filter_data,$voucher["min_price"]);
          // pass through to case "#"

Submitted by support on Fri, 2018-09-21 15:29

Hi Marco,

Both look correct, if still no joy i'll re-create the scenario fully on my test server...

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Fri, 2018-09-21 15:43

Last bug!

$voucher["discount_type"]=="#";

Should be

$voucher["discount_type"]="#";

Submitted by support on Fri, 2018-09-21 15:48

One more thing...

The location of the cc_rates.xml file is incorrect when includes/filter.php is being included from vouchers.php. I've added this above but for completeness, in includes/filter.php within the filter_ccExec() function, where you have:

      $filename = $config_feedDirectory."cc_rates.xml";

...REPLACE with:

      $filename = $config_feedDirectory."cc_rates.xml";
      if (!file_exists($filename))
      {
        $filename = "feeds/cc_rates.xml";
      }

Let me know when all up and running, and I'll tidy up the above!

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Fri, 2018-09-21 16:10

I think that this wasn't affecting me, because my $config_feedDirectory variable is from the root

$config_feedDirectory = "/mnt/secondDisk/feeds/";

However, I am going to change it if for any reason I change this directory later on by a relative path.

Submitted by sirmanu on Mon, 2018-09-24 17:43

Let's keep improving voucher functionality to Price Tapestry!
Is it possible to add hour to the valid period and not just date?

Submitted by support on Tue, 2018-09-25 10:22

Hi,

To add HH:MM resolution to voucher code validity is reasonably straight forward as it is just stored as a UNIX timestamp value on the voucher codes table, so to do this, first edit includes/widget.php and look for the following code at line 181:

      $y_default = date("Y",$default);

...and REPLACE with:

      $y_default = date("Y",$default);
      $h_default = intval(date("H",$default));
      $i_default = intval(date("i",$default));

And then the following code at (now) line 191:

      $y_default = "";

...and REPLACE with:

      $y_default = "";
      $h_default = "";
      $i_default = "";

And then the following code at (now) line 244:

    print "</div>";

...and REPLACE with:

    print "<select name='".$name."_h' style='width:60px;float:left;'>";
    if ($null_option) print "<option>".$null_option."</option>";
    for($i=0;$i<=23;$i++)
    {
      $selected = ((($h_default!=="")&&($i==$h_default))?"selected='selected'":"");
      $v = sprintf("%02d",$i);
      print "<option value='".$v."' ".$selected.">".$v."</option>";
    }
    print "</select>";
    print "<select name='".$name."_i' style='width:60px;float:left;'>";
    if ($null_option) print "<option>".$null_option."</option>";
    for($i=0;$i<=59;$i++)
    {
      $selected = ((($i_default!=="")&&($i==$i_default))?"selected='selected'":"");
      $v = sprintf("%02d",$i);
      print "<option value='".$v."' ".$selected.">".$v."</option>";
    }
    print "</select>";
    print "</div>";

Edit admin/voucher_codes.php and look for the following beginning at line 279:

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

...and REPLACE with:

      print "<td class='pta_num'>".date("Y-m-d H:i",$voucher["valid_from"])."</td>";
      print "<td class='pta_mid'>".($voucher["valid_to"]?date("Y-m-d H:i",$voucher["valid_to"]):"-")."</td>";

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

      $time = strtotime($_POST["valid_from_y"]."-".$_POST["valid_from_m"]."-".$_POST["valid_from_d"]);

...and REPLACE with:

      $time = strtotime($_POST["valid_from_y"]."-".$_POST["valid_from_m"]."-".$_POST["valid_from_d"]." ".$_POST["valid_from_h"].":".$_POST["valid_from_i"]);

And finally the following code beginning at line 109:

      $time = strtotime($_POST["valid_to_y"]."-".$_POST["valid_to_m"]."-".$_POST["valid_to_d"]);
      if ($time==FALSE)
      {
        $_POST["valid_to"] = "";
        widget_errorSet("valid","invalid entry");
      }
      else
      {
        $_POST["valid_to"] = $time + 86399;
      }

...and REPLACE with:

      $time = strtotime($_POST["valid_to_y"]."-".$_POST["valid_to_m"]."-".$_POST["valid_to_d"]." ".$_POST["valid_to_h"].":".$_POST["valid_to_i"]);
      if ($time==FALSE)
      {
        $_POST["valid_to"] = "";
        widget_errorSet("valid","invalid entry");
      }
      else
      {
        $_POST["valid_to"] = $time;
      }

Note that when adding a new code the time will default to the current server time, but that's no problem as validity checking is always against a date/time in the future anyway; but bear in mind that when adding an expiry date, if not a specific hour / minute don't forget to select 23:59 to ensure all day validity...

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Wed, 2018-09-26 11:14

David, it is working. Thanks

Submitted by sirmanu on Fri, 2018-10-05 09:40

Next.
What about to add a checkbox to allow a voucher to be "public" or "displayable". I mean, I don't want to show all vouchers into vouchers.php, because some of them are not working properly (like the advanced matching of https://www.pricetapestry.com/node/5920).

Submitted by support on Sat, 2018-10-06 10:03

Hi,

To add a new `hidden` field / setting, run the following dbmod.php script from top level of the Price Tapestry installation;

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

Next, edit admin/voucher_codes_edit.php and look for the following code at line 170:

                      database_safe($_POST["valid_to"])

...and REPLACE with:

                      database_safe($_POST["valid_to"]),
                      ($_POST["hidden"]?"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("Hidden","hidden",FALSE,$_POST["hidden"]);

Finally edit vouchers.php and look for the following code at line 6:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."vouchers` WHERE ( (valid_from < '".$now."' AND valid_to = '0') OR (valid_from <= '".$now."' AND valid_to > '".$now."') ) ORDER BY merchant";

...and REPLACE with:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."vouchers` WHERE ( (valid_from < '".$now."' AND valid_to = '0') OR (valid_from <= '".$now."' AND valid_to > '".$now."') ) AND hidden='0' ORDER BY merchant";

Cheers,
David.
--
PriceTapestry.com