Tags/topics: 
4
Answers
Vote up!
1
Vote down!

How to import users and customer profiles

What is the process for importing users and their addresses? I'm using Commerce Feeds - I can import the users easily enough and can import customer profiles fairly easily too, but the only way I can see of linking the two together would be via their user ID. Users won't get a user ID until they're already imported, so how can I link them to the appropriate profile info?

Asked by: gazzur
on June 18, 2013

4 Answers

Vote up!
1
Vote down!

I have been watching this post for some time in hope that someone will create an answer. I have not been able to find a definitive answer to this question if Commerce Profiles Imports can't be liked to users it is not usable!

We have found a workaround for this but it is far from ideal.

This requires modules:
Feeds
Feeds Tamper
Commerce Feeds
Entity Reference
feeds_tamper_string2id

Step 1) User Import
We have alphanumeric unique account codes for customers that are used user name. This is straight forward.

Step 2) Billing and Delivery profile imports
Our import file has two identical account code fields AccountCode1 AccountCode2.

Step 3) AccountCode1 maps to the GUID so we can update or delete the profiles. (Important note: if you set the import to update existing profiles and the profile is already assigned to an order it will create a new profile on every import that will quickly bloat your database.)

Step 4) AccountCode2 maps to field to a Profile Entity Reference field with target type User. The import reference is then "Customer code Ref: Entity ID of target user". The feeds tamper "Convert string into entity ID" is used to find the entity id of the user. When the import runs the account code is then imported and we get the entity ID stored in our Entity reference field.

Step 5) On import a rule then fires "Before saving an item imported via Customer: Billing Profile" that copies the value from our Entity reference field to the commerce-customer-profile:uid.

Whala!

Caveat:
The problem we have with this is that it works 90% of the time but we often have two digit account codes and these get confused during the auto look up therefore account ABC will often add the profile to account BC.

Has anyone had any success importing the account codes straight into the UID field using the "Cast to integer" tamper?

Answer by: Matt Batterton
Posted: May 29, 2014
Vote up!
0
Vote down!

Subscribing.

Matt you are right, this is not really an idea solution but it is quite clever and has got me thinking. Will let you know what I come up with.

Answer by: Justin
Posted: Aug 6, 2014
Vote up!
0
Vote down!

I was also thinking about this and thought about using a feeds tamper plugin to get the correspoding userid to the username.

I am importing the users first. Then in the import for the customer profile I map the username from my import to userid of customer profile. Then with Feeds Tamper I change the username to the userid.

I did this quick and dirty with an SQL query in the tamper plugin I have created. I am not to familiar with Drupal coding standards so this code might surely be improvable. But it did work for me now.

The benefit I am having from this, is that only those customer profiles get imported where a user is existing. Before using it that way all the profiles got imported even if no corresponding user could be found.

This is the code of the plugin:

<?php

/**
* @file
* Get the userid to usernam.
*/

$plugin = array(
  'form' => 'feeds_tamper_userid_to_username_form',
  'callback' => 'feeds_tamper_userid_to_username_callback',
  'name' => 'Userid to Username',
  'multi' => 'loop',
  'category' => 'SQL',
);

function feeds_tamper_userid_to_username_form($importer, $element_key, $settings) {
  $form = array();
  $form['info'] = array(
    '#markup' => t('This plugin deliver userid to username.'),
  );
  return $form;
}

function feeds_tamper_userid_to_username_callback($result, $item_key, $element_key, &$field, $settings) {
  $query = "SELECT uid FROM users WHERE name = '" . $field ."'";
  $result = db_query($query);
  $field = $result->fetchField();
}
Answer by: Stefan Korn
Posted: Sep 5, 2014
Vote up!
0
Vote down!

I've the same problem, but I'm not able to reply the solution posted by Matt.
Can someone help me ?

Answer by: Nikolino
Posted: Jan 27, 2016