Much discussion has arisen over anonymous checkout in Ubercart. In its most recent incarnation, UC effectively allows a customer to check out anonymously only once, because it captures the anonymous customer's e-mail address and automatically creates a user account for the customer. If the customer attempts another UC transaction using the same e-mail address, UC asks the customer to either log in or use a different e-mail address. Some people like this approach; some do not. To date, Ubercart and Drupal have been philosophically centered on a user-account experience, and that is unlikely to change, thus some sort of workaround is necessary.

It is possible to create a true anonymous user checkout in UC, a checkout that (1) does not create an account for the anonymous user; and (2) allows the anonymous user to provide the same e-mail address in repeated transactions without logging in. It's relatively easy to do. Its only drawback is this: it allows ONLY anonymous checkout, and does not allow creation of user accounts. There's probably a way to make anonymous checkout optional, but I don't need that feature and haven't pursued it. Here's how to enable anonymous-only checkouts:

First, create a new user role called, for example, "temporary." Then enable the Ubercart "add a role" feature. Enable that feature on all products, and set the role "temporary" as the role granted upon purchase of each product.

Next, in your UC store's conditional actions, disable all of the notices that go out when that role is granted. (No need for all the spam.)

Then, using the Rules module, create a rule that checks to see whether an updated user account has the role "temporary" and, if it does, deletes the user account. Once checkout is complete, poof, the user account is gone, and the same person can use the same e-mail to log in the next time.

Happily, this does not lose your customer's information or the order information, because all of that data (including the customer's e-mail address) is stored separately by Ubercart. You can still access all of the order and customer details through the ubercart orders features, and the data remains in the Drupal database, available for retrieval by Views.

Comments

mcfilms’s picture

This is a useful post. It even looks like it is possible to switch between registered users and anonymous with some extra configuration.

A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com

Anonymous’s picture

You just saved me hours of screwing with the Ubercart API!

parisek’s picture

What if I want connect order to user based on order email no matter if is user logged in or not (anonymous checkout)?

Simply I have hidden account which connects orders with same email. Right user account is used from inserted order email address. It is possible without hack ubercart core?

Thanks

Anonymous’s picture

Sure, you just need to make a simple module and use a few hooks - checkout and order most specifically. Then you can call the Drupal mail function and send the mail with your context available. I have some sample code from a recent project that may help if you'd like to see it though it won't be 'stable' for a couple weeks. It's missing any sort of UI and relies on the Rules UI to handle the user that gets created - both small issues for portability.

parisek’s picture

Thank you for quick answer, if you post any code i appreciate it. So basically what you mean is disable standard ubercart checkout (because function uc_cart_complete_sale cannot be hooked)?

parisek’s picture

Finnaly I hack core of Ubercart because it is really difficult to hook ubecart order handling. So I completely disable site login and allow only anonymous checkout. New orders are grouped by email address which is unique for every user and this helps me tracking of returning customers.

So if you want similar function just comment this line (dont forget to repeat when updating):

if ($user->uid == 0 && !empty($arg2['primary_email'])) {
        if (db_result(db_query("SELECT uid FROM {users} WHERE LOWER(mail) = LOWER('%s')", $arg2['primary_email'])) > 0) {
          form_set_error('panes][customer][primary_email', t('An account already exists for your e-mail address. You will either need to login with with this e-mail address or use a different e-mail address.'));
        }
}

Located in file: ubecart/uc_cart/uc_cart_checkout_pane.inc in function uc_checkout_pane_customer($op, &$arg1, $arg2) on lines 151-155

jgoodwill01’s picture

Any suggestions on how I would go about checking to make sure the "temporary" user that is being deleted is not also a site admin or has other roles assigned?

I like the setup you have described here but I not want our valid users accidentally deleting their accounts if they make a purchase.

Any help is appreciated. Thanks!

partyp’s picture

I have a few managers of my site which are the only other people using the site other than anonymous. Each of these users are assigned to a "manager" role. I just added another condition to the same rule... So all together it says,.. IF user has "temporary" role AND user is NOT a "manager" role then delete user.

Hope that helps :)

topdawg’s picture

Hmm.. I went through all the steps, and it didn't work for me. One thing that's different is that you say delete user, but I only see the option to delete "role." I'm not sure if that's an issue, but am bringing this up. I'm using drupal v6.

Also, after assigning the temporary role to a product, it doesn't really show anywhere that I can see, and only the add feature shows up, then when I re-attempt to add the role feature, it says that it's already there and cannot be added. (Red alert)

I would appreciate help, thanks
Joe

gregaltuna’s picture

Hey all.. I'm experiencing the same thing, and need this working, pronto. I don't get the "delete user" option...

Let me explain something to you. Um, I am not "Mr. Altuna". You're Mr. Altuna. I'm the Greg. So that's what you call me. You know, that or, uh, His Gregness, or uh, Greggie, or El Gregerino if you're not into the whole brevity thing.

geoffAuthor’s picture

I am building a site on Drupal 7/Ubercart 2.0. For some reason, when the customer is checking out the the temporary role is not assigned to a user. - This is the point, where it fails in the first place. Also, like somebody else in this set of conversation mentioned, there's no option to delete the user, it only mentions the role. So, how do I assign the role in checkout?

luthien’s picture

I used the code from this post and it works fine.

http://www.ubercart.org/comment/56233

joshuautley’s picture

I just wanted to chime in for people who come across this thread.

D7 Ubercart now allows you to do this.

Check: Enable anonymous checkout.

And

Check: Allow anonymous customers to use an existing account's email address.

Being a long time D6 user I missed the second checkbox during setup and went searching for an answer.

Josh Utley, President & CEO
Intrepid Network Inc. | Multimedia Services & Business Solutions

"Our mission is to provide a more personable multimedia service along with the highest quality business solutions."