Page 1 of 1

PageHelper.GetCategoryId()

Posted: Fri Oct 21, 2011 8:16 pm
by sloDavid
I'm looking at a product that I linked to from the shopping cart. I need to get a default category (and therefore category path) for the product, but none will be specified in the URL, of course. This product exists in multiple categories and subcategories.

Normally, you can use PageHelper.GetCategoryId() to do this, but I don't like the result that it provides.

I hoped that GetCategoryId() would start with the category that's listed first in my Admin panel sort order, and check its subcategories before checking other categories. But it doesn't. It's choosing a category that appears *later* in the sort order. I think it does this because I created that category first.

Anybody have good ideas? I don't want to have to actually *delete* the categories just to get the correct/new one to be what shows up. My only current workaround is to ignore GetCategoryId() altogether, loop through all of the product's categories until I find one such that the entire list of parents have public visibility, and set my old categories to hidden. I'm not opposed to it, I just don't think that I should have to change the old categories' visibility, just to get the correct default returned by GetCategoryId. Shouldn't the admin panel sorting establish that default precedence?

Re: PageHelper.GetCategoryId()

Posted: Fri Nov 04, 2011 5:06 pm
by david-ebt
It doesn't look like there is the concept of a default category for a product. How many products are in this situation? Perhaps you could add a product template field to each of the products and put in the default categoryID? Then you could use that value to get the breadcrumb, etc.

Re: PageHelper.GetCategoryId()

Posted: Wed Dec 07, 2011 6:08 pm
by sloDavid
That's an idea... but since this does apply to about 2/3 of my products, I think I'll just be better off to just add a database field and do the programming work necessary to actually build a default category feature. Rats.