E commerce 在Kentico中以编程方式注入翻译后的产品时出错,是否正确?

E commerce 在Kentico中以编程方式注入翻译后的产品时出错,是否正确?,e-commerce,kentico,E Commerce,Kentico,有关信息,我已经安装了一个新版本的Kentico v12,我使用的是基本的goat模板 我有一个Web服务中的产品列表(这是我的真实来源),我想注入其中 肯蒂科的后台办公室 从Web服务接收的产品与翻译时使用的语言相关。 如果我有两种语言,比如说荷兰语和法语,我会得到每种产品两次 实例: 假设我的Web服务只有一种产品,但可以识别两种语言,当我使用它时,我将收到两种产品 ProductId:1,语言:NL,名称:NameTranslatedInDutch ProductId:1,语言:FR,名

有关信息,我已经安装了一个新版本的Kentico v12,我使用的是基本的goat模板

我有一个Web服务中的产品列表(这是我的真实来源),我想注入其中 肯蒂科的后台办公室

从Web服务接收的产品与翻译时使用的语言相关。 如果我有两种语言,比如说荷兰语和法语,我会得到每种产品两次

实例:

假设我的Web服务只有一种产品,但可以识别两种语言,当我使用它时,我将收到两种产品

  • ProductId:1,语言:NL,名称:NameTranslatedInDutch
  • ProductId:1,语言:FR,名称:NameTranslatedFrench
允许我对它们进行分组的标识符是字段“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服务接收的数据结构不是一个选项

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

我遵循了这些教程:


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

之前

  • baseDocument.InsertAsNewCultureVersion(facet.Language,true)
试试看

  • if(baseDocument!=null)
    {
    baseDocument.SetValue(“产品名称”、“产品名称”)
    }
然后打电话给

  • baseDocument.InsertAsNewCultureVersion(facet.Language,true)

让我知道这是否有效

多谢各位!这样我就打开了锁:)不客气!很乐意帮忙。