Developer forum

Forum » Development » Getting ecommerce groups by SQL

Getting ecommerce groups by SQL

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

What is the recommended way to get Ecommerce groups from a custom SQL statement? I noticed that Load on GroupCollection is marked as obsolete so I wondered what the alternative is.

Also, is there a way to traverse child groups? The API lets you browse Parent Groups but I can't find references to the child groups. Never mind that second question. Intellisense messed with my head. Found the Subgroups.

Thanks,

Imar


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

I do not think there is an alternative.

But it is simple to do:

                    Dim groups As New GroupCollection()
                    Using reader As IDataReader = Dynamicweb.Data.Database.CreateDataReader(String.Format("SELECT * FROM [EcomGroups] WHERE [GroupID] IN ('GROUP1')"))
                        While reader.Read()
                            group = New Group(reader)
                            groups.Add(group)
                        End While
                    End Using

We go through the objects and check against the properties - groups are usually cached.

BR Nicolai

Votes for this answer: 1
 
Dmitrij Jazel
Reply

Hi Imar, this is the way we traverse EcomGroups :-)

@helper RenderNavigation_ECOM(Dynamicweb.eCommerce.Products.GroupCollection groupCollection, int lvl, int productPageID)
{
    groupCollection = (groupCollection == null)
        ? new Dynamicweb.eCommerce.Shops.Shop((string)Dynamicweb.Frontend.PageView.Current()
            .Area.get_Value("AreaEcomShopID"))
            .get_TopLevelGroups((string)Dynamicweb.Frontend.PageView.Current()
            .Area.get_Value("AreaEcomLanguageID"))
        : groupCollection;

    foreach (var group in groupCollection)
    {
        string li_class = string.Format("lvl{0}", lvl.ToString());
        <li class="@li_class">

            @{
                string link = string.Format("/Default.aspx?id={0}&GroupID={1}", productPageID.ToString(), group.ID);
                if (group.Subgroups.Count > 0)
                {
                    link = "#";
                }
            }
            <a href="@link" class="@li_class">@group.Name</a>
            @if (group.Subgroups.Count > 0)
            {
                string ul_class = string.Format("lvl{0}", (lvl + 1).ToString());
                <ul class="@ul_class">
                    @RenderNavigation_ECOM(group.Subgroups, lvl+1, productPageID) // recursive calling RenderNavigation_ECOM()
                </ul>
            }
        </li>
    }
}

/Dmitrij

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Dmitrij,

Thanks, but that traverses the entire group tree, someting I am trying to avoid. Instead, I want to get a group by its group number and then traverse child groups. It seems Nicolai's suggestion is the way to do it.

Thanks both!

Imar

 

You must be logged in to post in the forum