Having a CVL with all model-languages using Custom CVL in inRiver PIM

Hi!

In inRiver PIM the CVL is a core functionality that is greatly appricated by its users. A common CVL is the "language CVL", that holds all the languages that the users use. Typically used to mark products that have or should be translated. The simple solution is handling this CVL manually but then you always have to keep the CVL updated. A much more elegant and future proof way is using the inRivers ICustomValueList interface to create a custom CVL that is always updated with all the active languages. Lets have a look on how to do this!

When implementing the ICustomValueList interface you have two important methods that you need to implement, the GetAllCVLValues and GetCVLValueByKey. Both of these methods will use the UtilityService.GetAllLanguages() to get all the active languages in the inRiver installation.

Starting with GetAllCVLValues I simply uses Linq and a helper method to convert the CultureInfo objects into CVLValue(s). Like this
public List GetAllCVLValues()
        {
            return Context.ExtensionManager.UtilityService.GetAllLanguages()
                    .Select(CreateCvlValue)
                    .ToList();
        }

        private CVLValue CreateCvlValue(CultureInfo ci)
        {
            return new CVLValue()
            {
                Key = ci.Name,
                Value = $"{ci.DisplayName} ({ci.Name})",
                CVLId = Id
            };
        }

The helper method CreateCvlValue creates a key with language code and a string name (not LocaleString) that is the language name with the language code within parentheses. This is useful when the inRiver installation has multiple variations of the same language family, for example American and British English activated.

Next up is the GetCVLValueByKey method. I use Linq to find the corresponding CultureInfo with that key and then convert it to a CVLValue.

public CVLValue GetCVLValueByKey(string key)
        {
            var ci = Context.ExtensionManager.UtilityService.GetAllLanguages()
                .FirstOrDefault(
                    c => string.Equals(c.Name, key, StringComparison.OrdinalIgnoreCase));

            return ci != null ? CreateCvlValue(ci) : null;
        }

This works both in the new inRiver Product Marketing Cloud (iPMC) and the old on-premise version. The code written is for iPMC, to adapt it to the on-premise version simply change from Context.ExtensionManager to ExtensionService.Instance since this is executed within the inRiver server context. You also need to implement the GetId method which simply is a hardcoded string for the CVL-ID. In iPMC this is stored as the Extension Id instead.

If you have any thoughts then please post a comment!
Hope this helps!

/Peter

Comments

  1. Will Culture en-US work as CVL Key?

    ReplyDelete
    Replies
    1. Hi Tobias! A very valid question - and the answer is actually yes! The normal rules for CVL-keys are ignored when using a custom CVL.

      Delete

Post a Comment

Popular Posts