+1-888-365-2779
Try Now
More in this section

Forums / Ecommerce / List Deparments programatically

List Deparments programatically

4 posts, 0 answered
  1. OC
    OC avatar
    129 posts
    Registered:
    17 Nov 2004
    18 Nov 2011
    Link to this post
    I need to build my own navigation widget for the Departments of a store.

    But I can't find any documentation on how to grab and list Departments. Only to simple crud operations. I suppose this is done the same way as other taxons, but I can't find any examples of that as well.

    Anyone?

    OC
  2. Tom
    Tom avatar
    5 posts
    Registered:
    23 Aug 2011
    18 Nov 2011
    Link to this post
    You can use the TaxonomyManager to get all of the Departments.

    Something like:

    var departmentsTaxonomy = TaxonomyManager.GetManager().GetTaxonomy(TaxonomyManager.DepartmentsTaxonomyId);

    Will get you the departments taxonomy. After that you can access each Department by iterating over the "Taxa" property of "departmentsTaxonomy".


    Regards,
    Thomas
  3. OC
    OC avatar
    129 posts
    Registered:
    17 Nov 2004
    22 Nov 2011
    Link to this post
    Thanks Thomas,

    I ended up using this code, witch works great:
        TaxonomyManager tm = TaxonomyManager.GetManager();
        var depatments = tm.GetTaxonomies<HierarchicalTaxonomy>().Where(t => t.Name == "Departments").SingleOrDefault();
     
       var subGroup = depatments.Taxa.Where(t => t.Title == itm.ToolTip).SingleOrDefault();
     
            if(subGroup!= null)
                foreach (HierarchicalTaxon t in subGroup.Taxonomy.Taxa.Where(a => a.Parent == subGroup))
                {
                    RadMenuItem newItm = new RadMenuItem(t.Title);
                    newItm.CssClass = itm.ToolTip + "MenuItem";
                    itm.Items.Add(newItm);
                     
                }


    BUT: How can I get the subgroup Taxas sorted?

    Thanks for any input!

    OC
  4. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    Registered:
    03 Nov 2014
    24 Nov 2011
    Link to this post
    Hi Ole,

    You can cast your first result to HierarchicalTaxon and then simply use the Subtaxa property of HierarchicalTaxon and use the OrderBy method of LINQ:

    var subGroup = depatments.Taxa.Where(t => t.Title == "Title").SingleOrDefault() as HierarchicalTaxon;
    foreach (HierarchicalTaxon t in subGroup.Subtaxa.OrderBy(t => t.Title))
    {
                         
    }

    Greetings,
    Lubomir Velkov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
4 posts, 0 answered