Developer forum

Currently discussing: Plans to implement a Consent module for GDPR compliance.

Join the discussion!

Forum » Templates » Get Users from same group

Get Users from same group

Bjørn Kamfjord

So, I'm looking for some tips for how to set up some functionality. What I want to achieve is this.

When a "Department Manager" from one of my Customers shops on my site, she finds a product that she want to buy for some of her employees. So when she opens the product, there should be a list of her employees as a drop down above the size variants. She picks an employee, "Peter Parker" and gets his size preference predefined to small.  (if there is a preference). Add to cart, with a comment like "For: Peter Parker". She then picks "Tony Stark" and have his size prefrences ready and add to cart, repeat for all the relevant employees.

To create this we are thinking of Creating users in backend with custom-fields for size prefrences.

We'll sort them into groups for each Company and department like this:

Company-1 (Group)
|--Department-1 (Sub-Group)
|----User-1 (Department-Admin)(User)
|--User-10 (Company-Admin)


If I do it like this, is there a way for a User to list out his/hers "sibling" users? So User-1 will se User-2 and User-3 but not User-4,5,6 etc. ?

I off course need to have som sort administration of this as well....

Is there another aproach to solve this?


Nicolai Pedersen
Nicolai Pedersen

Hi Bjørn

I think you can do this. On a department admin user, you can take that user object, look at the users groups properties and find all users in there. That can be done from the product template if written in Razor. The size information is then easy to map to a variant.

You can get the current logged in user using User.Current:

And locate the group:

So something like

var user = Dynamicweb.Security.UserManagement.User.GetCurrentExtranetUser();
var group = user.Groups[0]; //Expection exactly one group - not 0 not 2 or more
var users = group.Users;
foreach(var u in users)
        var name = u.Name;

When adding the product to the cart, you can if you want, get one line for each person by having a custom orderline field for the name and fille that out when adding the product to the cart.


You must be logged in to post in the forum