Advanced Category Navigation

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
I'm using no source, please help me setting category navigation:
1. Set category ID navigation show in Home Page
Ex:default category
Books  
Computers  
Electronics  
Apparel & Shoes  
Digital downloads  
Jewelry  
Gift Cards

I want only show 3 category in home page:
Books  
Computers  
Electronics

2. show category level 2 with every title bar
Ex:
Computers  (title bar)
    Desktops  
    Notebooks  
    Accessories  
    Software & Games

Electronics  (title bar)
    Camera, photo  
    Cell phones

3. Only current category navigation in every category page
Not show all category

Thanks!
9 years ago
Hello,

There is a setting in each category in the administration, from which you can set if you like that category to be displayed on the home page.

If you like to show all of your categories in every category page you can achieve this by one of our plugins http://www.nop-templates.com/jcarousel-plugin-for-nopcommerce

With this plugin you can add all your categories in one carousel and display it in all category pages.
9 years ago
Hi,

I have one solution for you :)
Following are steps to do it:

- Under "Themes/DefaultClean/Views/Shared" folder.
  Create a new partial view named "_SeparatedCategoryNavigation.cshtml".

- Inside the created partial view. Paste following code:

@using Nop.Core.Infrastructure
@using Nop.Services.Catalog
@{
    var categoryService = EngineContext.Current.Resolve<ICategoryService>();
    var allCategories = categoryService.GetAllCategories();
}
@helper RenderCategoryLine(int parentCategoryId)
{
    var categoryService = EngineContext.Current.Resolve<ICategoryService>();
    var childCategories = categoryService.GetAllCategoriesByParentCategoryId(parentCategoryId);

    if (childCategories.Any())
    {
        foreach (var childCategory in childCategories)
        {
            <li>
                <a href="@Url.RouteUrl("Category", new { SeName = childCategory.ToModel().SeName })">@childCategory.Name</a>
            </li>
        }
    }
}
@if (allCategories.Any())
{
    foreach (var category in allCategories)
    {
        if (category.ParentCategoryId == 0)
        {
            <div class="block">
                <div class="title">
                    <a href="@Url.RouteUrl("Category", new { SeName = category.ToModel().SeName })">
                        <strong>@category.Name</strong>
                    </a>
                </div>
                <div class="listbox">
                    <ul class="list">
                        @RenderCategoryLine(category.Id)
                    </ul>
                </div>
            </div>
        }
    }
}

- Finally, render this partial view inside your desired page.
  For example, I will render it inside "_ColumnsThree.cshtml" view, like this:
BEFORE

@Html.Action("PollBlock", "Poll", new { systemKeyword = "LeftColumnPoll" })
@Html.Widget("left_side_column_after")

AFTER

@Html.Action("PollBlock", "Poll", new { systemKeyword = "LeftColumnPoll" })
@Html.Partial("_SeparatedCategoryNavigation")
@Html.Widget("left_side_column_after")

Hope this help :)
9 years ago
Great!
Thanks so much

I also add:  @Html.Partial("_SeparatedCategoryNavigation") to _ColumnsTwo.cshtml
You can help me show from subcategory 3, 4... when open a active category. Like default category navigation.

https://imagizer.imageshack.us/v2/196x257q90/674/yO6YHh.jpg
9 years ago
ngtrian wrote:
Great!
Thanks so much

I also add:  @Html.Partial("_SeparatedCategoryNavigation") to _ColumnsTwo.cshtml
You can help me show from subcategory 3, 4... when open a active category. Like default category navigation.

https://imagizer.imageshack.us/v2/196x257q90/674/yO6YHh.jpg


Here you are.
Replace entire "_SeparatedCategoryNavigation" partial view.

@using Nop.Core.Infrastructure
@using Nop.Services.Catalog
@{
    var categoryService = EngineContext.Current.Resolve<ICategoryService>();
    var allCategories = categoryService.GetAllCategories();
}
@helper RenderCategoryLine(int parentCategoryId)
{
    //current category ID
    var currentCategoryId = 0;
    if (Url.RequestContext.RouteData.Values["controller"].ToString().Equals("catalog", StringComparison.InvariantCultureIgnoreCase) &&
        Url.RequestContext.RouteData.Values["action"].ToString().Equals("category", StringComparison.InvariantCultureIgnoreCase))
    {
        currentCategoryId = Convert.ToInt32(Url.RequestContext.RouteData.Values["categoryId"].ToString());
    }

    var categoryService = EngineContext.Current.Resolve<ICategoryService>();
    var subCategories = categoryService.GetAllCategoriesByParentCategoryId(parentCategoryId);

    if (subCategories.Any())
    {
        foreach (var subCategory in subCategories)
        {
            <li class="@(subCategory.Id == currentCategoryId ? "active" : "inactive")">
                <a href="@Url.RouteUrl("Category", new { SeName = subCategory.ToModel().SeName })">@subCategory.Name</a>
                <ul class="sublist">
                    @RenderCategoryLine(subCategory.Id)
                </ul>
            </li@(category.Id>
        }
    }
}
@if (allCategories.Any())
{
    foreach (var category in allCategories)
    {
        if (category.ParentCategoryId == 0)
        {
            <div class="block block-category-navigation">
                <div class="title">
                    <a href="@Url.RouteUrl("Category", new { SeName = category.ToModel().SeName })">
                        <strong>@category.Name</strong>
                    </a>
                </div>
                <div class="listbox">
                    <ul class="list">
                        @RenderCategoryLine(category.Id)
                    </ul>
                </div>
            </div>
        }
    }
}
9 years ago
Hi,

Although the solutions from above may do the work, they are not complete and optimized. I can suggest build your html in the default CategoryNavigation view as the Model used there is being retrieved correctly (include acl, multi store support, etc.) and most importantly is being cached. If you place the logic for retrieving the categories in the view and call services from there (which is not recommended and breaking the three-tier-application guidelines) you will have no caching and you will have a lot of calls to the database on every page load which may slow down the performance a lot depending the number of categories.

Hope that helps!
9 years ago
Nop-Templates.com wrote:
Hi,

Although the solutions from above may do the work, they are not complete and optimized. I can suggest build your html in the default CategoryNavigation view as the Model used there is being retrieved correctly (include acl, multi store support, etc.) and most importantly is being cached. If you place the logic for retrieving the categories in the view and call services from there (which is not recommended and breaking the three-tier-application guidelines) you will have no caching and you will have a lot of calls to the database on every page load which may slow down the performance a lot depending the number of categories.

Hope that helps!


Sure, you are totally right :)

This solution only for "no source"
ngtrian wrote:
I'm using no source, please help me setting category navigation:
...
9 years ago
ima9ines wrote:
Hi,

Although the solutions from above may do the work, they are not complete and optimized. I can suggest build your html in the default CategoryNavigation view as the Model used there is being retrieved correctly (include acl, multi store support, etc.) and most importantly is being cached. If you place the logic for retrieving the categories in the view and call services from there (which is not recommended and breaking the three-tier-application guidelines) you will have no caching and you will have a lot of calls to the database on every page load which may slow down the performance a lot depending the number of categories.

Hope that helps!

Sure, you are totally right :)

This solution only for "no source"
I'm using no source, please help me setting category navigation:
...


Hi agree,

Another tricky solution may be to replace the

@Html.Action("CategoryNavigation", "Catalog", new { currentCategoryId = currentCategoryId, currentProductId = currentProductId }) 


call with

<div class="category-navigation">
    @Html.Action("TopMenu", "Catalog")
</div>




Thus all the built model will be returned from the cache and will be extremely fast and just correct the styles so that it is styled as a category navigation (add the styles with the .category-navigation prefix) so that the header menu navigation is not changed. But this approach will require more css overrides and fixes. Also the logic about the current category should be added in the TopMenu.cshtml.

As I said this approach will require some more styling stuff so it is up to ngtrian to decide. Both ways will do the trick.

Hope that makes sense!
9 years ago
Hi!
Can you make from subcategory 3,4... only show when current subcategory opening, like in default category.
Thank!

Computers (heading)
      Desktops
            All in one (subcategory 3- only show when opening)
            PC
      Notebooks
      Accessories
      Software & Games
Electronics (heading)
      Camera, photo
      Cell phones
9 years ago
And only show current category in _ColumnTwo.cshtml
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.