Developer forum

Forum » Development » Create ProductGroups and add values for ProductGroupFields

Create ProductGroups and add values for ProductGroupFields

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I have a situation where I need to grab some data from an external system and use it to create ProductGroups and populate some values on some custom ProductGroupFields.
What would be the most efficient way to handle the ProductGroupFields part using the API?

Thank you,
Adrian


Replies

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

One more thing. Can I control the sort order of subgroups under one parent Group?

By "control" I mean save a value for the sort order upon inserting a Subgroup or editing the sort order of an existing Subgroup.

Thank you,

Adrian

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Adrian

Use group.ProductGroupFieldValues to add an update group field values - save the group using the groupservice.

GroupRelation object controls the parent/child relation between groups - there is a table in the database as well. The relation has a sortorder as int that will control the order of the subgroups.

BR Nicolai

Votes for this answer: 1
 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply

Hi Adrian,

An example of NP's suggestion:

Dynamicweb.Ecommerce.Products.Group g = new Group
{
 Name = "myGroup",
 Description = "myDescription",
};
Dynamicweb.Ecommerce.Services.ProductGroups.Save(g);

// apply group field data
var groupField = new ProductGroupField("CustomField1") { SystemName = "CustomField1" };
var fv = new Dynamicweb.Ecommerce.Products.ProductGroupFieldValue(groupField, "new info");
g.ProductGroupFieldValues.Add(fv);

groupField = new ProductGroupField("CustomField2") { SystemName = "CustomField2" };
fv = new Dynamicweb.Ecommerce.Products.ProductGroupFieldValue(groupField, 246);
g.ProductGroupFieldValues.Add(fv);

Dynamicweb.Ecommerce.Services.ProductGroups.Save(g);

// Group.ParentGroups.Add(group) method does not expose sort order - you need to use a GroupRelation for that
string parentId = "GROUP7";
Dynamicweb.Ecommerce.Products.GroupRelation gr = new GroupRelation
{
 ParentId = parentId,
 Id = g.Id,
 Sorting = 1
};

gr.Save(g.Id, parentId);

// apply shop-group relation
Dynamicweb.Ecommerce.Shops.ShopGroupRelation sgr = new Dynamicweb.Ecommerce.Shops.ShopGroupRelation
{
 ShopId = "SHOP1",
 GroupId = g.Id
};

sgr.Save("SHOP1", g.Id);

 

/snedker

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

Thank you very much for the info. It is extremely useful.


Adrian

 

You must be logged in to post in the forum