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
Reply

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-2
|----User-3
|--Department-2
|----User-4
|----User-5
|----User-6
|--User-10 (Company-Admin)

Company-2
|--Department-1
|---User-A
.....

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?

Replies

 
Nicolai Pedersen
Nicolai Pedersen
Reply

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: https://doc.dynamicweb.com/api/html/25aa3b0f-43c4-65ea-948c-131abd318626.htm

And locate the group:

https://doc.dynamicweb.com/api/html/9247917b-9eb6-1cd4-ea5b-9653bfc333f4.htm

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