Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Drupal/Ubercart角色自定义价格php代码_Php_Drupal_Roles_Ubercart - Fatal编程技术网

Drupal/Ubercart角色自定义价格php代码

Drupal/Ubercart角色自定义价格php代码,php,drupal,roles,ubercart,Php,Drupal,Roles,Ubercart,我正在建立一个批发食品的电子商务网站,产品的价格会根据用户的登录情况而变化。我看了会员定价,基本上我能找到的每一个模块都可以改变价格,但它们要么是针对drupal 6的,要么不是我想要的。我正在使用带ubercart 3的Drupal 7 我找到了这个模块。它在产品创建中添加了一个字段,允许将自定义php代码添加到每个产品中,这正是im所追求的。但是我对php不是很在行,这就是为什么我一直在寻找模块而不是修改代码 我现在得到的是: if ([roles] == 'test company') {

我正在建立一个批发食品的电子商务网站,产品的价格会根据用户的登录情况而变化。我看了会员定价,基本上我能找到的每一个模块都可以改变价格,但它们要么是针对drupal 6的,要么不是我想要的。我正在使用带ubercart 3的Drupal 7

我找到了这个模块。它在产品创建中添加了一个字段,允许将自定义php代码添加到每个产品中,这正是im所追求的。但是我对php不是很在行,这就是为什么我一直在寻找模块而不是修改代码

我现在得到的是:

if ([roles] == 'test company') {
  $item->price = $item->price*0.8;
}
除了[roles]部分是错误的,它只会抛出错误。我试着用$users->uid=='1'这样的东西来钩住这样一个用户,但也没用

正确的变量是什么

谢谢你试试这个

$user->roles是分配给用户的角色数组

希望它有帮助

试试这个

$user->roles是分配给用户的角色数组


希望它能帮助您使用UC Price API制作自己的模块:


另请参见:

使用UC Price API制作您自己的模块:


另请参见:

谢谢!正是我想要的。谢谢!正是我想要的。
global $user; // access the global user object
if(in_array("administrator",$user->roles)){ // if its administrator
 $item->price = $item->price*0.8;
}elseif(in_array("vip",$user->roles)){ // if its a vip
 //..
}elseif(in_array("UserCompanyX",$user->roles)){ // if its a user from company X
 //..
}
if($user->roles[OFFSET] == "ROLE"){
 // price calculation
}
function example_uc_price_handler() {
  return array(
    'alter' => array(
      'title' => t('Reseller price handler'),
      'description' => t('Handles price markups by customer roles.'),
      'callback' => 'example_price_alterer',
    ),
  );
}

function example_price_alterer(&$price_info, $context, $options = array()){
  global $user;
  if (in_array("reseller", $user->roles)) { //Apply 30% reseller discount
    $price_info["price"] = $context["subject"]["node"]->sell_price - (
                           $context["subject"]["node"]->sell_price * 0.30) ;     
  }
  return;
}