From 75bd4bfe2cc408943e4a11c6c7f947d10e97e96a Mon Sep 17 00:00:00 2001
From: Lukas von Blarer <lukas.vonblarer@gmail.com>
Date: Tue, 4 Apr 2017 16:40:50 +0200
Subject: [PATCH] #2835660: Allow user to provide password during checkout
 registration

---
 commerce_checkout_login.module    | 16 ++++++++++++++--
 commerce_checkout_login.panes.inc | 18 ++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)

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 47093b9..1ba8dbd 100644
--- a/commerce_checkout_login.panes.inc
+++ b/commerce_checkout_login.panes.inc
@@ -119,6 +119,17 @@ 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',
+          '#type' => 'password',
+          '#title' => t('Password'),
+          //'#title_display' => 'invisible',
+          '#size' => 25,
+          '#required' => TRUE,
+        );
+      }
+
       $form['select']['register']['continue'] = array(
         '#type' => 'submit',
         '#name' => 'register',
@@ -235,5 +246,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;
 }
-- 
2.10.1

