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
Reply

Hi,

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

Replies

 
Morten Snedker
Morten Snedker
Reply
This post has been marked as an answer

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.

BR
Morten

 


 
Votes for this answer: 1
 
Kurt Moskjær Andersen
Kurt Moskjær Andersen
Reply

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?

/Kurt

 
Morten Snedker
Morten Snedker
Reply
This post has been marked as an answer

Hi Kurt,

Having group "Parent" and adding subgroups 01..05 and add sorting to these groups, and followingly execute this code:

            Dynamicweb.Ecommerce.Products.Group groupNew = new Dynamicweb.Ecommerce.Products.Group();
            groupNew.Name = "msn";
            Dynamicweb.Ecommerce.Services.ProductGroups.Save(groupNew);

            Dynamicweb.Ecommerce.Products.Group groupParent = Dynamicweb.Ecommerce.Services.ProductGroups.GetGroup("GROUP37");
            Dynamicweb.Ecommerce.Services.ProductGroups.AddSubgroup(groupParent, groupNew);

- my sorting remains intact. Though, the added group will have sortorder=0, as the AddSubgroup does not support setting the sort order. But I cannot reproduce a scenario that invalidates the already existing sort order of the original groups.

BR
Morten

 

Votes for this answer: 1
 
Kurt Moskjær Andersen
Kurt Moskjær Andersen
Reply

Thanks, Morten.

I'm using the exact same approach, but have experienced a periodic change of sort order, in previous versions of DW (9.6.1)

/Kurt

 

You must be logged in to post in the forum