I'm building a store website, where a customer service department is also using the site on the back end to take in some orders via phone or fax. I've configured my site so that user accounts are not created when orders are placed.

If a user is authenticated, it doesn't ask them for their email address during the checkout phase, it assumes the logged in UserID. There is a permission to "Display the account information pane for authenticated users. " in the checkout settings, but it doesn't allow you to change the email address.

Is there any way to force anonymous checkout? That is, I want authenticated users to re-enter in email information so that a new customer profile is created for ever order, and that the profile email can subsequently be used to send mail to the profile, rather than the user.

Thanks in advance!

Comments

TrevorBradley’s picture

Got it! Figured out just the right combination of hook_form_alter. The culprit function is actually commerce_order_account_pane_checkout_form, but the way the alter functions are layered makes it very difficult to insert the solution without hacking commerce directly.

function MODULE_form_commerce_checkout_form_checkout_alter(&$form, &$form_state) {
  unset($form['account']['username']);
  unset($form['account']['mail']);
  $form['account']['login'] = array(
    '#type' => 'container',
    '#prefix' => '<div id="account-login-container">',
    '#suffix' => '</div>',
  );

  $form['account']['login']['mail'] = array(
    '#type' => 'textfield',
    '#title' => t('E-mail address'),
    '#required' => TRUE,
  );

  if (variable_get('commerce_order_account_pane_mail_double_entry', FALSE)) {
    $form['account']['login']['mail_confirm'] = array(
      '#type' => 'textfield',
      '#title' => t('Confirm e-mail address'),
      '#description' => t('Provide your e-mail address in both fields.'),
      '#required' => TRUE,
    );
  }
}

Now, the account user information is still set in the profile, but I don't care, I can hide that...

I'd appreciate if anyone else could have a look at this and figure out if there was a better solution.

TrevorBradley’s picture

Status: Active » Closed (works as designed)

OK, I think I've figured out the *right* way to do this.

I've moved all the functions in commerce_order.checkout_pane.inc into my own module, and prefixed the function names. I then attached to the hook in commerce_checkout_panes as follows:

function MYMODULE_commerce_checkout_pane_info_alter(&$checkout_panes) {
  unset($checkout_panes['account']['file']);
  $checkout_panes['account']['base'] = 'MYMODULE_commerce_order_account_pane';
  $checkout_panes['account']['module'] = 'MYMODULE';
}

I then can hack the commerce_order_account_pane at will, because I'm actually hacking MYMODULE_commerce_order_account_pane.

Whew! That was hard, but I think it's finally right.