Developer forum

Forum » Development » Add user to assortments

Add user to assortments

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys and Happy New Year!

I have a requirement to extend the standard Swift functionality of adding new Users and include the assignment of the new user to the same Assortments as the parent user.

What would be the best (efficient) way of handling this?

I see that I can use the AssortmentService.GetAssortmentIdsByUser to gather the assortments of the current user but I could not find an explicit way of adding a user to assortments (or adding assortments to a user).

Thank you in advance for any suggestions.

Thank you,
Adrian


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

You have to do it through permisions on the assortment, like so:

          var permission = new AssortmentPermission(assortment, user);
          assortment.Permissions.Add(user.ID, permission);
          Dynamicweb.Ecommerce.Services.Assortments.SaveAssortment(assortment);
          permission.AssortmentID = assortment.ID;
          Dynamicweb.Ecommerce.Services.Assortments.SaveAssortmentPermission(permission);

I had to save twice: first the assortment, the the assortment permission. Not sure if that's still needed on recent versions.

Imar

 

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Imar,

Thank you very much for the detailed explanation.

Now it makes sense why I could not find an explicit method. I was looking in the wrong place :)

Maybe someone from Dynamicweb can express an opinion about this approach. In the meantime, I will use your suggestion.

Thank you very much,

Adrian

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

You put the user into a group that is in an assortment. Do not add users to assortments as it will cause performance issues very fast.

When you create new users you can add them to groups - and then they will automatically be in assortments that the group has access to.

BR Nicolai

 

You must be logged in to post in the forum