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

Create NodeContent with data in different language branches (Commerce 8.2.0 and CMS 7.15)

Vote:
 

Hi,

I'm trying to create NodeContent with 3 languages by using the ContentRepository. I have created a class "Category" that inherits the NodeContent from EPiServer.Commerce.Catalog.ContentTypes

[CatalogContentType(GUID = "D20F45B0-89BF-4897-B89D-FF60FDF2101F", DisplayName = "Category")]
public class Category : NodeContent {

}

To create the category I do the following:

var myCategory = ContentRepository.GetDefault(parentContentReference);
myCategory.Code = "MY_CODE";
myCategory.Name = "My category";
myCategory.DisplayName = "My category";

var contentReference = ContentRepository.Save(myCategory, SaveAction.Publish, AccessLevel.NoAccess);

The above creates and publishes the category in the primary language (in this case danish ("da")).

Now I'm in doubt exactly what to do, but I have tried this:

var allBranches = ContentRepository.GetLanguageBranches(myCategory.ContentLink);

var germanCategory = allBranches.FirstOrDefault(b => b.Language.Name == "de");
germanCategory = germanCategory.CreateWritableClone();
germanCategory.DisplayName = "Meine Kategorie";
ContentRepository.Save(germanCategory, SaveAction.Publish, AccessLevel.NoAccess);

It seems like I'm getting the correct branch, but when I call the "Save" method on the last line I get an exception saying: The provided content link does not have a value.

But the germanCategory has a ContentLink with a value.

The stack trace for the exception is here:

   at EPiServer.Core.DefaultContentLoader.Get[T](ContentReference contentLink, LoaderSettings loaderSettings)
   at EPiServer.Commerce.Validation.MissingStartingPointLanguageValidator.<>c__DisplayClass2.b__1(ICommerceRouter route)
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at EPiServer.Commerce.Validation.MissingStartingPointLanguageValidator.ShouldShowWarning(CatalogContentBase content)
   at EPiServer.Commerce.Validation.MissingStartingPointLanguageValidator.Validate(CatalogContentBase instance)
   at EPiServer.Validation.ValidationService.ValidateRecursively(Object instance, HashSet`1 visitedInstances)
   at EPiServer.Core.ContentProvider.Validate(IContent content, SaveAction action)
   at EPiServer.Core.DefaultContentRepository.Save(IContent content, SaveAction action, AccessLevel access)

Am I doing it wrong, and what is the correct way to do it?

Best regards
Rasmus Beuchert

#114484
Dec 12, 2014 14:43
Vote:
 

Compare the contententreference of germanCategory is not ContentReference.EmptyReference

I doubt germanCategory doesnot contain the category you are expecting. It will never be NULL even it didnot pick any thing therefore compare that contentreference of retried object is not a ContentReference.EmptyReference.

Refards
/K

#114493
Dec 12, 2014 16:32
Vote:
 

Hi,

The exception you are seeing is likely because there's no start (home page) created for the German language. Please try with that.

Regards.

/Q

#114500
Dec 12, 2014 18:09
Vote:
 

Thanks for your replies.

K Khan > The ContentLink of the germanCategory is not empty. It contains a real id (the same as the danish category).

Quan Mai > I didn't have a start page for the german language, but I've just tried creating it, but it didn't make any difference.

Any other ideas?

Thanks.

Rasmus

#114502
Dec 12, 2014 21:24
Vote:
 

Hi again,

I found out what was causing the issue. I am running the above code in a scheduled job in EPiServer, and it seems like it cannot resolve the "Start Page" in this context.

I have moved the code to a simple controller, and it just works now.

But I guess this means that it is not possible to do this in a scheduled job, or is there a workaround for this?

Best regards
Rasmus

#114532
Dec 15, 2014 10:26
Vote:
 

Schedule Job doesnot run under a webrequest therefore languages are resolved differently in scheduled jobs. To get your job to behave the same way, you will have to make sure you are requesting for the correct version.

Regrads
/K

#114542
Dec 15, 2014 11:41
Vote:
 

Make sure your site has a wildcard host mapped to it (admin->config tab-> manage websites, click on your site). I think the site who has the wildcard character mapped to it will be what site context the scheduled job runs in (if run automatically).

/T

#114836
Dec 23, 2014 18:44
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.