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

标签 drupal ubercart

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

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

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

在 $form_id == 'uc_cart_checkout_review_form' Hook 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


更新:


我一直想指出的是,用户不一定会像上面所说的那样自动登录。仅当 session 已保存时才会出现这种情况。但正如 safely impersonating another user 上的一篇文章所示在 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);

}

最佳答案

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

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

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

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

在我的脑海中,你会想要 UID(需要用户帐户),否则每个订单都将是 UID 0,因此基本上不可能有任何类型的报告/ View 或订单历史记录功能错了。

关于drupal - 是否可以在不创建新用户帐户的情况下使用 ubercart 进行匿名购买?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2608588/

相关文章:

drupal - 通过 Paypal 在 5 个月内处理信用卡

drupal - 无法在 Drupal 中编辑 block

drupal - 如何禁用本地服务器上的安全页面?

mysql - Drupal 8 数据库安装未连接到 docker mysql 容器

php - Drupal站点不断崩溃-求助调试

使用自定义 php 代码的 drupal 条件操作

php - Drupal 7 AJAX 通过 hook_menu 调用

drupal - 如何在 Ubercart 中显示可用库存数量?

drupal - 如何在 Drupal 7 中创建图片库?

drupal-7 - Drupal Commerce 和 SAP Business One