Create multilanguage catalog nodes/entries

Vote:
 

Hi,

It looks like you have to create a catalog node/entry in the default catalog language first, if you try to create a item in another language first you will get a error when trying to save the item,

------------

The provided content link does not have a value.
Parameter name: contentLink

------------

What is the supported way of doing this, getting the default langauge code for a catalog? If I check the catalog object it has a default language parameter but that is just a string, in my case named "English", that does not relate to a language code/langauge selector. Should a query EPiServer for the language "English" and from there get the language code?

/Viktor

#79407
Dec 16, 2013 16:25
Vote:
 

Is this Commerce 7.5? Also, can you post some example code how you get this error? Thanks!

#79419
Dec 17, 2013 8:46
Vote:
 

Hi,

Yes this is for 7.5. I have a catalog that currently has English and German, English is the default language for the catalog and during the catalog import the user can import German or English products. The following is the code we got the error with before,
--------------------
public ContentReference CreateOrUpdateNode(ContentReference parentReference, string name, string translatedName, IMarket market)
{
    var code = _catalogRepository.ConvertToCode(string.Format("{0} {1}", name.Trim(), parentReference.ID));
    var node = _catalogRepository.GetNode<Core.Models.MetaData.ProductNode>(code, market);
    if(node != null)
    {
        node = node.CreateWritableClone() as Core.Models.MetaData.ProductNode;
    }
    else
    {
        node = _contentRepository.GetDefault<Core.Models.MetaData.ProductNode>(parentReference, new LanguageSelector(market.DefaultLanguage);
        node.Name = _catalogRepository.GetSafeProductName(name);
       node.Code = code;
     }
     node.UrlSegment = Utilities.UrlUtility.GetSafeUrlSegment(translatedName);
     node.DisplayName = translatedName;
     return _contentRepository.Save(node, SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess);
}
--------------------
First we try to get the node, if it's not found get a default node for the current markets language (German) and then make the changes and save the node. If the node was null and the market is Germany we get the following error when trying to save it,
--------------------
The provided content link does not have a value.
Parameter name: contentLink
--------------------
Everything work perfect if we have already created the English version of the node and just add a new language version.
I have now rewritten the code as follows.
First get the current catalogs default language and find the language code for that language,
-------------------
var catalogReference = _referenceConverter.GetContentLink(Properties.Settings.Default.Import_Catalog_Id, CatalogContentType.Catalog, 0);
var catalog = _contentRepository.Get<CatalogContent>(catalogReference);
var defaultLanguageCode = _languageBranchRepository.ListAll()
    .Where(item => string.Compare(item.Name, catalog.DefaultLanguage, true) == 0)
    .Select(item => item.LanguageID)
    .FirstOrDefault();
-------------------
Then try to load the node for the current market (german) if it's not found create the node with the default language code, save it and try to load it again with the current market,
-------------------
public ContentReference CreateOrUpdateNode(ContentReference parentReference, string name, string translatedName, IMarket market, string defaultLanguageCode)
{
    var code = _catalogRepository.ConvertToCode(string.Format("{0} {1}", name.Trim(), parentReference.ID));
    var node = _catalogRepository.GetNode<Core.Models.MetaData.ProductNode>(code, market);
    if (node == null)
    {
        node = _contentRepository.GetDefault<Core.Models.MetaData.ProductNode>(parentReference, new LanguageSelector(defaultLanguageCode));
        node.Name = _catalogRepository.GetSafeProductName(name);
        node.Code = code;
        _contentRepository.Save(node, SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess);
        node = _catalogRepository.GetNode<Core.Models.MetaData.ProductNode>(code, market);
     }
     if (node != null)
     {
          node = node.CreateWritableClone() as Core.Models.MetaData.ProductNode;
          node.UrlSegment = Utilities.UrlUtility.GetSafeUrlSegment(translatedName);
          node.DisplayName = translatedName;
          return _contentRepository.Save(node, SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess);
     }
     return null;
}
-------------------
Both having to create the node like this and the way you have to find the default language code for the catalog feels unessesary "hard".

/Viktor

#79426
Edited, Dec 17, 2013 10:42
Vote:
 

What if you do GetDefault without the language selector? I think it will give you the English one automatically. Then you'll have to save and publish the English version, load the German, Clone and edit it.

We are aware that the marriage of the CMS and the Catalog multi language features isn't perfect and we will try to improve it.

#79428
Dec 17, 2013 11:15