You are here:  » Custom field into vouchers.php


Custom field into vouchers.php

Submitted by chrisst1 on Mon, 2012-12-17 16:44 in

Hi David

I am trying to get custom db data (merchant url_link) from the feeds table for each voucher code displayed in vouchers.php, I've tried adding a previous old mod but can't seem get it to work. Below is my functioning code without any extra queries, could you have a look please.

Thanks
Chris

{code saved}

Submitted by support on Tue, 2012-12-18 09:14

Hi Chris,

Towards the end of your working code where you have:

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

...try something like this:

      // get url_link from feeds table
      $sql2 = "SELECT url_link FROM `".$config_databaseTablePrefix."feeds` WHERE merchant='".database_safe($voucher["merchant"])."'";
      if (database_querySelect($sql2,$rows2))
      {
        $vouchers[$k]["url_link"] = $rows2[0]["url_link"];
      }
      else
      {
        $vouchers[$k]["url_link"] = "";
      }

Then in your html/coupons.php you can use url_link if set as required; either standalone or as a replace for $voucher["href"] perhaps - let me know if you're not sure...

Cheers,
David.
--
PriceTapestry.com

Submitted by chrisst1 on Tue, 2012-12-18 16:43

Thanks David

That did the trick, couple of misprints (`".$config) and (feeds`) I think.

$sql2 = "SELECT url_link FROM `".$config_databaseTablePrefix."feeds` WHERE merchant='".database_safe($voucher["merchant"])."'";

For future referance, if I wanted to query another table in addition to the above would it be a case of changing sql2 & rows2 to sql3 & rows3 for the new query?

If I don't post again this year have a Merry Christmas and a Happy New Year David, your help and support over the past twelve months (and the 5yrs before) has been very much appreciated, thanks.

Best Wishes
Chris

Submitted by support on Wed, 2012-12-19 08:40

Hi Chris,

Thanks for your comments and seasons greetings likewise!

For additional queries, you can simply reuse $sql2 and $rows2 - I normally use "2" variables in examples just incase the code is being used where an existing query using $sql and $rows may be in context - that's all!

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Thu, 2014-08-14 04:27

Hello David. I have a voucher file that I would like to use a url field for links in feed. It comes with a field to click to receive offer on the merchant's site.

I already created a field in the vouchers table named link.
I added following to cofigadvanced.php;

$config_voucherCodesFieldSet["link"] = "Link"

$config_voucherCodesCommonFields["link"] =
array("url");

If possible could the link be attached to the merchant/logo link or add something like click here for offer.

Submitted by support on Thu, 2014-08-14 08:29

Hi Roy,

To change the logo / merchant name link to your new `link` field, in html/coupons.php look for the following code at line 15:

  <a href='<?php print $voucher["href"]; ?>'>

...and REPLACE with:

  <a href='<?php print $voucher["link"]; ?>'>

If you wish to add a text link as well, for example after the description; look for the following code at line 23:

  <p><?php print $voucher["text"]; ?></p>

...and REPLACE with:

  <p><?php print $voucher["text"]; ?> <a href='<?php print $voucher["link"]; ?>'>Click here for offer</a></p>

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Tue, 2014-08-19 11:24

Hello David. I tried above code & the link takes me to homepage of PT site & not to the link registered in vouchers.php.

Submitted by support on Tue, 2014-08-19 11:30

Hi Roy,

Second replacement corrected above - PHP tags were required at that point...

Cheers,
David.
--
PriceTapestry.com

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

I'm still missing something. I do not have the initial code used for getting merchant link in product feeds table that was used and where to insert it. I am trying to use the merchant coupon link located inside voucher feed. I think I need to register these links somehow. In step 1 when it registers and list, the link is available and registered. But on the edit voucher page I do not see it. Also I see the link field in vouchers table in database for each voucher, but its empty. The only modification I used so far is the config.advanced.php and the /html/coupons.php.

When I click on link, it still takes me to homepage.

Submitted by support on Wed, 2014-08-20 06:05

Hi Roy,

The following changes should complete the process. In admin/voucher_codes_edit.php look for the following code at line 130:

                      valid_to = '%s'

...and REPLACE with:

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

Then look for the following code at line 142:

                      database_safe($_POST["valid_to"])

...and REPLACE with:

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

Then look for the following code at line 264:

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

...and REPLACE with:

  if (isset($voucherfeed["field_link"]))
  {
    $_POST["link"] = $voucherRecord[$voucherfeed["field_link"]];
  }
  if (isset($voucherfeed["field_valid_to"]))

And the final change, in admin/voucher_feeds_register_step3.php look for the following code at line 46:

  field_valid_to = '".database_safe($_POST["field_valid_to"])."',

...and REPLACE with:

  field_valid_to = '".database_safe($_POST["field_valid_to"])."',
  field_link = '".database_safe($_POST["field_link"])."',

Some of the above you may already have in place but should be a complete modification to register a "link" field and populate the "link" field in `pt_vouchers`. It not already in place the new fields required would be pt_voucherfeeds.field_link and pt_vouchers.link. The following dbmod.php script will create these fields if not in place:

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

Hope this helps!

Cheers,
David.
--
PriceTapestry.com