Posted on 07/03/2022 14:03:31
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