How to put some categories in the header menu?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
My customer want to put SOME OF level-1 categories (not including sub categories)  in the header menu, not all of them.
If I want to put all, I can use repeater.
But in this case, I think I should provide an interface in the Administration to configure it, and add a table in the DB.

Any idea about it to implement this function as simply as possible?
Thank you.
12 years ago
It would be beyond the scope of this forum to show you how to do the table mapping and data access layer stuff, but I have an idea for a quick fix.

You can use a nopcommerce topic, and place the top content inside of '~/Modules/HeaderMenu.ascx'.

Then your client can edit the additional menu items with the WYSIWYG editor.
12 years ago
theonlylawislove wrote:
It would be beyond the scope of this forum to show you how to do the table mapping and data access layer stuff, but I have an idea for a quick fix.

You can use a nopcommerce topic, and place the top content inside of '~/Modules/HeaderMenu.ascx'.

Then your client can edit the additional menu items with the WYSIWYG editor.


I know how to update the EF, but it's very inconvenient.
'Topic' may be a good way to make it, I'll look into it, thank you very much.
12 years ago
twilightgod wrote:
My customer want to put SOME OF level-1 categories (not including sub categories)  in the header menu, not all of them.
If I want to put all, I can use repeater.
But in this case, I think I should provide an interface in the Administration to configure it, and add a table in the DB.

Any idea about it to implement this function as simply as possible?
Thank you.


Do you mean something like this:

http://www.babygo.com.co/default.aspx

In the top menu when you hover in "Categorias" two dynamic columns appear, one with the top level categories and other with the manufacturers, they're botu build from the same logic and code that builds the left menus, if it works for you like that I'll post the code for that part of the menu.

The site is build from a template that I bought from: http://www.n-theme.com/
12 years ago
progresivo wrote:
My customer want to put SOME OF level-1 categories (not including sub categories)  in the header menu, not all of them.
If I want to put all, I can use repeater.
But in this case, I think I should provide an interface in the Administration to configure it, and add a table in the DB.

Any idea about it to implement this function as simply as possible?
Thank you.

Do you mean something like this:

http://www.babygo.com.co/default.aspx

In the top menu when you hover in "Categorias" two dynamic columns appear, one with the top level categories and other with the manufacturers, they're botu build from the same logic and code that builds the left menus, if it works for you like that I'll post the code for that part of the menu.

The site is build from a template that I bought from: http://www.n-theme.com/

Yes, it is. It will be very helpful, many thanks.
12 years ago
This is the ascx markup, it contains the same markup that is used on the left menu in terms of categories and manufacturers, but it uses a Javascript dynamic menu from http://www.javascriptkit.com/script/script2/jScale/:
<%@ Control Language="C#" AutoEventWireup="true" Inherits="NopSolutions.NopCommerce.Web.Modules.HeaderMegaMenu"
    CodeBehind="HeaderMegaMenu.ascx.cs" %>

<script type="text/javascript" src="<%=CommonHelper.GetStoreLocation()%>Scripts/jquery.megamenu.js"></script>
    <script type="text/javascript">
        //jkmegamenu.definemenu("anchorid", "menuid", "mouseover|click")
        jkmegamenu.definemenu("megaanchor", "megamenu1", "mouseover");
    </script>

<li><a href="" id="megaanchor"><%=GetLocaleResourceString("Category.Categories")%></a></li>
<%--Mega Menu--%>
<!--Mega Drop Down Menu HTML. Retain given CSS classes-->
<div id="megamenu1" class="megamenu">
    <div class="column">
        <h3><%=GetLocaleResourceString("Category.Categories")%></h3>
        <ul>
            <asp:PlaceHolder runat="server" ID="phCategories" EnableViewState="false" />
        </ul>
    </div>
    <div class="column">
        <h3><%=GetLocaleResourceString("Manufacturer.Manufacturers")%></h3>

        <asp:Repeater ID="rptrManufacturers" runat="server" OnItemDataBound="rptrManufacturers_ItemDataBound" EnableViewState="false">
            <HeaderTemplate>
                <ul>
            </HeaderTemplate>
            <ItemTemplate>
                <li>
                    <asp:HyperLink ID="hlManufacturer" runat="server" Text='<%#Server.HtmlEncode(Eval("LocalizedName").ToString()) %>'
                        CssClass='<%# ((int)Eval("ManufacturerId") == this.ManufacturerId) ? "active" : "inactive" %>' />
                </li>
            </ItemTemplate>
            <FooterTemplate>
                </ul>
            </FooterTemplate>
        </asp:Repeater>
        <div class="viewall">
            <a href="<%=CommonHelper.GetStoreLocation()%>manufacturers.aspx">
                <%=GetLocaleResourceString("Manufacturer.ViewAll")%></a>
        </div>
    </div>
    <br style="clear: left" />
    <!--Break after 3rd column. Move this if desired-->
    <br />
</div>
<%--@Mega Menu--%>


And the code behind uses the corresponding code that builds the category menu and manufacturers links on the NopCommerce distribution, I just copied the code and merged it (using sentences ommited, create them with Control + dot in Visual Studio):
namespace NopSolutions.NopCommerce.Web.Modules
{
    public partial class TopicControl: BaseNopFrontendUserControl
    {
        private bool ValidatePassword()
        {
            bool passwordOK = true;
            if (this.Topic != null)
            {
                if (this.Topic.IsPasswordProtected &&
                    !this.Topic.Password.Equals(this.EnteredPassword))
                {
                    passwordOK = false;
                }
            }
            return passwordOK;
        }

        protected void btnPassword_OnClick(object sender, EventArgs e)
        {
            this.EnteredPassword = txtPassword.Text;
            bool passwordOK = ValidatePassword();
            if (!passwordOK)
            {
                lError.Text = GetLocaleResourceString("TopicPage.WrongPassword");
            }
            BindData();
        }

        private void BindData()
        {
            if (this.LocalizedTopic != null)
            {
                bool passwordOK = ValidatePassword();
                if (passwordOK)
                {
                    phPassword.Visible = false;
                    lTitle.Visible = true;
                    lBody.Visible = true;

                    if (!string.IsNullOrEmpty(this.LocalizedTopic.Title))
                    {
                        lTitle.Text = Server.HtmlEncode(this.LocalizedTopic.Title);
                    }
                    else
                    {
                        lTitle.Visible = false;
                    }
                    if (!string.IsNullOrEmpty(this.LocalizedTopic.Body))
                    {
                        lBody.Text = this.LocalizedTopic.Body;
                    }
                    else
                    {
                        lBody.Visible = false;
                    }
                }
                else
                {
                    phPassword.Visible = true;
                    lTitle.Visible = false;
                    lBody.Visible = false;
                }
            }
            else
            {
                this.Visible = false;
            }
        }
        
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.BindData();

            if (this.LocalizedTopic != null)
            {
                if (this.OverrideSEO)
                {
                    //title
                    string title = this.LocalizedTopic.MetaTitle;
                    if (String.IsNullOrEmpty(title))
                        title = this.LocalizedTopic.Title;
                    if (!string.IsNullOrEmpty(title))
                        SEOHelper.RenderTitle(this.Page, title, true);

                    //meta
                    if (!String.IsNullOrEmpty(this.LocalizedTopic.MetaDescription))
                        SEOHelper.RenderMetaTag(this.Page, "description", this.LocalizedTopic.MetaDescription, true);
                    if (!String.IsNullOrEmpty(this.LocalizedTopic.MetaKeywords))
                        SEOHelper.RenderMetaTag(this.Page, "keywords", this.LocalizedTopic.MetaKeywords, true);
                }
            }
        }

        protected override void OnPreRender(EventArgs e)
        {
            //default button
            this.txtPassword.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + btnPassword.ClientID + "').click();return false;}} else {return true}; ");

            base.OnPreRender(e);
        }

        private LocalizedTopic localizedTopic = null;
        public LocalizedTopic LocalizedTopic
        {
            get
            {
                if (localizedTopic == null)
                {
                    localizedTopic = this.TopicService.GetLocalizedTopic(this.TopicName, NopContext.Current.WorkingLanguage.LanguageId);
                }
                return localizedTopic;
            }
        }

        public Topic Topic
        {
            get
            {
                if (this.LocalizedTopic != null)
                    return this.LocalizedTopic.Topic;
                else
                    return null;
            }
        }

        public string TopicName
        {
            get
            {
                object obj2 = this.ViewState["TopicName"];
                if (obj2 != null)
                    return (string)obj2;
                else
                    return string.Empty;
            }
            set
            {
                this.ViewState["TopicName"] = value;
            }
        }

        [DefaultValue(true)]
        public bool OverrideSEO
        {
            get
            {
                object obj2 = this.ViewState["OverrideSEO"];
                if (obj2 != null)
                    return (bool)obj2;
                else
                    return true;

            }
            set
            {
                this.ViewState["OverrideSEO"] = value;
            }
        }

        public string EnteredPassword
        {
            get
            {
                object obj2 = this.ViewState["EnteredPassword"];
                if (obj2 != null)
                    return (string)obj2;
                else
                    return string.Empty;
            }
            set
            {
                this.ViewState["EnteredPassword"] = value;
            }
        }
    }
}
12 years ago
How to Expand category menu by default
Any one have an idea on how to do this
am using 2.1 nopcommerce  
plz help me

Thank u....
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.