1

我正在建立一个批发食品的电子商务网站,产品的价格会根据登录的用户而变化。我查看了会员定价,基本上我能找到与改变价格有关的每个模块,但它们要么适用于 drupal 6,要么不适用我真的在追求什么。我将 Drupal 7 与 ubercart 3 一起使用。

我找到了这个模块http://drupal.org/project/uc_custom_price。它在产品创建中添加了一个字段,允许将自定义 php 代码添加到每个单独的产品中,这正是我所追求的。但是我对 php 不是很好,这就是为什么我一直在寻找模块而不是更改代码的原因。

我现在得到的是:

if ([roles] == 'test company') {
  $item->price = $item->price*0.8;
}

除了 [roles] 部分在那里使用是错误的,它只会引发错误。我尝试过使用 $users->uid =='1' 之类的东西来尝试挂接到这样的用户,但这也不起作用。

放在那里的正确变量是什么?

谢谢

4

2 回答 2

1

试试这个Drupal 7 全局 $user 对象

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
}

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

希望它有所帮助

于 2012-07-24T11:27:40.877 回答
0

使用 UC Price API 制作您自己的模块: http ://www.ubercart.org/docs/developer/11375/price_api

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;
}

另见:http ://www.ubercart.org/forum/development/14381/price_alteration_hook

于 2013-04-03T04:47:01.867 回答