Menu Navigation

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
15 anos atrás
Hi everyone,

I'm trying to accomplish a different menu system than what is provided in the core system.  Instead of having the Home Page, New Products, Search, etc.,  I want it to have the parent categories across the top and when you hover over them I want the menu to drop down with the sub menu's?  First question has anyone attempted this already?  Secondly, if I remove the home, products, search from the header menu module is this going to effect anything else in the site adversely?  Third, can anyone offer any guidance in try to accomplish this or anything I should possibly watch out for that I may have not already thought of?

Thanks in Advance,

WaltD
15 anos atrás
Hi Walt,

Yes I have the code for this. I will post it later. It may also be available in the next release.

No - removing the home, products etc. from the header control will not cause any problems. You could realocate these to the InfoBlock control.

Cheers,

Ben
15 anos atrás
Here you go. It will be refined for release but this essentially builds an asp.net menu. You will need to control formatting etc.


namespace NopSolutions.NopCommerce.Web.Modules
{
    public partial class CategoryNavigationMenu : BaseNopUserControl
    {
        #region Handlers
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        #endregion
        #region Overrides
        protected override void CreateChildControls()
        {
            if (!this.ChildControlsCreated)
            {
                CreateMenu();
                base.CreateChildControls();
                ChildControlsCreated = true;
            }
        }
        #endregion
        #region Utilities
        // Adds categories to asp.net menu control
        protected void CreateMenu()
        {
            CategoryCollection categories = CategoryManager.GetAllCategories(0);
            CreateMenuItems(categories, mnuCat.Items);
        }
        protected void CreateMenuItems(CategoryCollection categories, MenuItemCollection items)
        {
            foreach (Category category in categories)
            {
                MenuItem mi = new MenuItem(category.Name);
                mi.NavigateUrl = SEOHelper.GetCategoryURL(category.CategoryID);
                items.Add(mi);
                CreateSubLevel(category.CategoryID, mi);
            }
        }
        protected void CreateSubLevel(int parentCatID, MenuItem parentItem)
        {
            CategoryCollection categories = new CategoryCollection();
            categories = CategoryManager.GetAllCategories(parentCatID);
            if (categories.Count > 0)
                CreateMenuItems(categories, parentItem.ChildItems);
        }
        #endregion
    }
}
15 anos atrás
Hey Ben,

Thanks for the code.  I am having a little problem though.  Where does the mnuCat.Items come from?  I keep getting this error:   [quote] The name 'mnuCat' does not exist in the current context.[/quote]  Am I missing something still?  Well, obviously I'm missing "something".  LOL

Thanks again for all your help,
WaltD
15 anos atrás
Yes, you are :)

You need to add an asp.net menu control to the page/control.

i.e. <asp:menu runat="server" id="mnuCat"/>

Cheers,
Ben
15 anos atrás
Works well for me - thanks!
15 anos atrás
Yeh, works great for me now too.  Took me a little bit to get it to work the way I wanted it to but everything is good now.  Thanks again Ben!
15 anos atrás
On the categories menu. I would like the treeview to be expand all so the user can see all the subcategories is this possible?
15 anos atrás
You would need to replace the current category links with a treeview control. You can then dynamically add the items to the treeview like the above code does for a menu control. in fact the code would be very similar to the above so you should be able to adapt it.
15 anos atrás
Hey Ben,

I tried to re-implement this in the new version 1.11 and the codebehind keeps complaining about mnuCat does not exist in current context.  Any ideas?  And YES the control is on the page this time.  LOL

Thanks,
WaltD
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.