You are here:  » Multiple feeds from one merchant?

Support Forum



Multiple feeds from one merchant?

Submitted by daem0n on Tue, 2009-04-07 07:57 in

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

Submitted by support on Tue, 2009-04-07 08:01

Hi Joe,

Are they CSV or XML feeds?

Cheers,
David.

Submitted by daem0n on Tue, 2009-04-07 09:29

Hi David,

They're CSV files. Hopefully that makes things easier, rather than harder ;)

Thanks, -Joe

Submitted by support on Tue, 2009-04-07 09:50

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.

Submitted by daem0n on Wed, 2009-04-08 06:23

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

Submitted by daem0n on Wed, 2009-04-08 08:19

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

Submitted by support on Wed, 2009-04-08 08:30

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.

Submitted by daem0n on Wed, 2009-04-08 09:13

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

Submitted by support on Wed, 2009-04-08 09:15

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|")===|| strpos($line,"TRL|")===0) continue;
      
fputs($outputf,$line);
    }
    
fclose($inputf);
  }
  print 
"Done!";
?>

Cheers,
David.

Submitted by daem0n on Wed, 2009-04-08 09:29

I'll try it out when I get a chance later on today. Thanks a lot David!

-Joe

Submitted by daem0n on Thu, 2009-04-09 09:21

Tried the script out today, works great! Thanks a lot David for your help as always!!

-Joe