Hi how would i add voucher code to the site let's say just under the price. SO when when a user does search let's say on a samsung TV and it brings in feeds from currys, dixons, comet etc and we have entered a voucher code for them it brings it up ?
Is there a simple reason as to why this bit of code only works in html/prices.php?
I'd really like the voucher to be as prominant as possible.
I've tried putting it in html/product.php and also html/banner.php and it doesn't work in either.
Hi,
That's because of the $product["merchant"]
variable. The same method can be used anywhere else that a merchant name is accessible - it's just that a different variable name would be required.
Bear in mind however that within the price table, the code can pick up vouchers for all merchants stocking a product, whereas using the code in html/product.php you would only show the voucher HTML for the cheapest merchant. Easily done however, here's the code that will work at the end of html/product.php:
<?php
if (file_exists("vouchers/".$mainProduct["merchant"]))
{
require("vouchers/".$product["merchant"]);
}
?>
Cheers,
David.
Hi David
I have been using this approach for a while now to create a link to the relevant merchant voucher codes on another website.
I have recently moved my websites on to the same server. So I have two installations of PT for two different websites on the same server - one holding voucher codes, the other holding merchant datafeeds.
I wish to display in the price table a list of vouchers that may be relevant to the product in question for each merchant- see code below.
I have used the following code in a file in the directory "vouchers":
<?php
$path_to_pricetapestry = "/kunden/homepages/1/aaaaaaa/bbbbbbb/cccccccc/";
require($path_to_pricetapestry."config.php");
require($path_to_pricetapestry."includes/tapestry.php");
require($path_to_pricetapestry."includes/database.php");
$sql = "SELECT name,image_url,description FROM `".$config_databaseTablePrefix."products` WHERE merchant LIKE '%Click to reveal%' AND brand LIKE '%comet%' AND category LIKE '%Electronics and Appliances%' ORDER BY expirydate ASC";
if (database_querySelect($sql,$rows))
{
foreach($rows as $product)
{
if ($config_useRewrite)
{
$href = "http://mmmmmmmm.co.uk/vouchers/product/".tapestry_hyphenate($product["name"]).".html";
}
else
{
$href = $config_baseHREF."products.php?q=".urlencode($product["name"]);
}
?>
<ul><li>
<?php
print " ".$product["name"]." - ";
print "<a href='".$href."'>".$product["description"]."</a><br />";
?>
</li></ul>
<?php
}
}
?>
So I have one PT installation requesting information held by another PT installation. The problem that I am experiencing is that the declaration of the PT files in the above code is conflicting with PT installation running the merchant datafeeds
The error message is
"Fatal error: Cannot redeclare tapestry_search() (previously declared in /homepages/1/aaaaaaa/bbbbbbb/yyyyyyyyy/zzzzzzzzz/includes/tapestry.php:2) in /homepages/1/aaaaaaa/bbbbbbb/cccccccc/includes/tapestry.php on line 7"
Any ideas on how to get around this using two separate installations of PT?
Many thanks
Regards
Richard
Hi Richard,
The only require line you'll need is...
require($path_to_pricetapestry."config.php");
...and this will set the database parameters for the other site. If tapestry.php and database.php have already been included at this point (which it sounds like they have) there's no need to require them again...
Cheers,
David.
Hi David,
Trying to implement this using the following,if you recall using html/searchresults.php instead of html/prices.php as not using as a price comparison
{code saved}
inserted code is denoted at this point <tr><!--insert to add voucher code text-->
but I can't see anything showing up, do you mind advising where I may have gone wrong?
regards
Paul
Hi David,
I posted a question here yesterday, and I thought it's odd that at least my question wasn't published, and even odder that you didn't respond, just wondering whether you got it, or should it re-post?
Thanks
Paul
Hi Paul,
My apologies - not sure what happened there - I got the latest "new comment" alert and both of them were showing so I must have missed the first; sorry about that.
The code looks fine, but it looks as if it's executing as if in the /html/ rather than the / folder. Could you try changing the code as follows:
<?php
if (file_exists("../vouchers/".$product["merchant"]))
{
require("../vouchers/".$product["merchant"]);
}
else
{
print " ";
}
?>
If that doesn't help we'll look at some more comprehensive debug code...
Cheers,
David.
Hi David,
Thought it was unusual, just unsure you received it, sorry to pester.
I have now inserted the code, and its still not showing, It is only searchresults.php I need to add it to isn't it?
Regards
Paul
Hi Paul,
To double check the path is right, could you try the following (this undoes the above change and adds the debug print out)...
<?php
print "[Testing: "."vouchers/".$product["merchant"]."]";
if (file_exists("vouchers/".$product["merchant"]))
{
require("vouchers/".$product["merchant"]);
}
else
{
print " ";
}
?>
...and then let me know what is displayed in the "Testing: ......" between square brackets for each result...
Cheers,
David.
David,
OK results show this obvioussly changes for each merchant [Testing: vouchers/My Wardrobe]
Thanks, Paul..
And if you browse to:
http://www.example.com/vouchers/My Wardrobe
...the correct voucher information is displayed?
Cheers,
David.
nope! either gets a 404 or a page relating to that merchant...
Regards
Paul
Hi Paul,
That's the problem then rather than the code - /vouchers/Merchant Name - where Merchant Name must be spelt exactly as the merchant name is registered against the feed.
First of course, check that the directory name "vouchers" exists; and then look at the filenames within that folder...
Once /vouchers/Merchant Name works directly and isn't returning 404 then the code above should work fine...
Cheers,
David.
Hi David,
Well I don't understand, as I've created the /vouchers/ folder in my PT installation and for each merchant I've created a seperate text file, I've copied and pasted the merchant names directly from my PT installtion.
I'll have another read through and see if I've missed anything...
Thanks for your help
Regards
Paul
Hi Paul,
Some people implement this using the ".txt" extension on the filenames (as this makes it easier to manage / edit the files), in which case the same would have to be reflected in the code, for example:
<?php
if (file_exists("vouchers/".$product["merchant"].".txt"))
{
require("vouchers/".$product["merchant"].".txt");
}
else
{
print " ";
}
?>
Drop me an email if you want me to take a closer look...
Cheers,
David.
Hi,
What i'd recommended for this is rather than creating new database tables and admin tools, you could use a very similar mechanism to that described for showing merchant logos in this thread:
http://www.pricetapestry.com/node/314
Instead of "logos", create a new folder called "vouchers", and then inside that folder create text files that contain any voucher / discount / coupon codes for your merchants, using a filename that exactly matches (including spaces) the registered merchant names on your site. Then, after creating a new column header in the prices table as described in the other thread, the block of code to read and display the coupon code would become:
<td>
<?php
if (file_exists("vouchers/".$product["merchant"]))
{
require("vouchers/".$product["merchant"]);
}
else
{
print " ";
}
?>
</td>
Hope this helps!
Cheers,
David.