November Happy Hour will be moved to Thursday December 5th.

Finding Variant information

Vote:
 

How to find Variant path which displayed in commerece catalog /product/variant.

#205728
Jul 22, 2019 13:33
Vote:
 

Log into the Commerce catalog. Then, navigate to the variant and click the Belongs to tab to see its path.


#205733
Jul 22, 2019 18:25
Janakiram - Jul 23, 2019 5:51
Hi Bob,
Thanks for your quick reply, but
I need to get that in code.
The path has to be shown in elsewhere in my project. I am able get the variant but unable to find path string.
Please help me if there is way to find it.
Thanks.
Paul Middleton - Jul 24, 2019 17:27
Hi - You need to read up on how the RelationRepository works - details here : https://world.episerver.com/documentation/developer-guides/commerce/catalogs/catalog-content/Categorizations/
Vote:
 

It is unclear what you are trying to do, but i assume you want to get the variant url

From the code you can use ReferenceConverter to get the content link

From the content link you can use UrlResolver.GetUrl to get the url of the content. In this case, the variant

#205738
Jul 23, 2019 8:34
Janakiram - Jul 23, 2019 10:51
Hi Quan,
As in Bob Bolt suggestion in image we can see 'Primary Category'' , under that there is an item called "Mens Jacket" by the side of that we can see a hierarchical text. We need to get that string for a variant to show exactly how that is shown in the above image. We don't need the url. We are able to get the url as you suggested. If there is any way , please let me know. I really appreciate your reply.
Thanks.
Vote:
 

We have created some EntryContentExtensions that will help you to retrieve the PrimaryCategory

public static NodeContent GetCategory(this EntryContentBase entryContent, IContentLoader contentLoader = null)
{
    return GetCategory<NodeContent>(entryContent, contentLoader);
}

Here is the method GetCategory<T>() definitions

public static T GetCategory<T>(this EntryContentBase entryContent, IContentLoader contentLoader = null)
    where T : NodeContent
{
    if (entryContent == null)
        return null;

    if (contentLoader == null)
    {
        contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
    }

    var nodeContent = contentLoader
        .GetAncestors(entryContent.ContentLink)
        .FirstOrDefault(x => x is T);

    return nodeContent as T;
}

Let me know if it helps you.

Thanks

#205936
Jul 29, 2019 16:47
Vote:
 

What you mentioned in the comment sounds like bread crumb. If that is the case, you can do like this https://leanpub.com/epicommercerecipes/read_sample (Recipe 1.9) 

#205938
Jul 29, 2019 17:27
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.