Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • John Walker 41 posts 136 karma points
    Jan 03, 2013 @ 17:07
    John Walker
    0

    uCommerce 3 get all products from category and sub categories.

    Hi,

    I'm currently working on a site with a large amount of products (approx 1500) and I'm attempting to display all product within a category but also any child categories. Currently I'm doing this recursively. 

    So adding products from my current category then seeing if that category has any children, and looping round this method. This approach is currently very slow at pulling the data out I was wondering is there a better way of doing this or is there any built in query for this.

     

    Thanks,

    John

  • John Walker 41 posts 136 karma points
    Jan 04, 2013 @ 10:10
    John Walker
    101

    Managed to speed this up greatly by initially getting a list of the category id's then doing a Linq query for products that have a category product relation to any of the matching categories.

    John

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jan 09, 2013 @ 10:32
    Søren Spelling Lund
    0

    Hi John,

    Thanks for being aweome and posting the solution on the forum.

  • Marc Love (uSkinned.net) 432 posts 1691 karma points
    Jan 17, 2013 @ 12:41
    Marc Love (uSkinned.net)
    0

    Hi John,

    I need to also list all products sitting under a parent category. I am a bit new to linq, any chance you can post your linq command?

    Cheers,

    Marc

     

     

     

  • John Walker 41 posts 136 karma points
    Jan 17, 2013 @ 14:24
    John Walker
    0

    Hi Marc,

    If you have the current category you can just go:

    var cat = SiteContext.Current.CatalogContext.CurrentCategory;
    var parentCatProducts = category.ParentCategory.Products;

    John

     

  • Marc Love (uSkinned.net) 432 posts 1691 karma points
    Jan 18, 2013 @ 12:02
    Marc Love (uSkinned.net)
    0

    Hi John,

    Sorry, probably not explained this very well. My parent category doesnt have any products added to it. I have a parent/child hierarchy of products with all products sitting in the child categories.

    Parent
    --Child
    --Child
    Parent
    --Child
    --Child
    --Child

    I want to be able to click on the parent category from the menu and display all products that sit in the child categories below it.

    Cheers,

    Marc

  • Marc Love (uSkinned.net) 432 posts 1691 karma points
    Jan 18, 2013 @ 12:25
    Marc Love (uSkinned.net)
    0

    I suppose the easy solution would be to mae sure the parent categories are checked in uCommerce. Is this best practice or is anyone using any other methods to list products within a category and all child categories?

    Cheers,

    Marc

  • John Walker 41 posts 136 karma points
    Jan 18, 2013 @ 17:37
    John Walker
    0

    No we don't have all the parent categories checked. What I do is:

    1. From my current category do a recurssive loop to get all child/sub child categories Id.

    2. Do a search against all products to find any that have a CategoryProductRelations with any of the categories in our list.

     

    John

Please Sign in or register to post replies

Write your reply to:

Draft