how to show all catagories(include the 3ird catagory) at all pages(include home pages)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 лет назад
about  how to alter this  file code Modules/CategoryNavigation.ascx



using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using NopSolutions.NopCommerce.BusinessLogic.Categories;
using NopSolutions.NopCommerce.BusinessLogic.Products;
using NopSolutions.NopCommerce.BusinessLogic.SEO;
using NopSolutions.NopCommerce.Common.Utils;

namespace NopSolutions.NopCommerce.Web.Modules
{
    public partial class CategoryNavigation : BaseNopUserControl
    {
        #region Classes
        public class NopCommerceLi : WebControl, INamingContainer
        {
            public NopCommerceLi()
            {
                this.HyperLink = new HyperLink();
            }

            protected override void Render(System.Web.UI.HtmlTextWriter writer)
            {
                writer.WriteBeginTag("li");
                writer.WriteAttribute("class", this.CssClass);
                if (!String.IsNullOrEmpty(this.LiLeftMargin))
                {
                    writer.WriteAttribute("style", string.Format("margin-left: {0}px", this.LiLeftMargin));
                }
                writer.Write(HtmlTextWriter.TagRightChar);
                this.HyperLink.RenderControl(writer);
                writer.WriteEndTag("li");
            }

            public string LinkText
            {
                get
                {
                    return this.HyperLink.Text;
                }
                set
                {
                    if (value != null)
                    {
                        this.HyperLink.Text = value;
                    }
                }
            }

            public HyperLink HyperLink { get; set; }

            public string LiLeftMargin
            {
                get
                {
                    object liLeftMargin = this.ViewState["LiLeftMargin"];
                    if (liLeftMargin != null)
                        return Convert.ToString(liLeftMargin);
                    return string.Empty;

                }
                set
                {
                    this.ViewState["LiLeftMargin"] = value;
                }
            }
        }
        #endregion

        #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
        protected void CreateMenu()
        {
            List<Category> breadCrumb = null;
            var currentCategory = CategoryManager.GetCategoryById(CommonHelper.QueryStringInt("CategoryId"));
            if (currentCategory == null)
            {
                var product = ProductManager.GetProductById(CommonHelper.QueryStringInt("ProductId"));
                if (product != null)
                {
                    var productCategories = product.ProductCategories;
                    if (productCategories.Count > 0)
                        currentCategory = productCategories[0].Category;
                }
            }

            if (currentCategory != null)
                breadCrumb = CategoryManager.GetBreadCrumb(currentCategory.CategoryId);
            else
                breadCrumb = new List<Category>();

            CreateChildMenu(breadCrumb, 0, currentCategory, 0);
        }

        protected void CreateChildMenu(List<Category> breadCrumb, int rootCategoryId, Category currentCategory, int level)
        {
            int padding = level++ * 15;
            foreach (var category in CategoryManager.GetAllCategories(rootCategoryId))
            {
                var link = new NopCommerceLi();
                phCategories.Controls.Add(link);

                string categoryURL = SEOHelper.GetCategoryUrl(category);
                if (currentCategory != null && currentCategory.CategoryId == category.CategoryId)
                    link.CssClass = "active";
                else
                    link.CssClass = "inactive";
                link.HyperLink.NavigateUrl = categoryURL;
                link.HyperLink.Text = Server.HtmlEncode(category.LocalizedName);
                if (padding > 0)
                    link.LiLeftMargin = padding.ToString();

                for (int i = 0; i <= breadCrumb.Count - 1; i++)
                    if (breadCrumb[i].CategoryId == category.CategoryId)
                        CreateChildMenu(breadCrumb, category.CategoryId, currentCategory, level);
            }
        }
        #endregion
    }
}
13 лет назад
No one help me???
13 лет назад
Not sure that I got you. But If want to show all categories on left categories box, then
1. Open \Modules\CategoryNavigation.ascx.cs file
2. Comment lines 154-155
for (int i = 0; i <= breadCrumb.Count - 1; i++)
                    if (breadCrumb[i].CategoryId == category.CategoryId)


P.S. Not tested
13 лет назад
It's not available,

what's this code:


var currentCategory = CategoryManager.GetCategoryById(CommonHelper.QueryStringInt("CategoryId"));



            if (currentCategory != null)
                breadCrumb = CategoryManager.GetBreadCrumb(currentCategory.CategoryId);
            else
                breadCrumb = new List<Category>();




How to show all catagories include the 3rd subcatagories ?

Help me.....
13 лет назад
I've already posted the solution above. It'll display all available categories
13 лет назад
Are your meaning  delete this code  

"     if (breadCrumb[i].CategoryId == category.CategoryId)   "   ?
13 лет назад
I  have re compile,

But it is also not available.
13 лет назад
musocial wrote:
Are your meaning  delete this code  

"     if (breadCrumb[i].CategoryId == category.CategoryId)   "   ?

Correct, comment or delete the following lines
for (int i = 0; i <= breadCrumb.Count - 1; i++)
                    if (breadCrumb[i].CategoryId == category.CategoryId)
13 лет назад
Sorry!    I haven't solve this problem yet.


When I delete that code, The every page is all the same, Just like haven't delete that code. What's the problem?

I also have delete  all this path  files  
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

Is it needed re  compile again?
13 лет назад
musocial wrote:
Is it needed re  comple again?

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