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!