Parent category on a product in an additional categories

 

Hi,

I have a product which exists in two categories, and I'm having troubles getting the correct parent based on the context/url.

I can access the product from the two url below - which is great.

  • /en/catalog/private/lamps/test (primary)
  • /en/catalog/professional/lighting/test (additional category)

The problem arises when I'm trying to make a breadcrumb.

For it to work I need to be able to get the parent of the product, based on the url I'm on right now.

But I always end up with the primary category, which results in a wrong breadcrumb.

Understandably a ContentReference won't have enough information to determin which category I'm in, but is there another way to get the parent of the product?

By using currentPage.GetNodeRelations(); I can get a reference to both the parents, but I don't know which one of them is the correct one for the context I'm in.

Episerver version: 11.8.0.0

Commerce version: 12.2.0.0

Thanks!

#194072 Jun 12, 2018 17:30
  • Magnus Rahl
    Member since: 2008
     

    You could simply look at the URL of the incoming request. Or build that into the routing. I did a very similar thing a couple of years ago, see this blog post: https://world.episerver.com/blogs/Magnus-Rahl/Dates/2015/3/routing-context-aware-links-in-commerce-catalog/

    #194073 Jun 12, 2018 22:39
  • Quan Mai
    Member since: 2011
     

    I also wrote about it here https://leanpub.com/epicommercerecipes/read_sample

    I haven't read the blog post from Magnus (sorry!) but it might have same idea. 

    #194248 Jun 17, 2018 23:29