I want to make a page showing all my merchants ideally taken from the new affiliate window datafeed Merchant Metadata feed.
Is anyone using this feed - how would the best way to use something like this instead of the pricetapestry merchant list
Mainly i wanted to pop a logo and brief description for each merchant on a list - Maybe eventually have it link to a landing page with more detail of this merchant and a link to all their products that i host.
Any advice appreciated.
If this is a big job im willing to pay / donate
Thanks as always the page works fine - i dont use rewrite URL's
What would the change be in that case to make the links work?
No probs.. just change the line that displays the merchant name to:
print "<h4><a href='search.php?q=merchant:".tapestry_hyphenate($merchant["MERCHANT-NAME"])."'>".$merchant["MERCHANT-NAME"]."</a></h4>";
It will then use the non rewrite version...
Cheers!
David.
hi David,
Sorry to resurrect this topic but I've been using this successfully since last year but last week I updated my list of AW merchants as I'd added a couple of new ones and ever since the listing script doesn't bring up any merchants :(
I also used this script as a basis for automating my feed download (i.e. used it to loop through the awsubscribed XML file finding ids and names for each merchant to substitute into the URL to download and filename to write it to the server as) and that has stopped working too. I updated the fetch script to change the filename to look for as AW have changed the domain part of the URL - I thought that might be the problem - but it still doesn't work.
I've noticed that a couple of the merchant product feeds have misspelt the merchant name compared to what's in the merchant metadata file and can see that might affect the listing but can't for the life of me work out why the fetch script is failing.
Can you help me out at all please as it is taking me ages to do manual downloads !!
Thanks
Jan
Just done a phpinfo on my site and my hosts have upgraded to version 5.2 from 4.XX would this affect how things need to be coded - I'm not that brilliant with PHP.
Hello Jan,
I just went to download my latest subscribed merchants file and it seems like there is currently a problem with the file (it contains some preamble relating to an error on the server).
I was able to delete these lines, upload the file awsubscribed.xml to my server and tested the above script and it worked as expected. If you are seeing nothing when you run this script, it is likely to be the same problem. To resolve it, I had to open awsubscribed.xml into a text editor and delete the first 3 lines...
I have just raised a support ticket with Affiliate Window about this...
Cheers,
David.
Thanks David at least it wasn't just me having a blonde moment again then :)
I just had a look at my merchants XML file and there doesn't appear to be anything wrong with it so I'm completely stumped why it's stopped working. I've used the old version of the script with the old download filename and the old merchant file and that works, but the old script with the new file doesn't. Is there some way I can put a trace in the script to display errors so I can see why it's falling over ? I've tried adding print statements at various stages to see how far it gets but it only displays my "Fetch started" message which is just before the fetch statement.
Hi Jan,
Can you post a bit more of the code you're using (in particular the section reading awsubscribed.xml and then constructing download URLs) and i'll suggest what debug code to add...
Cheers,
David.
This is the whole script
<?php
require("includes/MagicParser.php");
// destination directory for downloaded files - must be writable by PHP
$targetDir = "feeds/";
// path to wget program for retrieval
$wgetProgram = "/usr/local/bin/wget";
// path to various unzip programs
$unzipPrograms["zip"] = "/usr/bin/unzip";
// check that target directory is writable, bail otherwise
if (!is_writable($targetDir))
{
print "<p>target directory ($targetDir) not writable - exiting</p>";
exit();
}
$merchant = array();
function myRecordHandler($record)
{
global $merchant;
$merchant[] = $record;
}
function fetch_url($url,$filename)
{
$source = fopen($url,"r");
$destination = fopen($filename,"w");
if (!$source || !$destination) return;
while(!feof($source))
{
fwrite($destination,fread($source,2048));
}
fclose($source);
fclose($destination);
}
function unzip_zip($header,$filename)
{
global $unzipPrograms;
// check if zip format
if ($header <> "PK".chr(0x03).chr(0x04)) return false;
$command = $unzipPrograms["zip"]." -p ".$filename." > ".$filename.".unzipped";
exec($command);
unlink($filename);
rename($filename.".unzipped",$filename);
return true;
}
function fetch($url,$filename)
{
global $targetDir;
global $wgetProgram;
global $unzipPrograms;
$temporaryFilename = $targetDir.uniqid("");
fetch_url($url,$temporaryFilename);
// bail if download has failed
if (!file_exists($temporaryFilename))
{
print "<p>download failed - exiting</p>";
exit();
}
// read the first 4 bytes to pass to unzip functions
$filePointer = fopen($temporaryFilename,"r");
$fileHeader = fread($filePointer,4);
fclose($filePointer);
// try and unzip the file by calling each unzip function
foreach($unzipPrograms as $name => $program)
{
$unzip_function = "unzip_".$name;
if ($unzip_function($fileHeader,$temporaryFilename)) break;
}
// finally rename to required target (delete existing if necessary)
$targetFilename = $targetDir.$filename;
if (file_exists($targetFilename))
{
unlink($targetFilename);
}
rename($temporaryFilename,$targetFilename);
// all done!
}
print "Affiliate Window feeds processing started ...";
MagicParser_parse("awsubscribed.xml","myRecordHandler");
print $record;
foreach ($merchant as $key_name => $key_value) {
$mid=$key_value["MERCHANT-ID"];
$name=$key_value["MERCHANT-NAME"];
$feed=str_replace(' ', "_", $name);
$feedname=str_replace('.', "_", $feed) . ".xml";
print "merchant id ".$mid." merchant name ".$name;
set_time_limit(0); // allow unlimited execution time
ignore_user_abort(); // carry on even if browser quits
fetch("http://datafeeds.productserve.com/datafeed_products.php?user=xxxx&password=xxxx&mid=".$mid."&format=XML&dtd=1.0",$feedname);
print "Feed fetched for " . $key_value["MERCHANT-ID"] . " " . $key_value["MERCHANT-NAME"] . "<BR>";
}
?>
Hello Jan,
The first thing I would do is to add the correct format string to MagicParser_parse() so that you don't have to rely on the auto-detect. To do this, change:
MagicParser_parse("awsubscribed.xml","myRecordHandler");
to:
MagicParser_parse("awsubscribed.xml","myRecordHandler","xml|AFFILIATEWINDOW/MERCHANT/");
As the next step, I would then dump the $merchant array on the next line, to confirm it has been parsed correctly:
print_r($merchant);exit();
If that's OK, then remove that code and a similar message to your "Feed fetched..." but before you fetch each feed (so just inside your foreach() loop) to print out what is about to happen...
Cheers,
David.
Hi David,
Tried that - it prints out "Affiliate Window feeds processing started ...Array ( )" then exits (even after I remove the exit statement)
Is that because it's not parsing the merchants XML file correctly ?
Hello Jan,
Yes - that means there are no records being found in "awsubscribed.xml". First thing to do is double check that the file does contain valid XML. If it looks OK, i'd write a quick test script to try and isolate the problem; for example:
<?php
require("includes/MagicParser.php");
function myRecordHandler($record)
{
print $record["MERCHANT-NAME"]."<br />";
}
MagicParser_parse("awsubscribed.xml","myRecordHandler","xml|AFFILIATEWINDOW/MERCHANT/");
?>
Now that by all rights should display the merchant list; but as this is no different to your existing code it probably won't..! The next thing I would do is upload your copy of awsubscribed.xml to the Magic Parser demo tool to see what it makes of it...
http://www.magicparser.com/demo
If that works - double check what Format String Magic Parser has selected for the file incase I was wrong with the one suggested above (although I don't think AW have changed the format). If still no joy, if you could email me a copy of your awsubscribed.xml (reply to your reg code or forum registration email) i'll happily take a look for you...
Cheers,
David.
Hi David,
The XMl looks OK from a quick glance but the MagicParser demo gives no results so there must be something wrong with the file. I'll send it by email to see if you can spot the error !!
Thanks
Jan
Just downloaded a new awsubscribed.xml file from AW and the scripts not working right again ! Does anyone know if AW have changed the format as it's only downloading the feed for the first merchant in the XML file.
Hello Janni,
The first thing to do is check the feed manually; does it contain all the merchants as normal?
If the format had changed it shouldn't have been able to pick-out the first one either; so that shouldn't be the problem. Request the file in your browser and have a look manually is the easiest way...
Cheers,
David.
Hi David - It was my mistake - I installed a new copy of PT in another directory and forgot to copy over MagicParserReplaceNull.php - sorry !!
Hi Kev,
The Affiliate Window merchants feed is pretty straight forward to use with Magic Parser. I've just tried it out - here's my first attempt running on the Price Tapestry demo site:
http://www.webpricecheck.co.uk/awmerchants.php
To use this, download the merchants xml feed (subscribed, product enabled) into your Price Tapestry root directory as "awsubscribed.xml"), and then run the script below - assuming that you're using rewrite URLs.
The only caveat here is that your registered merchant names must match exactly the merchant name in the Affiliate Window feed - otherwise the search link won't work....!
awmerchants.php
<?php
require("includes/common.php");
require("includes/MagicParser.php");
$banner["h2"] = "<strong>Affiliate Window Merchants</strong>";
function myRecordHandler($merchant)
{
print "<tr>";
print "<td><img src='".$merchant["LOGO"]."' /></td>";
print "<td>";
print "<h4><a href='/merchant/".tapestry_hyphenate($merchant["MERCHANT-NAME"])."/'>";
print $merchant["MERCHANT-NAME"];
print "</a></h4>";
print "<p><small>".$merchant["DESCRIPTION"]."</small></p>";
print "</td>";
print "</tr>";
}
require("html/header.php");
require("html/menu.php");
require("html/searchform.php");
require("html/banner.php");
print "<table width='728' cellpadding='10'>";
MagicParser_parse("awsubscribed.xml","myRecordHandler","xml|AFFILIATEWINDOW/MERCHANT/");
print "</table>";
require("html/footer.php");
?>
Let me know how you get on!
Cheers,
David.