You are here:  » Add a field for voucher link


Add a field for voucher link

Submitted by dlw on Mon, 2015-11-30 19:08 in

Hi David,

I would like to have the button for vouchers go to a specific affiliate link instead of to a particular product. That link is usually included in the voucher feeds I have set up. I tried the mod you suggested of using the description field for the link, but that's just not working for me because some vouchers need the description field as well.

I'm assuming I would need to add a field to one or more of the database tables and then modify some backend pages and the voucher display page, but I'm not quite sure how to proceed. I'm hoping you can help.

Thanks.

Submitted by support on Tue, 2015-12-01 09:51

Hi,

First step is to add the custom field "link" to the vouchers table. To do this, run the following dbmod.php script in the top level folder of your Price Tapestry installation and then delete the file:

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

The to add the field to the edit voucher code form, in admin/voucher_codes_edit.php look for the following code around line 165:

                      valid_to = '%s'

...and REPLACE with:

                      valid_to = '%s',
                      link = '%s'

Then look for the following code around line 178:

                      database_safe($_POST["valid_to"])

...and REPLACE with:

                      database_safe($_POST["valid_to"]),
                      database_safe($_POST["link"])

And to add the form field, look for the following code around line 445:

    print "</fieldset>";

...and REPLACE with:

      widget_textBox("Link","link",FALSE,(isset($_POST["link"]) ? $_POST["link"] : ""),"",12);
    print "</fieldset>";

(this will insert the Link field immediately below the Valid / Until field)

Finally, to use the link on the front-end instead of the link to search results for the voucher code, in vouchers.php look for the following code at line 17:

      $vouchers[$k]["href"] = $config_baseHREF."search.php?q=voucher:".urlencode($voucher["merchant"]).":".urlencode($voucher["code"]);

...and REPLACE with:

      if ($voucher["link"])
      {
        $vouchers[$k]["href"] = $voucher["link"];
      }
      else
      {
        $vouchers[$k]["href"] = $config_baseHREF."search.php?q=voucher:".urlencode($voucher["merchant"]).":".urlencode($voucher["code"]);
      }

Cheers,
David.
--
PriceTapestry.com

Submitted by dlw on Sat, 2015-12-05 09:01

Thanks! It works perfectly.

Submitted by bat on Wed, 2017-02-01 10:41

Hi David,
Will this work ok for 15/09A beta?

Submitted by support on Wed, 2017-02-01 10:48

Hello bat,

Yes - good for all beta and current distributions.

Cheers,
David.
--
PriceTapestry.com

Submitted by bat on Wed, 2017-02-01 12:04

Thanks David.
Where you've put the custom affiliate link to be a complete replacement for the link to search results when someone clicks View Products on voucher page, is there any way you it can be done where View Products button points to its normal search results only if the Link field in edit voucher codes is empty?
Only a couple of my merchants use links for their voucher code offers, you see.

many thanks

Submitted by support on Wed, 2017-02-01 12:14

Hello bat,

Sure - instead of the last replacement described above, at line 17 of vouchers.php, have a go with:

      if ($voucher["link"])
      {
        $vouchers[$k]["href"] = $voucher["link"];
      }
      else
      {
        $vouchers[$k]["href"] = $config_baseHREF."search.php?q=voucher:".urlencode($voucher["merchant"]).":".urlencode($voucher["code"]);
      }

Cheers,
David.
--
PriceTapestry.com

Submitted by dlw on Wed, 2021-09-08 03:33

David, I followed these directions and I can add a link if I'm adding coupons manually, but what about the coupon feed? When I list the coupons and click Add, it does not automatically fill the link field with the link. How can I fix that? It's just a minor thing, but it would save some time in copy/pasting. Also, would it be possible to have it automatically fill the "Description (for discount type "Other")" field with the coupon offer? Thanks in advance.

Submitted by support on Wed, 2021-09-08 09:33

Hi,

To populate "link" and "description" automatically (with discount type "Other"), edit voucher_codes_edit.php and look for the following code at line 289:

      if (isset($voucherfeed["field_valid_from"]))

...and REPLACE with:

      if (isset($voucherfeed["field_valid_from"]))
      if (isset($voucherRecord["link"]))
      {
        $_POST["link"] = $voucherRecord["link"];
        $_POST["discount_type"] = "S";
        $_POST["discount_text"] = $voucherRecord[$voucherfeed["field_description"]];
      }

Cheers,
David.
--
PriceTapestry.com

Submitted by dlw on Wed, 2021-09-08 23:58

That doesn't seem to be working. I don't think link and discount_text is being posted from voucher_feeds_list.php.

Submitted by support on Thu, 2021-09-09 07:58

Hi,

Sorry I should have noted the "link" as in;

       if (isset($voucherRecord["link"]))

...assumes that the link field is actually called "link" in the feed. If it's actually, for example "url" then the above line of the mod would need to be:

       if (isset($voucherRecord["url"]))

Cheers,
David.
--
PriceTapestry.com