e-commerce - 在 Kentico 中以编程方式注入翻译产品时出错,我做得对吗?
问题描述
有关信息,我已经安装了全新版本的 Kentico v12,并且我正在使用基本的山羊模板。
我有一个 Web 服务中的产品列表(这是我的事实来源),我想将其注入 Kentico 的后台。
从 Web 服务接收的产品与它们的翻译语言有关。如果我有 2 种语言,比如说荷兰语和法语,我会得到每种产品 2 次。
实际例子:
假设我的网络服务只有 1 种产品,但可以识别 2 种语言,当我使用它时,我会收到 2 种产品。
- ProductId:1,语言:NL,名称:NameTranslatedInDutch
- ProductId:1,语言:FR,名称:NameTranslatedInFrench
允许我对它们进行分组的标识符是字段“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 有两个字段。产品 ID 和产品名称。
前
baseDocument.InsertAsNewCultureVersion(facet.Language, true)
尝试
if (baseDocument != null) { baseDocument.SetValue("ProductName","the name of the product") }
然后打电话...
baseDocument.InsertAsNewCultureVersion(facet.Language, true)
让我知道这是否有效!
推荐阅读
- mysql - 如何通过 xhr fetch response 防止网络请求中显示个人信息
- excel - 如果我存储了一个 IRibbonUI 对象,我可以使用它使用 VBA 代码将控件添加到功能区吗?
- java - MS Graph Java SDK 引发身份验证异常
- c# - 将对象添加到 DBSet 时出现 InvalidCastException
- excel - 寻找公式以在 Excel 的两列中查找相似名称
- python - 用于对象检测的 TensorFlowLite 模型在加载时抛出 ValueError
- vue.js - VUEJS:模型在 for 循环中没有改变
- spring - Hystrix Circuit Breaker 是否可以为某些端点关闭而为其他端点打开
- linux - 如何在 Linux 中将临时文件夹(.tmp)转换为二进制文件(.bin)
- spring-boot - 强制 SpingBoot 使用 Gson 而不是 Jackson