Duplicate the functionality of the Department Widget

Posted by Community Admin on 05-Aug-2018 23:46

Duplicate the functionality of the Department Widget

All Replies

Posted by Community Admin on 13-Mar-2012 00:00

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 ?

Posted by Community Admin on 16-Mar-2012 00:00

Hello,

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

This thread is closed