0

I have created a commerce checkout page which, under certain conditions, is presented to the user with a custom login screen

$form['username'] = array(
    '#title' => t('Username'),
    '#type' => 'textfield',
    '#size' => 30
  );
  $form['password'] = array(
    '#title' => t('Password'),
    '#type' => 'password',
    '#size' => 30,
  );

In the submit handler, I log the user in

$username = $form_state['values']['user_login']['username'];
  $password = $form_state['values']['user_login']['password'];
  $login_array = array($username, $password);
  if($uid = user_authenticate($username, $password)) {
      global $user;
      $user = user_load($uid);

      $login_array = array ('name' => $username);
      user_login_finalize($login_array);
    }
  else {
    drupal_set_message('Invalid username or password');
  }  

However, what happens is, is on next page, /checkout/order-id/review, it says the user is logged in but page not found. This is because the newly logged in user doesn't have anything in his cart. Is there an easy way of transfering the old cart to this new user? I see that there is a Rule - Assign an anonymous order to a pre-existing user, which I enabled and thought it would do the trick, but it doesn't

In case it helps: there is one rule defined by commerce -- Create a new account for an anonymous order -- which I disabled because I don't want that functionality. I don't know why this would effect anything, but just mentioning it in case it does.

0

I ended up simply using commerce_cart_order_convert($order, $user); I was able to assign the order to the correct user, and I decided not to log him in at point in time. If I really need to log him in, I will do so after checkout is over when I don't need to access the checkout review page anymore.

  • You can also make use of the drupal.org/project/commerce_checkout_login module if you simply want to make it optional. – Ryan Szrama Dec 2 '13 at 19:15
  • This wouldn't work, as we have a unique checkout setup. We didn't want an Account Information pane on the checkout page, we wanted it all to process in the backend. – user1015214 Jul 23 '14 at 20:45
0

Commerce Checkout Login provides this functionality at checkout, transferring the current cart when doing so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.