function uc_checkout_pane_customer in Ubercart 5
Same name and namespace in other branches
- 6.2 uc_cart/uc_cart_checkout_pane.inc \uc_checkout_pane_customer()
- 7.3 uc_cart/uc_cart_checkout_pane.inc \uc_checkout_pane_customer()
Get the user's email address for login.
1 string reference to 'uc_checkout_pane_customer'
- uc_cart_checkout_pane in uc_cart/
uc_cart.module - Implementation of hook_checkout_pane().
File
- uc_cart/
uc_cart_checkout_pane.inc, line 47 - This file contains the callbacks for the default checkout panes supplied with Ubercart and their corresponding helper functions.
Code
function uc_checkout_pane_customer($op, &$arg1, $arg2) {
global $user;
switch ($op) {
case 'view':
$email = is_null($arg1) || empty($arg1->primary_email) ? $user->mail : $arg1->primary_email;
if ($user->uid) {
$description = t('Order information will be sent to your account e-mail listed below.');
// .'<br />'
$contents['primary_email'] = array(
'#type' => 'hidden',
'#value' => check_plain($email),
);
$contents['email_text'] = array(
'#value' => '<div>' . t('<b>E-mail address:</b> @email (<a href="!url">edit</a>)', array(
'@email' => $email,
'!url' => url('user/' . $user->uid . '/edit', 'destination=cart/checkout'),
)) . '</div>',
);
}
else {
$description = t('Enter a valid email address for this order or <a href="!url">click here</a> to login with an existing account and return to checkout.', array(
'!url' => url('user/login'),
));
$contents['primary_email'] = uc_textfield(t('E-mail address'), $email, TRUE, NULL, 64);
}
if (variable_get('uc_cart_email_validation', FALSE) && !$user->uid) {
$contents['primary_email_confirm'] = uc_textfield(t('Confirm e-mail address'), $_SESSION['email_match'] === FALSE ? '' : $email, TRUE, NULL, 64);
if ($_SESSION['email_match'] === FALSE) {
$contents['primary_email_confirm']['#attributes'] = array(
'class' => 'error',
);
unset($_SESSION['email_match']);
}
}
if ($user->uid == 0) {
$contents['new_account'] = array();
if (variable_get('uc_cart_new_account_name', FALSE)) {
$contents['new_account']['name'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#default_value' => $arg1->data['new_user']['name'],
'#maxlength' => 60,
'#size' => 32,
);
}
if (variable_get('uc_cart_new_account_password', FALSE)) {
$contents['new_account']['pass'] = array(
'#type' => 'password',
'#title' => t('Password'),
'#maxlength' => 32,
'#size' => 32,
);
$contents['new_account']['pass_confirm'] = array(
'#type' => 'password',
'#title' => t('Confirm password'),
'#description' => t('Passwords must match to proceed.'),
'#maxlength' => 32,
'#size' => 32,
);
}
if (!empty($contents['new_account'])) {
$array = array(
'#type' => 'fieldset',
'#title' => t('New account details'),
'#description' => variable_get('uc_cart_new_account_details', t('<b>Optional.</b> New customers may supply custom account details.<br />We will create these for you if no values are entered.')),
'#collapsible' => FALSE,
);
$contents['new_account'] = array_merge($array, $contents['new_account']);
}
/**
* This code adds profile fields required for registration to the
* customer checkout pane. However, I don't have the time to fool with
* validation/submission stuff, so I'm postponing this feature. -RS
$null = NULL;
$extra = _user_forms($null, NULL, NULL, 'register');
if (!empty($extra)) {
$contents = array_merge($contents, $extra);
}*/
}
return array(
'description' => $description,
'contents' => $contents,
);
case 'process':
if (!empty($arg2['primary_email']) && !valid_email_address($arg2['primary_email'])) {
drupal_set_message(t('You must enter a valid e-mail address.'), 'error');
return FALSE;
}
$arg1->primary_email = $arg2['primary_email'];
if (variable_get('uc_cart_email_validation', FALSE) && !$user->uid && $arg2['primary_email'] !== $arg2['primary_email_confirm']) {
drupal_set_message(t('The e-mail address did not match.'), 'error');
$_SESSION['email_match'] = FALSE;
return FALSE;
}
unset($_SESSION['email_match']);
// If new users can specify names or passwords then...
if ((variable_get('uc_cart_new_account_name', FALSE) || variable_get('uc_cart_new_account_password', FALSE)) && $user->uid == 0) {
// Skip if an account already exists for this e-mail address.
if (db_num_rows(db_query("SELECT uid FROM {users} WHERE LOWER(mail) = LOWER('%s')", $arg2['primary_email'])) > 0) {
drupal_set_message(t('An account already exists for your e-mail address. The new account details you entered will be disregarded.'));
}
else {
// Validate the username.
if (variable_get('uc_cart_new_account_name', FALSE) && !empty($arg2['new_account']['name'])) {
$message = user_validate_name($arg2['new_account']['name']);
if (!empty($message)) {
drupal_set_message($message, 'error');
return FALSE;
}
if (db_num_rows(db_query("SELECT uid FROM {users} WHERE LOWER(name) = LOWER('%s')", $arg2['new_account']['name'])) > 0) {
drupal_set_message(t('The username %name is already taken. Please enter a different name or leave the field blank for your username to be your e-mail address.', array(
'%name' => $arg2['new_account']['name'],
)), 'error');
return FALSE;
}
$arg1->data['new_user']['name'] = $arg2['new_account']['name'];
}
// Validate the password.
if (variable_get('uc_cart_new_account_password', FALSE)) {
if ($arg2['new_account']['pass'] != $arg2['new_account']['pass_confirm']) {
drupal_set_message(t('The passwords you entered did not match. Please try again.'), 'error');
return FALSE;
}
$arg1->data['new_user']['pass'] = $arg2['new_account']['pass'];
}
}
}
if ($user->uid) {
$arg1->uid = $user->uid;
}
return TRUE;
case 'review':
$review[] = array(
'title' => t('E-mail'),
'data' => check_plain($arg1->primary_email),
);
return $review;
case 'settings':
$form['uc_cart_email_validation'] = array(
'#type' => 'checkbox',
'#title' => t('Require e-mail validation for anonymous customers.'),
'#default_value' => variable_get('uc_cart_email_validation', FALSE),
);
$form['uc_cart_new_account_name'] = array(
'#type' => 'checkbox',
'#title' => t('Allow anonymous customers to specify a new user account name.'),
'#default_value' => variable_get('uc_cart_new_account_name', FALSE),
);
$form['uc_cart_new_account_password'] = array(
'#type' => 'checkbox',
'#title' => t('Allow anonymous customers to specify a new user account password.'),
'#default_value' => variable_get('uc_cart_new_account_password', FALSE),
);
$form['uc_cart_new_account_details'] = array(
'#type' => 'textarea',
'#title' => t('New account details help message'),
'#description' => t('Enter the help message displayed in the new account details fieldset when shown.'),
'#default_value' => variable_get('uc_cart_new_account_details', t('<b>Optional.</b> New customers may supply custom account details.<br />We will create these for you if no values are entered.')),
);
return $form;
}
}