You are here

function commerce_checkout_create_account in Commerce Core 7

Creates a new user account with the specified parameters and notification.

Parameters

$name: The new account username.

$mail: The e-mail address associated with the new account.

$pass: The new account password. If left empty, a password will be generated.

$status: TRUE or FALSE indicating the active / blocked status of the account.

$notify: TRUE or FALSE indicating whether or not to e-mail the new account details to the user.

Return value

The account user object.

File

modules/checkout/commerce_checkout.module, line 1004
Enable checkout as a multi-step form with customizable pages and a simple checkout pane API.

Code

function commerce_checkout_create_account($name, $mail, $pass, $status, $notify = FALSE) {

  // Setup the account fields array and save it as a new user.
  $fields = array(
    'name' => $name,
    'mail' => $mail,
    'init' => $mail,
    'pass' => empty($pass) ? user_password(variable_get('commerce_password_length', 8)) : $pass,
    'roles' => array(),
    'status' => $status,
  );
  $account = user_save('', $fields);

  // Manually set the password so it appears in the e-mail.
  $account->password = $fields['pass'];

  // Send the customer their account details if enabled.
  if ($notify) {

    // Send the e-mail through the user module.
    drupal_mail('user', 'register_no_approval_required', $mail, NULL, array(
      'account' => $account,
    ), commerce_email_from());
  }
  return $account;
}