0

Commerce Kickstart 2.

I used the included Feed to import users. I applied this patch: https://www.drupal.org/node/1570544 so I could keep the existing UIDs. Seemed to work OK.

I then wrote a script to import sales orders from an external db. That too seemed to go OK, except that the Username displayed on all reports, views, in fact -anywhere- that the field User:Name is displayed, it shows the First Name/Last Name of the billing profile of the last linked order. eg.

The username is 'MEGACORP'. But 'Frank Smith' is displayed as the User Name because that was the First/Last name of the imported order. -And- the link to the user account profile is users/frank_smith

The weird thing is that when people log in, they log in with the -correct- Username, ie. megacorp, -not- Frank_Smith

I looked at the SQL table Users and the Username is correct. (ie. megacorp)

AND I stumbled on creating a view of users, but as a wild-ass-guess set a relation to node entity reference and the Title field is 'Megacorp'.

Here are my field mappings in my customer profile import:

// Full Name(Required)
$profile_billing->commerce_customer_address[LANGUAGE_NONE][0]['name_line'] = $name;
// Country(Required)
$profile_billing->commerce_customer_address[LANGUAGE_NONE][0]['country'] = $row->country_iso_code_2;
// Address 1(Required)
$profile_billing->commerce_customer_address[LANGUAGE_NONE][0]['thoroughfare'] = $row->billing_street1;
// Address 2
$profile_billing->commerce_customer_address[LANGUAGE_NONE][0]['premise'] = $row->billing_street2;
// City(Required)
$profile_billing->commerce_customer_address[LANGUAGE_NONE][0]['locality'] = $row->billing_city;
// State(Required)
$profile_billing->commerce_customer_address[LANGUAGE_NONE][0]['administrative_area'] = $row->zone_code;
// Postal Code(Required)
$profile_billing->commerce_customer_address[LANGUAGE_NONE][0]['postal_code'] = $row->billing_postal_code;
//Business name(Required)
$profile_billing->field_business_name[LANGUAGE_NONE][0]['value'] = $row->billing_company;
 // Phone(Required)
$profile_billing->field_phone_number[LANGUAGE_NONE][0]['value'] = $row->billing_phone;`

So... 1. why is Username not pulling from the Users SQL table?

  1. Is the above behaviour something Commerce does? If so, can I turn it -off-?

  2. Is there -always- a related node for each user?

  3. The field billing_company doesn't seem to display on any view, even though it is available to import. How do I access -that-? I guess -that- is what I expected to appear on various forms/reports (eg. the invoice)

6

Commerce Kickstart 2 includes the following function, which uses hook_username_alter() to alter the display of the username to be the billing name, which is what it sounds like you're seeing here.

The easiest way around this would be to just delete this function, which is located in "/profiles/commerce_kickstart/modules/commerce_kickstart/commerce_kickstart_user/commerce_kickstart_user.module" from you're Drupal site's root directory.

/**
 * Implements hook_username_alter().
 */
function commerce_kickstart_user_username_alter(&$name, $account) {
  if (!empty($account->uid) && module_exists('commerce_addressbook')) {
    if ($billing_profile_id = commerce_addressbook_get_default_profile_id($account->uid, 'billing')) {
      $billing_profile = commerce_customer_profile_load($billing_profile_id);
      if (!empty($billing_profile->commerce_customer_address[LANGUAGE_NONE][0]['name_line'])) {
        $name = $billing_profile->commerce_customer_address[LANGUAGE_NONE][0]['name_line'];
      }
    }
  }
}
  • Wow. That's -awful-. If someone has a second for a follow-up: 1. How did you -find- this? 2. I imported the proper company name. How do I access that? What we want is not to use the 'Username' at all, but display the billing_company that is in the Profile. How do I hook into -that-? – jchwebdev Nov 6 '14 at 0:08
  • To answer your question: 1. I'm familiar enough with this distribution and with how usernames are handled in Drupal that I had a hunch that it was using Drupal's provided hook for altering the username. I wish it were easier than that... 2. If the company name is stored in the $billing_profile, you may be able to alter the code above to access that value, similar to how it's currently accessing the "name_line" value. – anemirovsky Nov 6 '14 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.