Page 1 of 1

Remove Subcategories from CategoryGridPage4.ascx

Posted: Mon Jul 28, 2008 5:43 pm
by fatone
I am using the 'CategoryGridPage4.ascx' to display products because I want to see the summary field displayed for each product. The only issue is that that subcategories are showing up in the list as a hypertext link. If I click the link it shows me all the products for that subcategory. I would like to avoid these subcategories from showing up in the list.

I was thinking that if the Category has a parent id, then I know it is a subcategory so I shouldn't display it. So I modified the ascx page within the Page_Init call to check the ParentId value. Since the ParentId value of 0 means it is a top category, I figured this would work! But it didn't

The code I added is to the 2nd if statement below "(node.Category.ParentId == 0)".

That didn't work, so what would be my best approach?

Code: Select all

            foreach (CatalogNode node in _Category.CatalogNodes)
            {
                if (node.Visibility == CatalogVisibility.Public)
                {
                    bool addNode = true;
                    if ((node.CatalogNodeType == CatalogNodeType.Category) && (node.Category.ParentId == 0))
                    {
                        addNode = (CatalogDataSource.CountForCategory(node.CatalogNodeId, true) > 0);
                    }
                    if (addNode) _ContentNodes.Add(node);
                }
            }

Re: Remove Subcategories from CategoryGridPage4.ascx

Posted: Mon Jul 28, 2008 6:57 pm
by jmestep
Do you have both subcategories and products displaying under a particular category in the grid in the center?
I don't know if this would help, but I use a different display page for categories that have subcategories from the one I use for categories that have products only.
I think the reason you might be having trouble with your code is that in the ac_CategoryParents table, the categories have two or more entries. For example on one of my categories,
CategoryId ParentID
5 0
5 5

If you want to display products only, you could try moving this code up
if (catalogNode.CatalogNodeType == CatalogNodeType.Product)

in the
protected void CatalogNodeList_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)

Re: Remove Subcategories from CategoryGridPage4.ascx

Posted: Mon Jul 28, 2008 9:10 pm
by fatone
Well,

That did help a bit, but all that does is not display the link! The actual space is still there (an empty box). I figured if I could detect the subcategory when the contentNode is being built, then I could avoid the box.

Any other info would be appreciated, I am running the code in debug mode to see if I can find something.

Re: Remove Subcategories from CategoryGridPage4.ascx

Posted: Mon Jul 28, 2008 10:01 pm
by fatone
Sometimes you just got to walk a way from the computer, watch some CSI and then come back with a whole new fresh mind! :D

I figured out the solution,

I modified the line that initializes the "_ContentNodes" variable. I changed it from

Code: Select all

 if (addNode)  _ContentNodes.Add(node);
to

Code: Select all

 if (addNode && node.CatalogNodeType == CatalogNodeType.Product)  _ContentNodes.Add(node);
Pretty simple after I looked at the objects more clearly in debug mode.

P.S. Thanks Judy for your info!