Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Saied 349 posts 674 karma points
    Jun 25, 2016 @ 16:07
    Saied
    0

    Getting a property at the Root node with multiple root nodes?

    Hi,

    I am using custom routing with a product page. I have a product document type and a product node that I use for the custom routing. Here is a screen shot of of my structure:

    enter image description here

    As you can see from above, I have two root nodes. bullydog.com points to stage.bullydog.com and sctflash.com points to stage.sctflash.com.

    If you go to stage.sctflash.com, you will notice that below the free shipping banner, it shows the text sct. If you go to stage.bullydog.com, it should say bd below the banner. I created a test property on my Home document type and called it test and just filled it with those values (sct for the sctflash.com root node and bd for the bullydog.com root node).

    Most of the pages bring back the correct properties except for the product page (which is uses the virtual node handler). If you go to product page for stage.sctflash.com, you will notice that the text below the banner now says bd when it should say sct, but if you go to product page for stage.bullydog.com, it says the bd which is correct. Here is an image of the both product nodes under each root node:

    enter image description here

    Notice how there is a product node under products which is under each root node (sctflash.com and bullydog.com).

    I noticed if I sort the root nodes and put sctflash.com first and bullydog.com second, it pulls the properties from sctflash.com. Basically, it is pulling the properties from whatever root node is first in the content tree. I suspect I am doing something wrong in the following code, because when I go to one of the product pages, it calls this and it seems like TypedContentAtRoot is the very root of the content tree, not the the root of your website. I am not sure if that makes sense, but basically what I mean is that if I am on sctflash.com, product page and I called TypedContentAtRoot, it doesn't go to sctflash.com, but it goes to bullydog.com. Here is the product virtual node code:

     public class ProductVirtualNodeRouteHandler : UmbracoVirtualNodeRouteHandler
        {
            protected override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext)
            {
    
               // umbracoContext = UmbracoContext.EnsureContext(new HttpContextWrapper(HttpContext.Current), ApplicationContext.Current);
                var helper = new UmbracoHelper(umbracoContext);
                const string alias = "Product";
                return helper.TypedContentAtRoot()
                    .First()
                    .Descendants()
                    .First(d => d.DocumentTypeAlias.InvariantEquals(alias));
            }
        }
    

    My guess is that when it calls helper.TypedContentAtRoot..., it returns as I mentioned, the very top root (bullydog.com) in this case. Can someone verify if this is correct?

    The code that is currently on the two stage websites has the the the line umbracoContext = UmbracoContext.EnsureContext(new HttpContextWrapper(HttpContext.Current), ApplicationContext.Current);, I just commented out because I wasn't sure if I needed it.

    So I guess my question boils down to, if I am on bullydog.com/products/product, how can i make sure it pulls the properies from bullydog.com and if I am on sctflash.com\products\product, how can I make sure it pulls the properties from sctflash.com?

    Thanks for all the help and sorry for the long post, I just wanted to give as much info as possible

    Saied

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Jun 25, 2016 @ 21:55
    David Brendel
    0

    Hi Saied,

    as you stated correctly the TypedContentAtRoot() always returns the first level nodes. Thats why First() always returns the bullydog.com node.

    Haven't used the virtualnoderoutehandler before so not sure how to handle that in the best way.

    Maybe one possibility would be to get the current host from the URL and then fetch not the first root node but the one with the matching host assigned to it.

    Regards David

  • Saied 349 posts 674 karma points
    Jun 25, 2016 @ 22:06
    Saied
    0

    Hi David

    After digging some more, I realized that it was doing exactly that. I was going to do the approach you mentioned. There seemed to be a variety of ways I can get the correct root node using the host name. Do you have a recommended way?

    The virtualnoderoutehandler was just some code I got from James South.

    Thanks Saied

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Jun 26, 2016 @ 22:28
    David Brendel
    0

    Hi Saied,

    think I have some code which does that but not sure in which project.

    I will see if I can find it, but can't promise.

    Regards David

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Jun 27, 2016 @ 19:07
    David Brendel
    0

    Hi Saied,

    just found some code which does not exactly what you want but could be a starting point.

    UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
            List<LanguageInfo> list = new List<LanguageInfo>();
            var allLanguages = new List<umbraco.cms.businesslogic.language.Language>();
    
            var curLanguage = library.GetCurrentDomains(nodeid)[0].Language;
            var ancestors = umbracoHelper.TypedContent(nodeid).AncestorOrSelf("Dbroot").Children;
    
            foreach (var homepage in ancestors)
            {
                var domain = Domain.GetDomainsById(homepage.Id)[0];
                allLanguages.Add(domain.Language);
            }
    

    That code expects a node id to get the current domain. Maybe you can have a look if you can get that from the requestContext.

    Regards David

Please Sign in or register to post replies

Write your reply to:

Draft