I am working on my first ecommerce project using the uCommerce platform. I need to keep the first category get the class selected. So when I on one of the categories below, the level 1 category need to keep the class selected.
With code I got now when I on Category 1 it´s gets the class selected. So what I am after if that when I on one of the other categories under Category 1 e.g the page I have mark as bold, then Category 1 should still have the class selected.
You have to extend your if statement to also check if the category is a parent of your current category. I would write a helper that can check every category from current node to topnode.
It could be done in this way:
public bool IsParentOf(Category parentCandidate, Category child)
{
var cat = child.Parent;
while (cat != null)
{
if (cat == parentCandidate)
{
return true;
}
else
{
cat = cat.ParentCategory;
}
}
return false;
}
I have not tested the code but something similar should do it.
Keep selected on first category level
Hi,
I am working on my first ecommerce project using the uCommerce platform. I need to keep the first category get the class selected. So when I on one of the categories below, the level 1 category need to keep the class selected.
My category structure is like this:
Catalog
-Category 1
--Sub category
----Sub category
----Sub category
--Sub category
-Category 2
With code I got now when I on Category 1 it´s gets the class selected. So what I am after if that when I on one of the other categories under Category 1 e.g the page I have mark as bold, then Category 1 should still have the class selected.
The code I have so far looks like this:
The Umbraco version I am using is Umbraco 4.11.10 and uCommerce 6.0.3.14141
/Dennis
Hi Dennis,
You have to extend your if statement to also check if the category is a parent of your current category. I would write a helper that can check every category from current node to topnode.
It could be done in this way:
I have not tested the code but something similar should do it.
If you have any questions just ask :)
EDIT:
Then you extend this line:
with:
Best regards
Martin
Hi Martin,
I have tried your code, but I get that the IsParentOf can not be resolve, so maybe I have placed helper method at the wrong place?
My code looks like this now:
Maybe you can spot what I´am doing wrong.
/Dennis
Hi Dennis,
I actually think that it should be a function instead of a helper. Take a look at this: http://www.mikesdotnetting.com/Article/173/The-Difference-Between-@Helpers-and-@Functions-In-WebMatrix
Best regards
Martin
is working on a reply...