Get products by department
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
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)) 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.
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();Awesome :) Thank you.