在 Kentico 中以编程方式注入翻译产品时出错,我做对了吗?

Error when programmatically injecting translated products in Kentico, am I doing it right?

有关信息,我安装了全新版本的 Kentico v12,并且我使用的是基本山羊模板。

我有一个 web 服务中的产品列表(这是我的真实来源),我想将其注入 Kentico 的后台。

从网络服务接收到的产品与其翻译的语言相关。 如果我有 2 种语言,比方说荷兰语和法语,我将获得每种产品 2 次。

实际例子:

假设我的网络服务只有 1 个产品但识别 2 种语言,当我使用它时我将收到 2 个产品。

允许我对它们进行分组的标识符是字段 "ProductId"

为了创建我的产品的新文化版本,我使用了 TreeNode 的方法 "InsertAsNewCultureVersion"。

当我执行它时出现这个错误:

我的代码:

                // I search all documents related to the ProductId received from the webservice
                var document = DocumentHelper
                         .GetDocuments()
                         .OnSite("Goat")
                         .Culture(facet.Language)
                         .Path("/", PathTypeEnum.Children)
                         .Where(
                           new WhereCondition(
                               "DocumentName",
                               QueryOperator.Equals,
                               facet.ProductId))
                         .FirstOrDefault();

                // If it already exists I only have to update it
                if (document != null)
                {
                    UpdateProductTreeNode(facet, document);
                }
                // Otherwise i need to insert a new culture version
                else
                {
                    // I search for the first possible version for my product
                    var baseDocument = (SKUTreeNode)DocumentHelper
                         .GetDocuments()
                         .OnSite("Goat")
                         .Path("/", PathTypeEnum.Children)
                         .Where(
                           new WhereCondition(
                               "DocumentName",
                               QueryOperator.Equals,
                               facet.ProductId))
                         .FirstOrDefault();

                    // I'm sure it's not null, i've already checked it above but didn't copy/paste this part 
                    baseDocument.InsertAsNewCultureVersion(facet.Language, true); // Exception occurs here

                    var newDocument = DocumentHelper
                         .GetDocuments()
                         .OnSite("Goat")
                         .Culture(facet.Language)
                         .Path("/", PathTypeEnum.Children)
                         .Where(
                           new WhereCondition(
                               "DocumentName",
                               QueryOperator.Equals,
                               facet.ProductId))
                          .FirstOrDefault();

                    UpdateProductTreeNode(facet, newDocument);
                }

我做错了什么吗? 我应该采取不同的做法吗?

遗憾的是更新从 web 服务接收到的数据的结构不是一个选项。

我的代码质量不是很好但是不相关,我正在做一个概念验证,一旦我确定它可以工作质量就会提高^^

我遵循了这些教程:

所以您返回的 SKUTreeNode 是 cms.product 页面类型,并且在插入时需要填写一列。默认情况下 CMS.Product 有两个字段。 ProductID 和 ProductName。

之前

  • baseDocument.InsertAsNewCultureVersion(facet.Language, true)

尝试

  • if (baseDocument != null) { baseDocument.SetValue("ProductName","the name of the product") }

然后调用...

  • baseDocument.InsertAsNewCultureVersion(facet.Language, true)

如果有效,请告诉我!