You are here:  » Merchant Coupons Page


Merchant Coupons Page

Submitted by Rocket32 on Thu, 2015-09-24 11:18 in

Hellow David,
I am trying to create a Merchants coupon page that shows all the merchants and additional custom merchants to select from that will take visitor to the coupon results only from that merchant selected. How can I accomplish this with a page like the current merchants page?

Submitted by support on Thu, 2015-09-24 12:52

Hi,

The first step would be to put add support for a merchant filter on vouchers.php. To do this, 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:

  $merchant = (isset($_GET["merchant"])?$_GET["merchant"]:"");
  $where = "( (valid_from < '".$now."' AND valid_to = '0') OR (valid_from <= '".$now."' AND valid_to > '".$now."') )";
  if ($merchant)
  {
    $where .= " AND merchant='".database_safe($merchant)."' ";
  }
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."vouchers` WHERE ".$where." ORDER BY merchant";

With that in place, for your merchants > vouchers page, start with a copy of merchants.php and replace the creation of the "href" value with the link to the vouchers page for that merchant. To do this, look for the following code beginning at line 21:

      if ($config_useRewrite)
      {
        $item["href"] = urlencode(tapestry_hyphenate($product["merchant"]))."/";
      }
      else
      {
        $item["href"] = "search.php?q=merchant:".urlencode($product["merchant"]).":";
      }

...and REPLACE with:

      $item["href"] = $config_baseHREF."vouchers.php?merchant=".urlencode($product["merchant"]);

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Thu, 2015-09-24 23:11

It works fine with registered coupons. The problem is it is displaying all the api results added to the coupons page from node/5733. I would like it to display registered merchants or merchants from the api call for the merchant selected from the couponmerchants.php page created. Also how do I add a custom merchant not registered from api call to the couponmerchants.php page?

Submitted by support on Fri, 2015-09-25 07:46

Hi,

If you modify the parsing code to also use the merchant filter value that should solve both problems in one go. For each of your parsing functions where you have the last line that populates the global $coupons variable...

    $coupons["vouchers"][] = $voucher;

...check if $merchant is set, and if so only add the voucher to the $coupons array if it is for the selected merchant, e.g.

    global $merchant;
    if ((!$merchant) || ($merchant==$voucher["merchant"]))
    {
      $coupons["vouchers"][] = $voucher;
    }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Sat, 2015-09-26 22:18

It all works fine now except during navigation. When I go to page 2 on navigation, all other coupons are populated instead of selected Merchant's 2nd coupon page of results.

The following code is used for counting

<?php
   
global $merchant;
     if ((!
$merchant) || ($merchant==$voucher["merchant"]))
     {
       
$coupons["vouchers"][] = $voucher;
     }
  }
  if (
count($coupons["vouchers"]))
  {
    
$navigation["resultCount"] = count($coupons["vouchers"]);
    
$pageVouchers = array();
    
$counter 0;
    foreach(
$coupons["vouchers"] as $voucher)
    {
    global 
$page;
    global 
$config_resultsPerPage;
    global 
$counter;
      
$counter++;
      if (
         (
$counter <= (($page-1)*$config_resultsPerPage))
         ||
         (
$counter > ($page*$config_resultsPerPage))
         )
         continue;
      
$pageVouchers[] = $voucher;
    }
    
$coupons["vouchers"] = $pageVouchers;
     
$banner["h2"] = "<strong>".translate("Pet Supply Coupon Codes")."</strong>";
  }
    if (
count($coupons["vouchers"])) 
?>

Submitted by support on Sun, 2015-09-27 09:24

Hi,

You could pass the merchant value through navigation.php using the sort parameter, so where you have:

  require("html/navigation.php");

...REPLACE with:

  $sort = "&merchant=".urlencode($merchant);
  require("html/navigation.php");

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Fri, 2015-11-13 05:00

Hello David. How do I get the new merchantcoupons.php page to show only custom merchants or merchants with vouchers on vouchers.php page? Also is there a way when someone clicks on a merchant's link on the merchantcoupons.php page that does not have vouchers, they be taken to that merchants original merchant link from merchants.php? Right now it shows an error when clicking on it.

Submitted by support on Fri, 2015-11-13 08:45

Hi,

Sure - in your new merchantcoupons.php, look for the existing SELECT SQL (currently based on the merchants.php version) at line 6:

  $sql = "SELECT DISTINCT(merchant) FROM `".$config_databaseTablePrefix."products` ORDER BY merchant";

...and REPLACE with:

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

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by support on Mon, 2015-11-16 09:06

Hi Rocket32,

I'm afraid accidentally lost some posts whilst re-arranging some old threads and I recall you had posted a follow up here to the above post but I'm afraid I lost the comment - if you're still not sure please could you re-post your question and I'll check it out right away...

I also noticed you had posted a comment on the multi-language thread - I'm going to double check the code on my test server right now, but in the mean time I recall you mentioned just getting a blank page, which would indicate a fatal PHP error. To reveal the error, temporarily enable error reporting by adding the following lines to config.php:

  error_reporting(E_ALL);
  ini_set('display_errors','on');

If that reveals the error or of course if no difference post a follow up on the multi-language thread and I'll check that out with you right away of course;

Apologies for any inconvenience.

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Mon, 2015-11-16 12:06

Hello David. On the new merchantcoupons.php page are the original merchants registered for the PT site. First issue is all the vouchers on the vouchers page are from an api call. Also there are custom merchants and registered merchants on this page also. The problem is the when clicking on a merchant that does not have coupons or vouchers registered, it takes me to a blank page. Also is it possible to add the custom api merchants from the vouchers.php to the merchantcoupons.php page.

Submitted by support on Mon, 2015-11-16 12:48

Hi,

It sounds like it would be best to make merchantcoupons.php entirely manual so that you can specify the list of merchants for which you have API calls for that merchant's voucher codes supported by the modified vouchers.php with support for the merchant= parameter.

To do this, where you have the following code at line 8:

  if (database_querySelect($sql,$rows))

...REPLACE with:

  $merchants = array("Merchant 1","Merchant 2","Merchant 3");
  $rows = array();
  foreach($merchants as $merchant)
  {
    $rows[] = array("merchant"=>$merchant);
  }
  if (count($rows))

Edit the $merchants array to contain the list of merchants to include in the index.

Finally, in vouchers.php, you can enclose each API call within an IF statement so that it is only executed if the page is being requested for that merchant, for example:

  if ($merchant == "Merchant 1")
  {
    // vouchers.php code for Merchant 1 here
  }

Alternatively, if you still want vouchers.php to show all voucher codes (registered and custom) if called without a merchant parameter, then use:

  if (!$merchant || ($merchant == "Merchant 1"))
  {
    // vouchers.php code for Merchant 1 here
  }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Wed, 2015-11-25 05:00

Hey David all is working fine now. How can I add logos from custom api merchants to the merchantcoupons.php page and the vouchers.php page?

Submitted by support on Wed, 2015-11-25 09:35

Hi,

If you save logos for your custom merchants in /logos/ e.g.

/logos/AdvertiserName.jpg

...then referring to your previous thread regarding parsing of your custom coupon feeds it looks like you're displaying the merchant name using code similar to;

    print "<a target='_BLANK' href='".$record["CLICKURL"]."'>".$record["ADVERTISERNAME"]."</a>";

So in this case, to display the logo instead you would use:

    print "<a target='_BLANK' href='".$record["CLICKURL"]."'>
           <img src='/logos/".$record["ADVERTISERNAME"].".jpg' />
           </a>";

Or just generally, within your ...RecordHandler() function for each feed;

  print "<img src='".$record["ADVERTISERNAME"].".jpg' />";

Hope this helps!

Cheers,
David.
--
PriceTapestry.com