Developer forum

Forum » Development » Product / Group API

Product / Group API


Reply
Hi,

If I run this code, I get alot of products:
var products = Product.getAllProductsFromShop("SHOP2");

However, if I run this code, I dont get any groups. But the Group with that ID exists:
var parentGroup = Group.GetGroupsByIDs(new List<string>
{
    "SHOP2"
}).Cast<Group>().FirstOrDefault();

if (parentGroup == null)
{
    throw new Exception("DynamicWeb does not work as expected.");
}

Thanks,
Martin.

Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
Hi Martin

If I read your code correctly then "SHOP2" is a shop ID, and not a group ID which is why you don't get any groups. Group.GetGroupsByIDs expects group IDs and not shop IDs.

However if you do in fact have a group with the ID "SHOP2" then it needs to be available for the current Context language.

- Jeppe
 
Reply
Thank you for your answer.

In case other people need the same, here is the solution:

var groups = Group.getGroups();
groups.Sort(GroupCollection.SortBy.ShopOrder);
var allGroups = groups.Cast<Group>();

They are now sorted as in the admin module.

However - behold, it's not only the root groups you have in your collection, so we need to run a LINQ query to get the root groups like this:

var rootGroups = (from grp in allGroups
                           where grp.IsTopGroup == true && grp.ShopID == "SHOP2"
                           grp).Distinct();

 

You must be logged in to post in the forum