Developer forum

Forum » Development » Custom sort

Reply
When looping products how do I write the sorting.?

Is there a dw controle for this?

foreach (Product p in g.Products)
{
sb.Append(p.Name);
}

Replies

 
Reply
Hi

A Product doesn't have a sorting in itself, but only to a group, because a product can be sorted differently in each of it's groups.

Therefore sorting is stored in the relation between a group and a product. We have an API class to handle this.

The code to change the sorting will look something like this:

ProductGroupRelation rel1 = new ProductGroupRelation(myProduct1.ID, myGroup.ID);
rel1.Sorting = 2;
rel1.Save(rel1.ProductID, rel1.GroupID);

ProductGroupRelation rel2 = new ProductGroupRelation(myProduct2.ID, myGroup.ID);
rel2.Sorting = 1;
rel2.Save(rel2.ProductID, rel2.GroupID);

This code will sort myProduct2 before myProduct1 in the group myGroup.

 - Lasse

 

You must be logged in to post in the forum