Try our conversational search powered by Generative AI!

ContentReference.StartPage ID 0

EVT
EVT
Vote:
 

When running Search & Navigation Content Indexing Job we have an issue that it indexes the CMS part but when it comes to the Commerce part we get an error that homePage is null. I can see that StartPage comes with the following values

Checking at any other point of a running solution the values of the StartPage are these

How can it be?

#304528
Jul 03, 2023 14:15
Vote:
 

The job specifically adds SiteDefinition.Empty to the list of SiteDefinitions it will go through. IIRC then it is for the media. i.e. what you saw is as designed

#304530
Jul 03, 2023 14:27
EVT
Vote:
 

Ok, how to solve this? : D

#304532
Jul 03, 2023 14:29
Vote:
 

This happens when running on schedule because the current HTTP Context is null, therefore, it's not possible to find out which site you are on. If you only have a single site, adding '*' as the site url will solve the issue.

For multi-site sometimes you can use ISiteDefinitionRepository to find all SiteDefinitions you have, pick the one you are interested, then use SiteDefinition.StartPage to get its startpage (e.g. when you process catalog content there's no direct relation between catalog items to the cms content and you typically match catalog name to site name or something like that). For CMS content you will probably need to get page ancestors up to the one having type Home Page - that will be the home page for that content.

#304533
Jul 03, 2023 14:34
Vote:
 

In theory, your code could check if the current SiteDefinition is Empty or not and fallback to a "Default" one

#304534
Jul 03, 2023 14:45
EVT - Jul 03, 2023 14:48
First thing tomorrow!
EVT - Jul 04, 2023 7:53
I don't suppose you have an example of this?
EVT
Vote:
 

@Ruslan

It is a single site and the configuration looks this way

Anything wrong with it?

#304536
Jul 03, 2023 14:48
Vote:
 

That's the setup I meant. Just checked - works fine on catalog content. Might depend on the EPi version, though. I'd trust whatever Quan Mai says :)

#304538
Jul 03, 2023 15:39
Quan Mai - Jul 04, 2023 8:23
thanks for your kind words, but I am wrong from times to times. it's good that we have a community with many great contributors, like you
Vote:
 

@EVT: pseudo of course

if (SiteDefinition.Current == SiteDefinition.Empty)

{

startPage = fallbackStartPageInSetting;

}

else

{

startPage = ContentReference.StartPage;

}

//Get start page;

You can also have this

public ContentReference GetStartPageWithFallback()\

{

if (SiteDefinition.Current == SiteDefinition.Empty)

{

startPage = fallbackStartPageInSetting;

}

else

{

startPage = ContentReference.StartPage;

}

return startPage;

}
#304589
Edited, Jul 04, 2023 8:26
EVT - Jul 04, 2023 8:33
I mean the "fallbackStartPageInSetting" part : D I cannot get to it : D
SystemDefinition.Current.RootPage.ToPageReference() StartPage property is also all 0s.

Copied SiteDefinition.GetCurrentInternal method but also 0s.

Testing ServiceLocator.Current.GetInstance
Quan Mai - Jul 04, 2023 8:54
the easiest way is to have that as convention, or pre-defined value. See post below
Vote:
 

You can have a default fallback name, for example 

var fallbackSiteDefiniton = siteDefinitionRepo.List().FirstOrDefault(x=>x.Name == "default");

or

const Guid FallbackSiteId = new Guid("52513efb-37aa-4974-845b-70b990e65d08");

var fallbackSiteDefinition = siteDefinitionRepo.Get(FallbackSiteId);

#304592
Jul 04, 2023 8:56
EVT
Vote:
 

This seems to work

Let's see what my colleagues think of it. 

#304598
Jul 04, 2023 9:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.