views:

367

answers:

1

I would like to be able to have anonymous users purchase a product but not have a new account created when they purchase it.

Unfortunately the creation of a new user seems to be very tightly integrated into ubercart's ordering system. And, because the order module is part of the ubercart core, it's behavior cannot be overridden easily.

One possibility for overriding the creation of a new user account is by supplying ubercart with a bogus anonymous account:

hook into hook_form_alter at $form_id == 'uc_cart_checkout_review_form' because this is where ubercart first associates the $order to an uid. Add our submit function to the queue:

//Find out if the user is anonymous:
global $user;
if ($user->uid == 0 ) {

  //Load a previously created anonymous user account
  $anonymous_user = mymodule_get_anonymous_user();

  //create the order and assign our anonymous_user_id to it
  $order = uc_order_load($_SESSION['cart_order']);
  $order->uid = $anonymous_user->uid;
  uc_order_save($order);

  //Assign the global user our anonymous user uid
  $user->uid = $anonymous_user->uid;

}

But what I really need is to be able to have an anonymous purchase without being forced to create a new account, this solution does not work for me.

Apart from which, using this technique will automatically login the anonymous_user into our bogus_anonymous_user account. Which is definitely something I don't want.

Is there a better non-duct-tape way around the creation of a new user account for anonymous purchases in ubercart?.

AND FYI - at this point I'm kind of stuck with ubercart so I cannot use something else.

Thanks!

D

+4  A: 

Unfortunately, it creates accounts for anonymous users so a user can log in and see their invoice, order history, etc.

You could just turn off the email that gets sent and not make accounts active. This is in Configuration > Checkout:

Send new customers a separate e-mail with their account details.
New customer accounts will be set to active.

I think you are better off -not- hacking Ubercart because it will be harder to update in that case. At least this way, they don't get an email, and they don't know they have an account.

Off the top of my head, you would want the UID (requiring a user account) otherwise every order would be by UID 0, thus making it basically impossible to have any kind of reporting/views or order history functionality should something go wrong.

Kevin
Thanks, but the other thing that ubercart does when it creates a new account for an anonymous user is to publish that info on the checkout complete page. If I don't want that user to know about the account I'll need a way around that too?
DKinzer
OK, I see that I can edit that checkout completion message. So this has been very helpful! Thanks!
DKinzer

related questions