Using a particuliar category page as home page

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 年 前
Ok..I'm looking for a slick way (ie. elegant way) to use a particuliar category page as HOME.

I thought I'd post here before I start digging into the code and replacing stuff to see if anyone has a nice, clean way to do this :)
13 年 前
Response.Redirect("your category url")

Of course a nicer way would be to have a property on your category "Use as home page" rather than hardcoding the url
13 年 前
Ah..ok. Thank you.


I'm trying to avoid a redirect for seo reasons.

But because you quoted "use a home page" makes me think such a setting exists. If that's the case, where would this setting be? I'm still working with visual studio 2005, so if it's in the project file I'll have to D/L the 2010 freebie version.
13 年 前
Actually, I think I'm getting there.

In default.aspx I "commented out" the stuff inside the container, and replaced it with the stuff inside the container of Category.aspx.

Now, to set a default category? Hrrmm..any ideas?
13 年 前
After some time I've replaced Default.asp,.cs....with the code from category.aspx.
To start out simple, I've just copied the NopSolutions.NopCommerce.Web.CategoryPage class into
NopSolutions.NopCommerce.Web.default class. (I'll work on a derivation later).

Anyway, after a build & publish I get the following error "Object reference not set to an instance of an object."

Here's my default.aspx.cs

You'll notice I tried using CategoryManager.GetCategoryById() to set a default category, but that still didn't work.

namespace NopSolutions.NopCommerce.Web
{
    public partial class Default : BaseNopPage
    {
        Category category = null;//**** CategoryManager.GetCategoryById(some catid);

        private void CreateChildControlsTree()
        {
            category = CategoryManager.GetCategoryById(48);
            if (category != null)
            {
                Control child = null;

                CategoryTemplate categoryTemplate = category.CategoryTemplate;
                if (categoryTemplate == null)
                    throw new NopException(string.Format("Category template path can not be empty. CategoryID={0}", category.CategoryId));

                child = base.LoadControl(categoryTemplate.TemplatePath);
                this.CategoryPlaceHolder.Controls.Add(child);
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);            
            this.CreateChildControlsTree();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (category == null || category.Deleted || !category.Published)
                Response.Redirect(CommonHelper.GetStoreLocation());

            string title = string.Empty;
            if (!string.IsNullOrEmpty(category.LocalizedMetaTitle))
                title = category.LocalizedMetaTitle;
            else
                title = category.LocalizedName;
            SEOHelper.RenderTitle(this, title, true);
            SEOHelper.RenderMetaTag(this, "description", category.LocalizedMetaDescription, true);
            SEOHelper.RenderMetaTag(this, "keywords", category.LocalizedMetaKeywords, true);

            if (!Page.IsPostBack)
            {
                NopContext.Current.LastContinueShoppingPage = CommonHelper.GetThisPageUrl(true);
            }
        }

        public int CategoryId
        {
            get
            {
                return CommonHelper.QueryStringInt("CategoryId");
            }
        }

        public override PageSslProtectionEnum SslProtected
        {
            get
            {
                return PageSslProtectionEnum.No;
            }
        }
    }
}



Any ideas on how to instantiate a CategoryPage with a known categoryID?
13 年 前
You need to pass the category id as a querystring, that's why it wouldn't have worked for you initially - look at the CategoryId property.
13 年 前
Hrm...i tried using default.aspx?categoryid=mydefaultcatID and got same error (i even checked the urlrewrite config for default.aspx and updated it to be like category.aspx).

category.aspx?categoryid=mydefaultcatID DOES work, but if I call just plain old category.aspx I get the same error. So I guess the categoryID param isn't getting passed correctly.

In any event, I guess what I'm getting at is I can pass all kinds of query strings to a page. They only have meaning when i assign meaning to them. ie...passing ?answer=42&favcolor=blue_no_red to say category.aspx doesn't mean they have any meaning (or variables) associated.

Somewhere in the code there must be something like categoryID=Request.QueryString("categoryID").
That's prolly what i need to find so I can just 'hard-code' it for the default page :)
13 年 前
There is, as I said, on the CategoryId property:

public int CategoryId
        {
            get
            {
                return CommonHelper.QueryStringInt("CategoryId");
            }
        }


This is essentially a helper method that does int.parse(Request.QueryString["CategoryId"])
13 年 前
Ah..there we go-sweet! Thank you!

Wife had me doin yardwork or woulda responded sooner
13 年 前
Actually, still not working. I also realize this thread should in dev, so I'll post there.

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