如何在Ubercart中授予特定角色?

时间:2010-08-20 15:57:38

标签: php drupal content-management-system e-commerce ubercart

我正在尝试向订购金额等于或大于100.00€的用户授予特定角色:条件操作非常接近成就,但我没有采取行动(需要PHP)。

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

2 个答案:

答案 0 :(得分:3)

基于几个related threads,我认为您希望按照以下方式添加“执行自定义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');

答案 1 :(得分: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');