Developer forum

Forum » Ecommerce - Standard features » Group saved subscriber

Group saved subscriber

Andreas Pettersson
Reply

 

Hi,

I tried to implement the group aftersave subscriber. I get the group but I dont have any more data then the groupId and the name for the group. 
I need the parentgroups for the newly created group, becuase i need to check if the newly created group is in a specific product group.

I tried to do GetGroup on the new groupid but i get null as respons..
How can i do to get the parentgroups for the newly created group? And are there anyway to get the highest group from a subgroup? 

 

Regards

Andreas


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi

The groups are many to many - so there is a supporting table and object called GroupRelation

Take a look at Dynamicweb.Ecommerce.Products.GroupRelation.GetGroupRelationsByChildId or ByParent

BR Nicolai

 
Andreas Pettersson
Reply

Hi,

Thanks but it count 0 in the subscriber method. Any other way i can get the newly created group relation/parent? 

Regards
Andreas

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

I am not sure I follow.

In the notification, you get the newly created group. In your first code example you try to retrieve that same group from the GroupService - which makes no sense since you already have that object.

When the group is created, it has no relations yet - so after group has been created and saved to database, you only have a group - there are no relations (parents or children). If you are using the UI, the group is first created and saved to database, then the notification is fired, and then just after, the relation is created. The relation needs to group first, so the group is saved first.

When the relation is created there is another notification - Notifications.Ecommerce.Group.RelationUpdated - that will hold the ID of the group and its new parent. So maybe you need to listen for that - and make sure that it is a new group and not just an update from an existing group.

A solution could be in your groupsaved notification to save the groupid into request.items if the group is new, and then in the RelationUpdated notification react if .Items contains the groupid that the relation is created for.

Alternatively please specifiy what you are trying to do - there might be another way.

BR Nicolai

 
Andreas Pettersson
Reply

The thing I want to do is:

When you add a new group under a specific parent group (that is a specific group) i want to add the newly created group id to a specific product field option.
Like this: 

/Andreas

 
Andreas Pettersson
Reply

Now i used the relationupdated subscriber and get the groups from there to see if it is correct group and in that case add fieldoption to productfield. Because there you hade the child and parentId groupid so i can get both groups from DW api.

/Andreas

 

You must be logged in to post in the forum