VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: Actlas on May 21, 2013, 12:44:09 PM

Title: How to display custom fields depending on usergroup?
Post by: Actlas on May 21, 2013, 12:44:09 PM
We are running VM 2.0.6.
We have certain custom fields that we would like to display only for users in a certain group.
I know my syntax is completely wrong at this moment. I copied some stuff I found on the forums. I should pick up a book on php.
Perhaps someone else knows how to do this?

I already started to modify default_customfields.php:

First I check if a user is in the groups with id 3 or 5 and I add it to a variable. (code added to top of default_customfields.php)

function is_verdeler(){
$user =& JFactory::getUser();
$user_id = $user->get('id');
if(true){
//include inherited groups
jimport( 'joomla.access.access' );
$groups = JAccess::getGroupsByUser($user_id);
}else{
//exclude inherited groups
$user =& JFactory::getUser($user_id);
$groups = isset($user->groups) ? $user->groups : array();
}
$return = 0;
if(in_array(3, $groups) OR in_array(5, $groups)){
$return = true;
}
return $return;
}
$isverdeler = $this->is_verdeler();


I would use the option admin only in the backend to mark fields which should be displayed for certain user groups only.
Then in default_customfields.php I would add a check beneath "if ($field->display) {..." to see if custom field should actually be displayed for the current user.

Anyone else who did this. Help would be greatly appreciated.
Title: Re: How to display custom fields depending on usergroup?
Post by: Actlas on May 25, 2013, 08:52:09 AM
Nobody had to implement this before?
Title: Re: How to display custom fields depending on usergroup?
Post by: Milbo on May 25, 2013, 11:18:03 AM
No, but interesting idea. You need of course the groups, the user is in.
Something like

$model = VmModel::getModel('users');
$user = $model->getCurrentUser();
if(in_array($user->virtuemart_shoppergroup_id,array(your shoppergroup ids))){

} else{

}


We overhaul the customfields for vm2.1. Yeyeh I talk since December about it. But this is an intersting idea to add.
Title: Re: How to display custom fields depending on usergroup?
Post by: Actlas on August 05, 2013, 10:05:53 AM
Has this been implemented by any chance?
Title: Re: How to display custom fields depending on usergroup?
Post by: Actlas on August 19, 2013, 10:01:48 AM
Bump...

The prices for shoppers are ok but the prices for the product options aren't adjusted by the tax and calculation rules for our distributors!

Nobody is in the same situation?