是否可以在不创建新用户帐户的情况下使用 ubercart 进行匿名购买?

发布于 2024-08-28 03:10:26 字数 1829 浏览 4 评论 0原文

我希望能够让匿名用户购买产品,但在购买产品时不创建新帐户。

不幸的是,新用户的创建似乎非常紧密地集成到 ubercart 的订购系统中。而且,由于订单模块是 ubercart 核心的一部分,因此它的行为不能轻易被覆盖。

覆盖新用户帐户创建的一种可能性是向 ubercart 提供虚假的匿名帐户:

在 $form_id == 'uc_cart_checkout_review_form' 处挂钩到 hook_form_alter,因为这是 ubercart 首先将 $order 关联到的地方一个 uid。将我们的提交功能添加到队列中:

//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 中进行匿名购买?

仅供参考 - 此时我有点被 ubercart 困住了,所以我不能使用其他东西。

谢谢!

D


更新:


我一直想指出,用户不一定会像上面所说的那样自动登录。仅当保存会话时才如此。但正如一篇关于在 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);

}

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

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

腻橙味 2024-09-04 03:10:26

不幸的是,它为匿名用户创建帐户,以便用户可以登录并查看他们的发票、订单历史记录等。

您可以只关闭发送的电子邮件而不激活帐户。这是在配置> Checkout:

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

我认为你最好不要破解 Ubercart,因为在这种情况下更新会更困难。至少这样,他们不会收到电子邮件,也不知道自己有帐户。

在我的脑海中,你会想要 UID(需要用户帐户),否则每个订单都将由 UID 0 表示,因此如果出现问题,基本上不可能有任何类型的报告/视图或订单历史记录功能。

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.

友谊不毕业 2024-09-04 03:10:26

我做了一个模块,允许匿名用户拥有购物车,并且结帐过程非常短。用户应在结帐表单中填写 4 个字段(姓名、电子邮件、电话和评论),此数据 + 购物车内容将在提交表单后发送给经理和客户。
模块稍后将在 drupal.org 上发布。

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.

滴情不沾 2024-09-04 03:10:26

ECO(Ubercart 的额外自定义)模块 为 Drupal 6.x / Ubercart 2.3 提供了一种实现此目的的方法。

它的工作原理是使用 hook_menu_alter 覆盖 cart/checkout/complete 路径的页面回调,并将其替换为自己的实现,该实现不会为匿名结账创建新的 Drupal 用户。

比直接破解 Ubercart 更好,但像这样替换 Ubercart 功能的核心部分仍然不理想。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文