I had a requirement from a client to allow the user to provide a password during checkout registration. Attached is a patch that let's an admin configure the checkout pane to allow for collecting the password during registration. On checkout complete that password is used to create the account.

Comments

caschbre created an issue. See original summary.

caschbre’s picture

Hmm... something is going on with the drupal node add/edit forms and i'm unable to upload the patch file. So here's the patch inline here.

diff --git a/commerce_checkout_login.module b/commerce_checkout_login.module
index 567213d..f83229d 100644
--- a/commerce_checkout_login.module
+++ b/commerce_checkout_login.module
@@ -165,7 +165,11 @@ function ccl_validate_existing_account(&$form, &$form_state, &$account) {
 function commerce_checkout_login_commerce_checkout_complete($order) {
   if (ccl_current_user_is_anonymous() && !empty($order->data['commerce_checkout_login_register'])) {
     $account = ccl_create_new_user_for($order);
-    ccl_dislay_password_reset_message($account);
+
+    if (!variable_get('commerce_checkout_login_allow_registration_password', FALSE)) {
+      ccl_dislay_password_reset_message($account);
+    }
+
     ccl_new_account_notification($account);
     ccl_login_convert_order($account->uid, $order);
   }
@@ -197,7 +201,15 @@ function ccl_dislay_password_reset_message($account) {
 function ccl_create_new_user_for(stdClass $order) {
   $username = $order->data['commerce_checkout_login_register']['username'];
   $mail = $order->data['commerce_checkout_login_register']['mail'];
-  $account = commerce_checkout_create_account($username, $mail, user_password(), TRUE, TRUE);
+
+  if (variable_get('commerce_checkout_login_allow_registration_password', FALSE)) {
+    $pass = $order->data['commerce_checkout_login_register']['pass'];
+  }
+  else {
+    $pass = user_password();
+  }
+
+  $account = commerce_checkout_create_account($username, $mail, $pass, TRUE, TRUE);
   return $account;
 }
 
diff --git a/commerce_checkout_login.panes.inc b/commerce_checkout_login.panes.inc
index c27268d..9185fd1 100644
--- a/commerce_checkout_login.panes.inc
+++ b/commerce_checkout_login.panes.inc
@@ -119,6 +119,16 @@ function commerce_checkout_login_account_form($form, &$form_state, $checkout_pan
         );
       }
 
+      if (variable_get('commerce_checkout_login_allow_registration_password', FALSE)) {
+        $form['select']['register']['pass'] = array(
+          '#type' => 'password_confirm',
+          '#title' => t('Password'),
+          '#title_display' => 'invisible',
+          '#size' => 25,
+          '#required' => TRUE,
+        );
+      }
+
       $form['select']['register']['continue'] = array(
         '#type' => 'submit',
         '#name' => 'register',
@@ -239,5 +249,12 @@ function commerce_checkout_login_account_settings_form($checkout_pane) {
     '#default_value' => variable_get('commerce_order_account_pane_mail_double_entry', FALSE),
   );
 
+  $form['commerce_checkout_login_allow_registration_password'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Capture password during registration'),
+    '#description' => t('Allow the user to enter a password when registering.'),
+    '#default_value' => variable_get('commerce_checkout_login_allow_registration_password', FALSE),
+  );
+
   return $form;
 }
luksak’s picture

Status: Active » Needs review
StatusFileSize
new3.24 KB

Creating a patch according to #2 which works for me so far.

Status: Needs review » Needs work

The last submitted patch, 3: 2835660-provide-password-3.patch, failed testing.

luksak’s picture

I applied the patch to beta1...

Road Kill’s picture

Patch from no3 fro beta1 fails it now sends out three emails with the one time login link which fails.

matthiasm11’s picture

Status: Needs work » Needs review
StatusFileSize
new2.77 KB

Rerolled the patch from #3.
I think #6 is a separate issue, sending emails is slightly different in beta2 compared to beta1.

Status: Needs review » Needs work

The last submitted patch, 7: provide_password-2835660-7.patch, failed testing. View results

solideogloria’s picture

Been using this for over a year without issue, but IMHO there should be an option for whether or not to send an email to the user, because right now what I am using is this (with FALSE instead of TRUE for the last parameter):

$account = commerce_checkout_create_account($username, $mail, $pass, TRUE, FALSE);

Because of this, I also don't use these lines:

ccl_dislay_password_reset_message($account);
ccl_new_account_notification($account);

These aren't necessary if you log in authenticated users anyway. (See this issue: https://www.drupal.org/project/commerce_checkout_login/issues/2681989)