You are here:  » Custom Vouchers on Voucher page.


Custom Vouchers on Voucher page.

Submitted by Rocket32 on Sat, 2013-11-23 16:44 in

Is it possible to add vouchers for unregistered merchants to the voucher page or site?

Submitted by support on Sun, 2013-11-24 10:15

Hi Rocket32,

The most straight forward way would be to add to the $coupons["vouchers"] array with custom entries, so they will be displayed by html/coupons.php in exactly the same format as database voucher codes. To do this, simply create a new file in the top level called voucherscustom.php containing the following:

<?php
  $coupons
["vouchers"][] = array(
    
"href" => "http://www.example.com",
    
"merchant" => "Example.com",
    
"text" => "Save 10% when you spend over £100 using voucher code ABC1234"
    
);
  
$coupons["vouchers"][] = array(
    
"href" => "http://www.example.net",
    
"merchant" => "Example.net",
    
"text" => "£25 off when you spend over £1000 using voucher code ZZZ999"
    
);
?>

And then in vouchers.php look for the following code at line 64:

  require("html/coupons.php");

...and REPLACE with:

  require("voucherscustom.php");
  require("html/coupons.php");

This would give the maximum flexibility without restricting you to the calculational requirements of database voucher codes; but if that wouldn't be a problem then it should be straight forward to create a "virtual" custom merchant via which you can use the same interface to add codes manually.

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Thu, 2013-11-28 06:01

Hey David. Is there any way to make this work with a coupon feed as stated in http://www.pricetapestry.com/node/2076? You assisted me in creating a coupon page with navigation. I am wondering is there a way to make this custom voucher page work along with my vouchers.php page or added to the page navigation. I am trying to see if there may an easier way to place them on page instead of manually when a feed is involved and combine the two(custom voucher feed page & original vouchers.php) some how with navigation structure.

Thanks,
Roy

Submitted by support on Thu, 2013-11-28 09:13

Hello Roy,

If you go with vouchers.php as the starting point; look for the following code at line 54:

  $banner["h2"] = "<strong>".translate("Voucher Codes")."</strong>";

At this point, the $coupons array will have been populated with the default database voucher codes. To then add additional codes from your feed, REPLACE with the following code, based on the last example in note 2076:

  require("includes/MagicParser.php");
  $page = (isset($_GET["page"])?intval($_GET["page"]):"1");
  function myRecordHandler($item)
  {
    global $coupons;
    $coupon = array();
    $coupon["merchant"] = $item["TITLE"];
    $coupon["href"] = $item["LINK"];
    $coupon["text"] = $item["DESCRIPTION"];
    $coupons[] = $coupon;
  }
  $url = "{link saved}";
  $xml = file_get_contents($url);
  MagicParser_parse("string://".$xml,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  $navigation["resultCount"] = count($coupons);
  // unset $coupons not within current page scope
  $counter = 0;
  foreach($items as $k => $v)
  {
    $counter++;
    if (
       ($counter <= (($page-1)*$config_resultsPerPage))
       ||
       ($counter >= ($page*$config_resultsPerPage))
       )
    {
      unset($coupons[$k]);
      continue;
    }
  }
  $banner["h2"] = "<strong>".translate("Voucher Codes")."</strong>";

And then to display the navigation bar just before the footer, look for the following code at line 66:

  require("html/footer.php");

...and REPLACE with:

  $rewrite = FALSE;$q = "";$sort="";
  require("html/navigation.php");
  require("html/footer.php");

Should be close!

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Wed, 2014-08-13 00:58

Hi David. This custom voucher mod works for the rss coupon feed. Can this mod work for a coupon feed that has all the values in a comma separated .txt file containing several merchants & vouchers. I would be using the automation tool to download feed in /voucherfeeds folder. The file has some merchants that are registered on the PT site already, but there are other unregistered merchants in same file that I would like to use the custom voucher code feature. Also the voucher feed has a clickable link to merchant's voucher offer. I think a merchantlink field may need to be registered. Would this require a merchantlink dmod for unregistered merchants or registered? Also would an unregistered merchant dmod be needed?

Submitted by support on Wed, 2014-08-13 09:02

Hi Roy,

Sure - the same technique can be used to show vouchers from any feed format. After applying the above modification you will have this line in your code:

   $navigation["resultCount"] = count($coupons);

The place to add code to parse additional feeds is immediately before this point, e.g.

  $excludeMerchants = array("Merchant 1","Merchant 2","Merchant 3");
  function myRecordHandler2($item)
  {
    global $coupons;
    global $excludeMerchants;
    if (in_array($item["MERCHANT"],$excludeMerchants)) return;
    $coupon = array();
    $coupon["merchant"] = $item["MERCHANT"];
    $coupon["href"] = $item["LINK"];
    $coupon["text"] = $item["DESCRIPTION"];
    $coupons[] = $coupon;
  }
  $filename = "voucherfeeds/filename.csv";
  $csv = file_get_contents($filename);
  MagicParser_parse("string://".$csv,"myRecordHandler2","FORMAT_STRING");

Notice the renamed record handler function "myRecordHandler2" to avoid conflicting with the RSS version above.

Replace filename.csv with the filename of your feed in the voucherfeeeds/ folder, and edit the merchant names Merchant 1, Merchant 2 etc. in the $exludeMerchants array to exactly match the merchant names from the feed that correspond to merchants already on your site and therefore will be using the built in voucher code functionality (this way it doesn't matter if the merchant names in the voucher feed don't exactly match the names you use on your site).

Finally, before uploading go to the Voucher Codes page in Admin and click Register alongside the feed. Copy the auto-detected format string and use it to replace FORMAT_STRING in the above code. Click Next to go to Step 2, and from the Sample Data locate the appropriate field names corresponding to the merchant name, link and description and use them to replace MERCHANT, LINK and DESCRIPTION in the above code.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com