david
david

Reputation: 33547

Is it possible to have anonymous purchases with ubercart without the creation of a new user account?

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


Update:


I've been meaning to point out that it's not necessarily true that a user would be automatically logged in as stated above. This is true only if the session is saved. But as shown in an article on safely impersonating another user in Drupal, one can bypass the auto login as follows:

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

  $original_user = $user;

  session_save_session(FALSE);  //Prevents the auto login amongst other effects.

  //Load admin user
  $user = user_load(array('uid' => 1));


  //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);

  //Set things back to normal.
  $user = $original_user;
  session_save_session(TRUE);

}

Upvotes: 3

Views: 4218

Answers (3)

grumbler
grumbler

Reputation: 926

The ECO (Extra Customizations for Ubercart) module provides a way to do this for Drupal 6.x / Ubercart 2.3.

It works by using hook_menu_alter to override the page callback for the cart/checkout/complete path and replace it with its own implementation that does not create a new Drupal user for anonymous checkouts.

Better than hacking Ubercart directly, but it's still non-ideal to swap out a core chunk of Ubercart's functionality like this.

Upvotes: 1

Vlad Savitsky
Vlad Savitsky

Reputation: 1200

I have done a module that allow anonymous users to have a cart and checkout process is very short. User should fill 4 fields at checkout form (name, email, phone and comment) and this data + cart content will be sent to managers and to customer after form submitting. Module will be published at drupal.org later.

Upvotes: 1

Kevin
Kevin

Reputation: 13226

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.

Upvotes: 4

Related Questions