1

我正在尝试向订购金额等于或大于 100.00 欧元的用户授予特定角色:条件操作非常接近成就,但我在操作上失败了(需要 PHP)。

如何在 Ubercart 条件操作中使用 PHP 操作授予角色?

4

2 回答 2

3

基于几个相关的 线程,我认为您想添加一个“执行自定义 PHP 代码”操作,如下所示(在第 3 行中替换为适当的角色名称):

if($account) {
  $uid = $account->uid;
  $role_name = 'YOUR SPECIFIC ROLE NAME GOES HERE';
  $rid = db_result(db_query("SELECT rid FROM {role} WHERE name = '%s'", $role_name));

  // Load user object
  $account = user_load(array('uid' => 1));

  // Save the user object with the new roles.
  if ($account !== FALSE) {
    $roles = $account->roles + array($rid => $role_name);
    user_save($account, array('roles' => $roles));

  watchdog('user', 'uc ca added role to Ubercart created user');
于 2010-08-20T23:50:36.280 回答
3

提供的代码需要关闭两个括号。我删除了if语句,从订单中获取了 uid 并修复了 uid 设置(它是“1”):

  $uid = $order->uid;
  $role_name = 'customer';
  $rid = db_result(db_query("SELECT rid FROM {role} WHERE name = '%s'", $role_name));

  // Load user object
  $account = user_load(array('uid' => $uid));

  // Save the user object with the new roles.
  $roles = $account->roles + array($rid => $role_name);
  user_save($account, array('roles' => $roles));

  watchdog('user', 'uc ca added role to Ubercart created user');
于 2011-08-15T17:36:54.983 回答