Is it possible to anonymous purchases with ubercart without creating a new user account?

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

Unfortunately, creating a new user seems to be very tightly integrated into the ubercart ordering system. And since the order module is part of the ubercart kernel, its behavior cannot be easily overridden.

One possibility to override the creation of a new user account is to provide ubercart with a false anonymous account:

bind hook_form_alter to $ form_id == 'uc_cart_checkout_review_form', because that's where ubercart binds $ order to 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;

}

, , .

, , anonymous_user bogus_anonymous_user. .

ubercart?.

FYI - ubercart, - .

!

D


Update:


, , , . , . , Drupal, :

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

}
+3
3

, , , ..

. > :

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

, - Ubercart, . , , , , .

UID ( ), UID 0, - / , - .

+4

, . 4 (, , ), + . drupal.org.

+1

ECO ( Ubercart) Drupal 6.x/Ubercart 2.3.

It works by using hook_menu_alterto override the page callback for the path cart/checkout/completeand replace it with its own implementation, which does not create a new Drupal user for anonymous checks.

Better than hacking Ubercart directly, but it's still not ideal for replacing the bulk of Ubercart features like this.

+1
source

Source: https://habr.com/ru/post/1740474/


All Articles