首页 > 解决方案 > 在 Kentico 中以编程方式注入翻译产品时出错,我做得对吗?

问题描述

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

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

从 Web 服务接收的产品与它们的翻译语言有关。如果我有 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 服务接收到的数据结构。

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

我遵循了这些教程:

标签: e-commercekentico

解决方案


因此,您返回的 SKUTreeNode 是 cms.product 页面类型,插入时需要填写一列。默认情况下 CMS.Product 有两个字段。产品 ID 和产品名称。

  • baseDocument.InsertAsNewCultureVersion(facet.Language, true)

尝试

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

然后打电话...

  • baseDocument.InsertAsNewCultureVersion(facet.Language, true)

让我知道这是否有效!


推荐阅读