You are here

function uc_order_create_form_create_submit in Ubercart 7.3

Form submission handler for customer search.

See also

uc_order_create_form()

1 string reference to 'uc_order_create_form_create_submit'
uc_order_create_form in uc_order/uc_order.admin.inc
Creates a new order and redirect to its edit screen.

File

uc_order/uc_order.admin.inc, line 561
Order administration menu items.

Code

function uc_order_create_form_create_submit($form, &$form_state) {
  global $user;
  switch ($form_state['values']['customer_type']) {
    case 'search':
      $uid = $form_state['values']['customer']['uid'];
      break;
    case 'create':

      // Create new account.
      $email = trim($form_state['values']['customer']['email']);
      $fields = array(
        'name' => uc_store_email_to_username($email),
        'mail' => $email,
        'pass' => user_password(),
        'status' => variable_get('uc_new_customer_status_active', TRUE) ? 1 : 0,
      );
      $account = user_save(NULL, $fields);
      $uid = $account->uid;
      if ($form_state['values']['customer']['sendmail']) {

        // Manually set the password so it appears in the e-mail.
        $account->password = $fields['pass'];
        drupal_mail('user', 'register_admin_created', $email, uc_store_mail_recipient_language($email), array(
          'account' => $account,
        ), uc_store_email_from());
        drupal_set_message(t('A welcome message has been e-mailed to the new user.'));
      }
      break;
    default:
      $uid = 0;
  }
  $order = uc_order_new($uid, 'post_checkout');
  uc_order_comment_save($order->order_id, $user->uid, t('Order created by the administration.'), 'admin');
  $form_state['redirect'] = 'admin/store/orders/' . $order->order_id . '/edit';
}