2012-07-24 17 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