Try Now
More in this section

Forums / Ecommerce / Duplicate the functionality of the Department Widget

Duplicate the functionality of the Department Widget

2 posts, 0 answered
  1. Victor
    Victor avatar
    94 posts
    15 Jun 2011
    13 Mar 2012
    Link to this post
    Is it possible to duplicate the functionality of the Department Widget using the API.  Specifically what I want to do, is select all departments that contain products, along with the count of products.

    It can be done using SQL by joining the sf_taxa table to the sf_taxonomy_statistic table but this feels like a "hack"

    Is there a better way to do this using the API ?
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    14 Oct 2016
    16 Mar 2012
    Link to this post

    Yes, it's possible to obtain the statistics for each Taxonomy. The TaxonomyStatistics object will contain lots of useful data that might help you achieve the desired functionality. You can get the MarkedItemsCount - this is the count of all content items that have been assigned a particular taxon. You can also get the TaxonId, which will allow you to get the specific Department, and form there you can even get all products under that department. I've prepared a small sample demonstrating the usage of the above discussed objects below, hope you find it useful:
    public void GetTaxonomyStatsAndProductsInDepartment()
               var productsManager = CatalogManager.GetManager();
               var taxonomyManager = TaxonomyManager.GetManager();
               //get the statistics for the usage of Departments taxonomy
               var taxStat = taxonomyManager.GetStatistics()
                                       .Where(tS => tS.TaxonomyId == TaxonomyManager.DepartmentsTaxonomyId);
               foreach (var stat in taxStat)
                   //Get the count of items under that Department
                   var itemsCount = stat.MarkedItemsCount;
                   //Get the Department ID
                   var departmentId = stat.TaxonId;
                   //Get all products for the Department
                   var productsInDepartment = productsManager.GetProducts().ToArray().Where(p => p.GetValue<TrackedList<Guid>>("Department").Contains(departmentId));
    One thing worth noting is that in order to use the extension method GetValue() you'll need to add a reference to the Telerik.Sitefinity.Model namespace in your class.

    All the best,
    Boyan Barnev
    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
2 posts, 0 answered