Remove Subcategories from CategoryGridPage4.ascx

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
fatone
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 38
Joined: Thu Jan 17, 2008 7:35 am

Remove Subcategories from CategoryGridPage4.ascx

Post by fatone » Mon Jul 28, 2008 5:43 pm

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);
                }
            }

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Remove Subcategories from CategoryGridPage4.ascx

Post by jmestep » Mon Jul 28, 2008 6:57 pm

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)
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

fatone
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 38
Joined: Thu Jan 17, 2008 7:35 am

Re: Remove Subcategories from CategoryGridPage4.ascx

Post by fatone » Mon Jul 28, 2008 9:10 pm

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.

fatone
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 38
Joined: Thu Jan 17, 2008 7:35 am

Re: Remove Subcategories from CategoryGridPage4.ascx

Post by fatone » Mon Jul 28, 2008 10:01 pm

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!

Post Reply