PageHelper.GetCategoryId()
Posted: Fri Oct 21, 2011 8:16 pm
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?
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?