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

Forums / Ecommerce / Get products by department

Get products by department

5 posts, 0 answered
  1. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    30 Nov 2011
    Link to this post
    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
  2. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    Registered:
    03 Nov 2014
    06 Dec 2011
    Link to this post
    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
  3. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    07 Dec 2011
    Link to this post
    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. 
  4. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    Registered:
    03 Nov 2014
    07 Dec 2011
    Link to this post
    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
  5. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    07 Dec 2011
    Link to this post
    Awesome :) Thank you.
5 posts, 0 answered