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.
Hace 13 años
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
    }
}
Hace 13 años
No one help me???
Hace 13 años
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
Hace 13 años
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.....
Hace 13 años
I've already posted the solution above. It'll display all available categories
Hace 13 años
Are your meaning  delete this code  

"     if (breadCrumb[i].CategoryId == category.CategoryId)   "   ?
Hace 13 años
I  have re compile,

But it is also not available.
Hace 13 años
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)
Hace 13 años
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?
Hace 13 años
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.