Author Topic: How to display custom fields depending on usergroup?  (Read 1478 times)

Actlas

  • Jr. Member
  • **
  • Posts: 69
How to display custom fields depending on usergroup?
« 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)

Code: [Select]
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.

Actlas

  • Jr. Member
  • **
  • Posts: 69
Re: How to display custom fields depending on usergroup?
« Reply #1 on: May 25, 2013, 08:52:09 am »
Nobody had to implement this before?

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10040
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: How to display custom fields depending on usergroup?
« Reply #2 on: May 25, 2013, 11:18:03 am »
No, but interesting idea. You need of course the groups, the user is in.
Something like
Code: [Select]
$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.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Actlas

  • Jr. Member
  • **
  • Posts: 69
Re: How to display custom fields depending on usergroup?
« Reply #3 on: August 05, 2013, 10:05:53 am »
Has this been implemented by any chance?

Actlas

  • Jr. Member
  • **
  • Posts: 69
Re: How to display custom fields depending on usergroup?
« Reply #4 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?