Hi David,
What's recommended if you have multiple feeds from the same merchant? Basically they give me a feed for each category of items. How do you import these feeds since I want all of them to be under the same merchant? Should I join all of the feeds together somehow? Have others dealt with this before?
Thanks for any ideas!
-Joe
Hi David,
They're CSV files. Hopefully that makes things easier, rather than harder ;)
Thanks, -Joe
Hi Joe,
If you make your /feeds/ folder writable (the easiest way to do this is with your FTP program - right-click on the folder and look for Permissions... or Properties... and then Permissions... and give write access to all users - owner, group, world); the following script, to be run in your /admin/ folder should concatenate the files easily - just change the names of the files in the $input array (and add more lines if necessary), and the output filename in $output:
concat.php
<?php
set_time_limit(0);
$input = array();
$input[] = "MerchantCategoryA.csv";
$input[] = "MerchantCategoryB.csv";
$input[] = "MerchantCategoryC.csv";
$output = "Merchant.csv";
$outputf = fopen("../feeds/".$output,"w");
if (!$outputf) die("Could not create output file!");
foreach($input as $filename)
{
$inputf = fopen("../feeds/".$filename,"r");
while(!feof($inputf)) fputs($outputf,fgets($inputf));
fclose($inputf);
}
print "Done!";
?>
Hope this helps!
Cheers,
David.
Hi David,
I haven't tried it out yet, but it looks exactly like what I was looking for. You cease to amaze me! Thanks as always, -Joe
I noticed one thing that could cause a problem. All of the category files have a header and footer line that are not products. How can I strip those lines out before joining them?...any ideas?
Thanks! -Joe
Hi Joe,
Could you post an example of the header and footer lines and I'll code to identify and ignore them...
Would you want to keep the very first header from the first file still?
Cheers,
David.
Hi David,
Nah I don't need any headers if it makes things easier. I rarely use them since the ones that I get tend to not be very useful.
The files have this (or similar because of date and time) as a header:
HDR|2762|merchant.com|2009-04-08/08:16:43
The footers are like so (I figured out this stands for something like "Total Records Listed = 9" and is dependent on how many products are in each file):
TRL|9
Thanks David! -Joe
Hi Joe,
They're easy enough to strip out - try this:
<?php
set_time_limit(0);
$input = array();
$input[] = "MerchantCategoryA.csv";
$input[] = "MerchantCategoryB.csv";
$input[] = "MerchantCategoryC.csv";
$output = "Merchant.csv";
$outputf = fopen("../feeds/".$output,"w");
if (!$outputf) die("Could not create output file!");
foreach($input as $filename)
{
$inputf = fopen("../feeds/".$filename,"r");
while(!feof($inputf))
{
$line = fgets($inputf);
if (strpos($line,"HDR|")===0 || strpos($line,"TRL|")===0) continue;
fputs($outputf,$line);
}
fclose($inputf);
}
print "Done!";
?>
Cheers,
David.
I'll try it out when I get a chance later on today. Thanks a lot David!
-Joe
Tried the script out today, works great! Thanks a lot David for your help as always!!
-Joe
Hi Joe,
Are they CSV or XML feeds?
Cheers,
David.