Get products by department

Posted by Community Admin on 05-Aug-2018 14:32

Get products by department

All Replies

Posted by Community Admin on 30-Nov-2011 00:00

Hello

Our project requires mostly custom ecommerce modules to replace the out of the box controls. For a product listing control, based on knowing the department name, how can I get a list of products for that department? I followed several examples of finding items by taxon but they all use GetItemsByTaxon, a method of ContentDataProviderBase, which is not available to Catalog items (CatalogDataProviderBase).

thanks

Posted by Community Admin on 06-Dec-2011 00:00

Hello Nick,

Unfortunately our current model does not allow a proper IQueryable implementation for GetItemsByTaxon for the CatalogManager. The only workaround is this one:

var catalogManager = CatalogManager.GetManager();
var taxonId = new Guid("FF27E7C4-F6E6-4C10-810D-244CF7143E6F");
var products = catalogManager.GetProducts();
 
foreach (var product in products)
    if (product.Organizer.TaxonExists("Department", taxonId))
    
    

Best wishes,
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

Posted by Community Admin on 07-Dec-2011 00:00

Thanks.

Are there plans to provide a proper implementation of IQueryable?

Because, honestly, that work around is ridiculous. Get and check EVERY product in a foreach loop? Could it be any less efficient? I wouldn't mind so much if I only had 20 products, but the project this is for will have thousands. 

Posted by Community Admin on 07-Dec-2011 00:00

Hello Nick,

Well it seems I was wrong with my first reply. There is a way to get the products as a proper IQueryable:

TaxonomyManager manager = TaxonomyManager.GetManager();
var catManager = CatalogManager.GetManager();
 
//provide the name of the desired Department
var deptName = "Department1";
//Get the Id of the department
var myCategoryId = manager.GetTaxa<HierarchicalTaxon>().Where(t => t.Name == deptName).SingleOrDefault().Id;
 
//get all products, who are assigned to this department
var productsInDepartment1 = catManager.GetProducts().Where(p => p.GetValue<TrackedList<Guid>>("Department").Contains(myCategoryId)).ToList();

Sorry for the initial misleading.

Regards,
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

Posted by Community Admin on 07-Dec-2011 00:00

Awesome :) Thank you.

This thread is closed