Anonymous Customer Drupal Account Optional Patch


This patch for Ubercart beta 7 makes the creation of a Drupal user account for an anonymous customer optional.

Ubercart creates a Drupal user account for each customer, even if the site configuration indicates that only the site administrator can create a user account. This rather large patch changes five files in Ubercart to prevent that. If this patch is applied and the site is configured such that only the site administrator can create Drupal accounts, the patched Ubercart will respect this and reference the customer in the Ubercart database tables by the customer's email address rather than using the Drupal user ID. By using the email address as a key to the Ubercart tables, all the same reporting functions are supported as in the unpatched version. Logged in Drupal users are treated exactly the same as they would be without this patch.

If the site is configured to allow others than the site administrator to create Drupal user accounts, the patch will produce no change from default Ubercart behavior.

The patch changes SQL used to reference Ubercart tables to use the email address as an alternative to the Drupal user ID to identify the customer. Unfortunately this patch changes only the MySQL version of the SQL, so the patch will not work with PostgreSQL. If someone would provide the necessary PostgreSQL version the patch could be enhanced.

anon_cust_patch.tar.gz5.48 KB
paacific's picture
Joined: 01/16/2009
Juice: 2
Plz help with Drupal 5.x-1.6 !

I downloaded Ubercart 5.x-1.6 (ubercart-5.x-1.6.tar.gz)

and tried to apply your patch but was unable to do it correctly/its not working.

I would really appreciate if you could provide some help in any way.

screenshot.jpg 92.24 KB
Diversicon's picture
Joined: 02/04/2009
Juice: 2
Compatibility Question

I am also looking for this functionality but I can't discern from "Compatibility: "Ubercart Beta 7" if this will work with 1.x or 2.x. I've browsed the site but have been unable to determine if it should work (beyond doing a backup and taking a shot).

Could someone please clarify the compatibility for this contribution.


steingard's picture
Joined: 03/30/2008
Juice: 70
Re: Anonymous Customer Drupal Account Optional Patch

I tottaly would love to have this in the latest UC 1.x (may even sponsor it)!

How does this work if a store admin creates an order where the cust doesnt have an email address ( I guess it's be cust #0 like usual?)

nkinkade's picture
Joined: 06/11/2009
Juice: 22
Another small patch

The following patch seems to effectively prevent Ubercart from creating a Drupal user for anonymous checkouts. It's not as complete a solution as the patch that started this thread, but one advantage is that it only requires two very small changes to a single Ubercart file:

--- a/sites/default/modules/ubercart/uc_cart/uc_cart.module
+++ b/sites/default/modules/ubercart/uc_cart/uc_cart.module
@@ -1117,7 +1117,11 @@ function uc_cart_complete_sale($order, $login = FALSE) {
   global $user;

   // Logic to create new user if necessary:
-  if ($order->uid == 0) {
+  // CC doesn't want Ubercart to create a new Drupal user so let's set
+  // this if statement to something that will never evaluate to true.
+  // If uid is ever ROFL! then I'll quit my job and paddle off into
+  // the Pacifc in a canoe. (nkinkade 2009-06-17)
+  if ($order->uid == 'ROFL!') {
     // Check for an existing user account with the e-mail address from checkout.
     $result = db_query("SELECT uid FROM {users} WHERE mail = '%s'", $order->primary_email);

@@ -1209,7 +1213,9 @@ function uc_cart_complete_sale($order, $login = FALSE) {
   // Clear our the session variables used to force the cart workflow.
   unset($_SESSION['cart_order'], $_SESSION['do_complete'], $_SESSION['new_user']);

-  ca_pull_trigger('uc_checkout_complete', $order, $user->uid == 0 ? $account : $user);
+  // Compare uid against -1 which will always fail, forcing the use of $user.
+  // (nkinkade 2009-06-17)
+  ca_pull_trigger('uc_checkout_complete', $order, $user->uid == -1 ? $account : $user);

   return $output;


Ypthor's picture
Joined: 12/17/2009
Juice: 7

Thanks, that seems(!) to work in 6.x-2.0, with a slight modification.