2012-07-24 21 views
1

Im建立一个批发食品的电子商务网站和产品定价根据用户登录改变。我看了会员定价,基本上每个模块,我可以找到与做改变价格,但他们要么为Drupal 6或不真正什么后即时。我使用Drupal 7与ubercart 3.Drupal/Ubercart定制价格PHP代码的角色

我发现这个模块http://drupal.org/project/uc_custom_price。它在产品创建过程中添加了一个字段,允许将自定义的PHP代码添加到每个单独的产品中,这正是后面的内容。但即时通讯不是那么好,这就是为什么我一直在寻找模块,而不是改变代码。

在此刻得到了什么香港专业教育学院是:

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

除[角色]部分是使用有错误的东西,它只是引发错误。我曾尝试使用诸如$ users-> uid =='1'之类的东西来尝试挂钩到这样的用户,但这也没有奏效。

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

感谢

回答

1

试试这个Drupal 7 global $user object

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 
} 

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

希望它帮助

+0

谢谢!正是我以后的事情。 – Weighsone 2012-07-24 20:18:22

0

请与UC价格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