Hi,

Here is my problem which i have struggled with for the past week:

1. I have a csv file with hundreds of associated users info with ids:

2612450, 2612276 etc

2. I have a file with hundreds of images associated file names to ids:

2612450_1.jpg, 2612450_2.jpg, 2612450_3.jpg

2612276_1.jpg, 2612276_2.jpg etc

3. I have set up and Imported the user csv file to profile2 with the feeds module no problem.

However i can not find a way to associate the images to the users any ideas please?

Comments

colinstables created an issue. See original summary.

megachriz’s picture

Assigned: colinstables » Unassigned
Status: Active » Fixed

Since there is no mapper for user ID, you either need the user name or user mail address to import images for an user using the User processor.

I think the following could work:

  1. Make a CSV export of all users with the following data: user ID (uid) and user name (name).
  2. To this CSV, add a column called "image" and put in the full URL to the images in there. If there are multiple images for a single user, seperate them by a pipe character: |. You can use the information from the user ID column to merge in the right image URLs.
  3. Create an importer. Set parser to "CSV parser", processor to "User processor".
  4. On the mapping settings:
    • Map "name" to "User name (name)" and set this target as unique.
    • Map "image" to your image field.
  5. Install the Feeds Tamper module. Also enable the module "Feeds Tamper Admin UI".
  6. On the Tamper settings, add a tamper plugin of type "Explode" and set "String separator" to the pipe character: |.
  7. Import the CSV file.

I hope this helps. The most work would be to get the image URLs in the CSV file. There may be some tools in Microsoft Excel available to ease that process.

If you are good with PHP, an other option could be to implement hook_feeds_after_parse() in a custom module. You could then retrieve the user name based on the image URL. Make sure though that all images for one user are in a single item, something like this:

$item = array(
  'name' => 'John Doe',
  'images' => array(
    'http://www.example.com/2612450_1.jpg',
    'http://www.example.com/2612450_2.jpg',
    'http://www.example.com/2612450_3.jpg',
  ),
);

Not this, because then only the last image will be imported (each item will overwrite the previous one):

$items[0] = array(
  'name' => 'John Doe',
  'image' => 'http://www.example.com/2612450_1.jpg',
);
$items[1] = array(
  'name' => 'John Doe',
  'image' => 'http://www.example.com/2612450_2.jpg',
);
$items[2] = array(
  'name' => 'John Doe',
  'image' => 'http://www.example.com/2612450_3.jpg',
);

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

colinstables’s picture

Thanks very much for the info i will give it a try thankyo :)