cancel
Showing results for 
Search instead for 
Did you mean: 

How to get main category name from product model

former_member634320
Participant
0 Kudos
 

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member702005
Participant
0 Kudos

Hi Amit, It really depends on what do you mean by "main category".

If this is a top-level category from a supercategory tree, than you can access it by traversing the tree up to the root (until supercategories==null). But if you mean "main category" = the default category from multiple categories the product is assigned to, I'm affraid there is no such concept OOTB and you need to extend your product model to explicitly point one of the categories to be the "main".

In one of our projects we extended the products attributes in items.xml to include an additional field "mainCategory" and assigned the first category from supercategories collection to that field if it was empty or the value specified by the user if he/she did provide one.