Developer forum

Forum » Ecommerce - Standard features » Group sorting reset with API-import

Group sorting reset with API-import

Kurt Moskjær Andersen
Kurt Moskjær Andersen


I'm updating/inserting product groups from the API. The only attributes I update/insert, is Id, Number, Name and ShopId.

The group is saved with Dynamicweb.Ecommerse.Services.ProductGroups.Save(group).

My customer experiences, that after each import, the group sorting is reset, even though he has already made a custom sort from within Dynamicweb, on the existing groups.

Is the sorting reset/updated in some way, when I save a new group through the API?

Best regards
Kurt Moskjaer Andersen


Morten Snedker
Morten Snedker

Hi Kurt,

It is difficult to say what happens with no code example. Are you remembering to actually create a GroupRelation? Because, this is where the sorting is set. Like in this example:

        private void CreateGroupRelation(string ChildId, string ParentId, int Sorting)
            string _child = SanitizeId(ChildId);
            string _parent = SanitizeId(ParentId);

            Dynamicweb.Ecommerce.Products.GroupRelation relation = new Dynamicweb.Ecommerce.Products.GroupRelation();
            relation.Id = _child;
            relation.ParentId = _parent;
            relation.Sorting = Sorting;
            relation.IsPrimary = false;
            relation.InheritCategories = false;
            relation.Save(_child, _parent);

If you already have the relation (and the sorting), it should not reset if you just set some of the other properties and then save the relation. But again, it will be easier to answer properly with a piece of code to review.



Kurt Moskjær Andersen
Kurt Moskjær Andersen

Hi Morten,

Actually, I don't create a GroupRelation directly, like your code, but add groups as subgroups with: Services.ProductGroups.AddSubgroup(parentGrp, subGrp);

I guess the group relations are handled by the service?



You must be logged in to post in the forum