Category Header Menu is Available

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
Trevor,

Thanks a lot... this indeed resolved the problem.

I think the issue was due to the path...one program was getting it and othewr was not...
Pushing it to Header resolved the problem, as script became available to both the programs.

This was a bottleneck for me to release the site.....looking for thanks giving deadline :-))
13 years ago
My pleasure.  Glad things worked out for you (and your client).

t
13 years ago
Took your advice and separated it into essentially 3 parent categories.... with all the child categories coming off them as they should.

But ran into a problem....

So on my main header on the home page if i click on Parent1 or any of its it child elements and go to view them. It will display everything in the header on that page but when I go to hover the over the Parent Name again it will not display anything.....

I have played with various things to attempt to get it to get it to work but without sucess at the moment - had a look at the page outputs and it appears like its generating the urls just not offering the menu!

**Edit** Actually its on any page that is in a directory ie

mainsite.com/Category/Page1.aspx
mainsite.com/Manufacturers/Page34.aspx

but its fine on any other page such as About Us etc etc.... random


**RESOLVED**

Worked it out. My url pointing the Scripts file was fine at top level but when in a directory it was incorrect ie stil Scripts/Jquery
13 years ago
Those pesky relative URL's catch everyone.

I plan on releasing a better, updated version once the MVC 2.0 is out.  With things changing so much I don't have the time to produce and test 4 different versions of that menu.  Perhaps one will be included in the new release.

Anyways.  Glad it worked for you.

t
13 years ago
The category header menu in nop1.9 is not working...? I have some errors in HeaderCategoryMenu.ascx.cs

3 x The name 'CategoryManager' does not exist in the current context  line:  33

and

The type or namespace name 'CategoryCollection' could not be found (are you missing a using directive or an assembly reference?)

CategoryCollecion is not exist in 1.9?

can you please help? what I must change in source code? thanks for all answers!
13 years ago
Hi we3b,

The category menu does not currently support nop 1.9.  Nop 1.9 did away with the manager classes and added interfaces.  I haven't had time to revise it.  Sorry.

t
13 years ago
Hi People,

I just checked the code and structure of CategoryNavigation and I resolved the problem in nop 1.9.
Here is the code of HeaderCategoryMenu.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="HeaderCategoryMenu.ascx.cs"
    Inherits="NopSolutions.NopCommerce.Web.Modules.HeaderCategoryMenu" %>
<%@ Register TagPrefix="nopCommerce" TagName="SearchBox" Src="~/Modules/SearchBox.ascx" %>
<div class="categoryheadermenu">
    <div id="categorymenu" class="categorymenu">
        <ul class="parentLevelContainer">
            <li class="parentLevel"><a href="<%=CommonHelper.GetStoreLocation()%>">
                    <%=GetLocaleResourceString("Content.HomePage")%></a><p>
                |</p> </li>
                        <% if (this.ProductService.RecentlyAddedProductsEnabled)
                    { %>
            <li class="parentLevel"><a href="<%=Page.ResolveUrl("~/recentlyaddedproducts.aspx")%>">
                <%=GetLocaleResourceString("Products.NewProducts")%></a><p>
                |</p> </li>
                     <%} %>
        </ul>
        <asp:PlaceHolder ID="phCategoryMenu" runat="server"></asp:PlaceHolder>
        <ul class="parentLevelContainer">
            <li class="parentLevel"><a href="../ContactUs.aspx"><%=GetLocaleResourceString("ContactUs.ContactUs")%></a><p>
                |</p>
            </li>
        </ul>
    </div>
    <div class="searchbox">
        <nopCommerce:SearchBox ID="ctrlSearchBox" runat="server" />
    </div>
</div>
<div class="clear">
</div>

<script type="text/javascript" src="../Scripts/jquery-1.4.min.js"></script>
<script type="text/javascript">
    //Removes the last "|" from the parent menu.
    $('#categorymenu').find('p:last').css("display", "none");
    //Find CategoryId in firebug or document markup and enter for horizontal level2 menu. Repeat for each desired.
    //Comment out if not needed.
    $('#parent27').find('ul:first').addClass('hSubMenu');
    function displayItem(id) {
        $(id).find('ul:first').css("left", "-13px").fadeIn('3000');
        return false;
    }
    function displayItem2(id) {
        if ($.browser.msie && $.browser.version < 8)
            $(id).find('ul:first').css("left", "17em");
        else
            $(id).find('ul:first').css("left", "14em");
        return false;
    }
    function hideItem(id) {
        $(id).find('ul').css("left", "-10000px");
        return false;
    }
</script>


and here is updated .cs file:


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NopSolutions.NopCommerce.BusinessLogic.Categories;
using NopSolutions.NopCommerce.BusinessLogic.SEO;
using NopSolutions.NopCommerce.Common.Utils;

namespace NopSolutions.NopCommerce.Web.Modules
{
    public partial class HeaderCategoryMenu : BaseNopUserControl
    {
        //Use these sort methods just below your desired collections
        private int SortByName(Category c1, Category c2)
        {
            return c1.Name.CompareTo(c2.Name);
        }
        private int SortByCategoryId(Category c1, Category c2)
        {
            return c1.CategoryId.CompareTo(c2.CategoryId);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            LiteralControl lit = new LiteralControl();
            lit.Text = CreateParentMenu();
            phCategoryMenu.Controls.Add(lit);
        }
        protected string CreateParentMenu()
        {
            List<Category> parentCollection = CategoryService.GetAllCategoriesByParentCategoryId(0);//CategoryManager.GetAllCategoriesByParentCategoryId(0);
            StringWriter stringWriter = new StringWriter();
            using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "parentLevelContainer");
                writer.RenderBeginTag(HtmlTextWriterTag.Ul);
                foreach (Category parentCategory in parentCollection)
                {
                    string parentID = "parent" + parentCategory.CategoryId;
                    List<Category> childCollection1 = CategoryService.GetAllCategoriesByParentCategoryId(parentCategory.CategoryId);//CategoryManager.GetAllCategoriesByParentCategoryId(parentCategory.CategoryId);
                    //This will sort all level 1 children by name
                    childCollection1.Sort(SortByName);
                    writer.AddAttribute(HtmlTextWriterAttribute.Id, parentID);
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, "parentLevel");
                    //jquery/javascript
                    writer.AddAttribute("onmouseover", string.Concat("javascript:displayItem('#" + parentID + "')"));
                    writer.AddAttribute("onmouseout", string.Concat("javascript:hideItem('#" + parentID + "')"));
                    writer.RenderBeginTag(HtmlTextWriterTag.Li);
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, SEOHelper.GetCategoryUrl(parentCategory));
                    writer.RenderBeginTag(HtmlTextWriterTag.A);
                    writer.Write(parentCategory.Name.ToString());
                    writer.RenderEndTag();
                    writer.RenderBeginTag(HtmlTextWriterTag.P);
                    writer.Write("|");
                    writer.RenderEndTag();
                    if (childCollection1.Count > 0)
                    {
                        writer.AddAttribute(HtmlTextWriterAttribute.Class, "childLevel1Container");
                        writer.RenderBeginTag(HtmlTextWriterTag.Ul);
                        foreach (Category childCategory1 in childCollection1)
                        {
                            string child1ID = "child1" + childCategory1.CategoryId;
                            List<Category> childCollection2 = CategoryService.GetAllCategoriesByParentCategoryId(childCategory1.CategoryId);//CategoryManager.GetAllCategories(childCategory1.CategoryId);
                            //This will sort all level 2 children by CategoryId
                            childCollection2.Sort(SortByCategoryId);
                            writer.AddAttribute(HtmlTextWriterAttribute.Id, child1ID);
                            writer.AddAttribute(HtmlTextWriterAttribute.Class, "childLevel1");
                            writer.AddAttribute("onmouseover", string.Concat("javascript:displayItem2('#" + child1ID + "')"));
                            writer.AddAttribute("onmouseout", string.Concat("javascript:hideItem('#" + child1ID + "')"));
                            writer.RenderBeginTag(HtmlTextWriterTag.Li);
                            writer.AddAttribute(HtmlTextWriterAttribute.Href, SEOHelper.GetCategoryUrl(childCategory1));
                            writer.RenderBeginTag(HtmlTextWriterTag.A);
                            writer.Write(childCategory1.Name.ToString());
                            writer.RenderEndTag();
                            if (childCollection2.Count > 0)
                            {
                                writer.AddAttribute(HtmlTextWriterAttribute.Class, "childLevel2Container");
                                writer.RenderBeginTag(HtmlTextWriterTag.Ul);
                                foreach (Category childCategory2 in childCollection2)
                                {
                                    writer.AddAttribute(HtmlTextWriterAttribute.Class, "childLevel2");
                                    writer.RenderBeginTag(HtmlTextWriterTag.Li);
                                    writer.AddAttribute(HtmlTextWriterAttribute.Href, SEOHelper.GetCategoryUrl(childCategory2));
                                    writer.RenderBeginTag(HtmlTextWriterTag.A);
                                    writer.Write(childCategory2.Name.ToString());
                                    writer.RenderEndTag();
                                    //Repeat logic to add level 4 navigation. Be sure to add classes to stylesheet
                                    writer.RenderEndTag();
                                }
                                writer.RenderEndTag();
                            }
                            writer.RenderEndTag();
                        }
                        writer.RenderEndTag();
                    }
                    writer.RenderEndTag();
                }
                writer.RenderEndTag();
            }
            return stringWriter.ToString();
        }
    }
}


Have a nice day!
13 years ago
Atta boy we3b!

I haven't looked at 1.9 in depth but it looks like the service classes took place of the manager classes.  You saved me some work.  Thanks.

t
13 years ago
Hi joebloe,

No problem, as you can see it was easy. I will develop many features for nopcommerce...Becouse I started working with them....
13 years ago
I've hosted this code in the zip file at:

http://www.nopeasy.com/boards/t/4/category-header-menu-is-available.aspx

for anyone who wants to download it.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.