You are here:  » enhanced voucher code functionality


enhanced voucher code functionality

Submitted by karakartal on Sun, 2011-07-03 22:26 in

Hi David,

Some vouchers/coupons do not have very trivial redemption instructions. This confuses people. I want to add a new field in the coupon creation inferface which I can use to add instructions. These instructions will then be displayed in a new small window which will pop up after the visitor clicks the "buy now" button for that merchant. Do you have some codes you can share with me ?

Submitted by support on Mon, 2011-07-04 20:05

Hello karakartal,

There's quite a bit involved here - to start with, could you use the "Discount Text" field to enter your instructions?

If that's possible, the first step would be to remove the automatic appending of the Discount Text to the voucher code. In includes/tapestry.php, look for the following code at line 227:

$product["voucher_code"] .= " (".$voucher["discount_text"].")";

...and either comment out or delete that line.

Then look for the following code at line 237:

          $products[$k]["voucher_code"] = $product["voucher_code"];

...and REPLACE with:

          $products[$k]["voucher_code"] = $product["voucher_code"];
          $products[$k]["discount_text"] = $voucher["discount_text"];

Next, code could be added to the tapestry_buyURL function that generates a JavaScript alert containing the Discount Text when the link is clicked. To try this, in the same file look for the following code beginning at line 83:

    if ($config_useTracking)
    {
      return $config_baseHREF."jump.php?id=".$product["id"];
    }
    else
    {
      return $product["buy_url"];
    }

...and REPLACE with:

    if ($config_useTracking)
    {
      $retval = $config_baseHREF."jump.php?id=".$product["id"];
    }
    else
    {
      $retval = $product["buy_url"];
    }
    if ($product["discount_text"])
    {
      $retval .= "' onclick='JavaScript:alert(\"".$product["discount_text"]."\");";
    }
    return $retval;

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by gregor on Sun, 2011-08-07 21:30

I tried this mod and I think there is a minor problem. I believe this code ....
$products[$k]["discount_text"] = $product["discount_text"];

should be ....
$products[$k]["discount_text"] = $voucher["discount_text"];

It's a good mod that gives some flexibility. Thanks!

Submitted by support on Mon, 2011-08-08 08:56

Thanks Gregor, corrected above...

Cheers,
David.
--
PriceTapestry.com

Submitted by richard on Mon, 2016-07-11 14:50

Hi David

I have tried this mod in v1509 but I do not see the alert. Do the above instructions apply to v1509?

Best regards,

Richard

Submitted by support on Mon, 2016-07-11 15:07

Hi Richard,

I worked through above on my test server against 15/09A and works fine but bear in mind that it would apply only for Voucher Code integration level 1 ($config_useVoucherCodes = "1"; in config.advanced.php).

If you are using integration level 2, where voucher code discounts are calculated at import time and the `voucher_code` field populated in the products table then with the above in place import would actually fail since the process of applying voucher codes would create a new field "discount_text" (the text to be displayed in the pop-up) which would become part of the SQL.

However, if you hadn't yet tried a re-import and were not therefore seeing the above occur, simply adding the new `discount_text` field to the products table is all you need to do (and then followed by an import of any affected feeds). The dbmod.php script to run is as follows;

<?php
  
require("includes/common.php");
  
$sql "ALTER TABLE `".$config_databaseTablePrefix."products`
            ADD `discount_text` VARCHAR(255) NOT NULL"
;
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by richard on Mon, 2016-07-11 15:18

Hi David,

Many thanks.

I am using level 2 integration. I did not have the problem when I imported feed as I already had extra field.

Is there a solution for level 2 integration?

Best regards,

Richard

Submitted by support on Tue, 2016-07-12 09:15

Sorry Richard,

I wasn't clear in my reply - the dbmod.php to add the `discount_text` field should be all that is required for the above to work with level 2 integration. Could you perhaps double check in the database (e.g. using phpMyAdmin) and look at a product for which you have added pop-up text to display and confirm that this is shown in the `discount_text` field?

That will confirm whether the problem is at import time, or do with the actual alert display itself; alternatively, another check you could do is to browse to a product page from which you are expecting the alert and use your browser's View > Source option and then search the page source for "JavaScript:alert". If that is present that would indicate that the JavaScript is not being invoked for some reason. Once possibility is that your template is enclosing the Buy URL field in double-quotes. In order to put the onclick JavaScript in line, the above code closes the href attribute with a single quote, and then leaves the onclick attribute unclosed, since this is closed by the template (which is only expecting a URL at this point).

If that looks like the case and you need to use double-quoted attributes instead, in place of this line:

  $retval .= "' onclick='JavaScript:alert(\"".$product["discount_text"]."\");";

...use:

  $retval .= "\" onclick=\"JavaScript:alert('".$product["discount_text"]."');";

Cheers,
David.
--
PriceTapestry.com

Submitted by richard on Tue, 2016-07-12 10:10

Perfect, many thanks David.