how to show/hide categories

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
mshaw
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 40
Joined: Thu Sep 04, 2008 1:53 pm

how to show/hide categories

Post by mshaw » Tue Sep 30, 2008 2:30 pm

For specific url referrers to the ac7 site we want to show one category and its products and for anyone else a different category and is products. We changed the SimpleCategoryList.cs code thus:
if (HttpContext.Current.Request.UrlReferrer.ToString().Contains("http://localhost/testexchange") || HttpContext.Current.Request.UrlReferrer.ToString().Contains("http://www.exchangeonlinemall.com/defau ... =aafes.com"))
{
referrerCategoryId = 7;
}
else
referrerCategoryId = 8;

but this does not load any categories at all.
If we let it default to a value of zero then both categories show and we do not want that.
What am I doing wrong? Any help is appreciated. Once we have this working we can do the same for featured products, top sellers, etc. I hope!

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: how to show/hide categories

Post by mazhar » Mon Oct 06, 2008 9:13 am

Loading the categories for an id =0 means load the root categories. In your case i think that you have two root categories. What you are currently doing will load the children of the the specified category. For example when you load for id=7 then its children will be loaded. If you want to show one of the root category and hide the other then you can try by first loading for root categories by providing an id=0 and then removing the category that you don't want to show from the loaded data.
For example if we look into the SimpleCategoryList control then we found the following statements loading the data

Code: Select all

CategoryList.DataSource = CategoryDataSource.LoadForParent(_CategoryId, true);
CategoryList.DataBind();
You can customize these statements to meet your needs as below

Code: Select all

CategoryCollection categories = CategoryDataSource.LoadForParent(_CategoryId, true);
        Category hiddenCat = null;
        foreach (Category c in categories)
            if (c.CategoryId == 1)
            {
                hiddenCat = c;
                break;
            }
        if (hiddenCat != null)
            categories.Remove(hiddenCat);
        CategoryList.DataSource = categories;
        CategoryList.DataBind();

mshaw
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 40
Joined: Thu Sep 04, 2008 1:53 pm

Re: how to show/hide categories

Post by mshaw » Tue Oct 28, 2008 3:24 pm

Thanks, that is great! Just what we needed.

Post Reply