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.

  • Kim Bantz Rasmussen 81 posts 310 karma points
    Nov 14, 2013 @ 16:51
    Kim Bantz Rasmussen
    0

    Heading on subcategories - Category helper

    Hi,

    In the Category helper, I have this code:

    @using UCommerce.Api
    @using UCommerce.Extensions
    @using UCommerce.EntitiesV2
    @using UCommerce.Runtime
    @using umbraco.MacroEngines
    @helper DisplayCategoryProducts(UCommerce.EntitiesV2.Category category)
        {
            var products = CatalogLibrary.GetProducts(category);
            @uCommerce.Helpers.Product.DisplayListProducts(products, category)
            foreach (var childCategory in category.Categories)
            {
            <div class="row-fluid">
                <div class="span12">
                    <h1>@childCategory.Id @childCategory.DisplayName()</h1>
                </div>

     

    I would love to use @childCategory.Level so I could make different headline sizes in level 1 and level 2.

    Best regards
    Kim 

  • Morten Skjoldager 440 posts 1499 karma points
    Nov 15, 2013 @ 10:30
    Morten Skjoldager
    100

    You can make an extension method to Category that gives you the amount of categories top the top.

    on top of my head it would look a little somthing like this:

           public static int Level(this Category category)
            {
                int level = 0;
                var currentCategory = category;
                while (currentCategory.ParentCategory != null)
                {
                    currentCategory = currentCategory.ParentCategory;
                    level++;
                }
    
                return level;
            }

    Hope that helps 

  • Kim Bantz Rasmussen 81 posts 310 karma points
    Nov 18, 2013 @ 11:45
    Kim Bantz Rasmussen
    0

    Okay, I will try your code, thanks!

  • Kim Bantz Rasmussen 81 posts 310 karma points
    Nov 18, 2013 @ 16:42
    Kim Bantz Rasmussen
    0

    This is a noob question, but how do I use the method inside the helper?

    @using UCommerce.Api
    @using UCommerce.Extensions
    @using UCommerce.EntitiesV2
    @using UCommerce.Runtime
    @using umbraco.MacroEngines
    @helper DisplayCategoryProducts(UCommerce.EntitiesV2.Category category)
        {
            var products = CatalogLibrary.GetProducts(category);
            @uCommerce.Helpers.Product.DisplayListProducts(products, category)
            foreach (var childCategory in category.Categories)
            {
            <div class="row-fluid">
                <div class="span12">
                    <h1>Level() @childCategory.DisplayName()</h1>
                </div>
            </div>
            <div class="row-fluid">   
                @DisplayCategoryProducts(childCategory)
            </div>    
            }
    }
    
    
        public static int Level(this Category category)
            {
                int level = 0;
                var currentCategory = category;
                while (currentCategory.ParentCategory != null)
                {
                    currentCategory = currentCategory.ParentCategory;
                    level++;
                }
    
                return level;
            }

     

    Best regards
    Kim 

Please Sign in or register to post replies

Write your reply to:

Draft