3

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

不幸的是,新用户的创建似乎非常紧密地集成到 ubercart 的订购系统中。而且,因为 order 模块是 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);

}
4

3 回答 3

4

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

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

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

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

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

于 2010-04-09T15:39:42.483 回答
1

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

于 2010-12-09T18:23:25.830 回答
1

ECO(Ubercart的额外定制)模块为 Drupal 6.x / Ubercart 2.3 提供了一种方法。

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

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

于 2011-08-28T02:21:31.060 回答