Developer forum

Forum » Templates » eCommerce subgroup sorting (not navigation sorting)

eCommerce subgroup sorting (not navigation sorting)

Jacob Storgaard Jensen
Reply

Hi,
I've got a pretty simple group structure in eCom, but making it work in frontend is quite hard...

  • Group1
    • Subgroup1
    • Subgroup2
  • Group2
    • Subgroup3
    • Sugrroup4

Important! No groups will ever be present more that one place in this structure!

In the frontend we would like to list them like this:
Initial page:
Group1
Group2
Etc.

On click on a level1 group we would like all products from the level2 groups (child groups of that level1 group) listed, but grouped by their level2 group.

  • Subgroup1
    • Product1
    • Product2
    • Product3
  • Subgroup2
    • Product4
    • Product5
    • etc.

I have managed to get the products grouped, but I can't seem to access the sort order from the backend. I know that the comment on this earlier has been: "it doesn't make sense to have that available because groups can be in more than one location in the group tree"... But in my case it sure does!

Here is my code (might be possible to do it better, but I'm no hardcore programmer):
 
@{
       var groups = GetLoop("Products").GroupBy(g => g.GetString("Ecom:Product.PrimaryOrFirstGroupID"));
                foreach (var group in groups)
                {
                    foreach (var p in group)
                    {
                        if (group.First()==p) {
                            var agroups = p.GetLoop("AssociatedGroups");
                            foreach (var agroup in agroups.Where(g => g.GetString("Ecom:Group.ID") == group.Key)) {
                                <h3>@agroup.GetString("Ecom:Group.Name")</h3>
                            }
                        }
                    }
                    <ul>
                        @foreach (var p in group)
                            {
                                here I have my code for each product              
                            }
                    </ul>
                }
            }

Replies

 
Nicolai Pedersen
Reply

Hm - difficult trick you can look at this one - that would be the sort value of the first instance of the product in the group...

ProductGroupRelation.GetProductGroupRelations("prod1", "group1")(0).Sorting

BR Nicolai

 
Jacob Storgaard Jensen
Reply

Hi Nicolai, I might have been a little unclear in my writing... Do you mean this is getting the sort value for the products or the subgroups?

Because the products are sorting just fine, it's the subgroups I have no control over... When I sort the products in backend they re-arrange in frontend accordingly, but when I sort the Subgroups the subgroups stay sortes in the order they were created in eCom.

If I sort the Level1 groups, the Level1 groups re-arrange just fine.

 
Nicolai Pedersen
Reply

Ok - then you need to get hold of a eCommerce.Products.GroupRelation instance for the subgroups and use the Sorting property.

 

You must be logged in to post in the forum