C# 使用Kentico API 9创建多文化产品

C# 使用Kentico API 9创建多文化产品,c#,kentico,C#,Kentico,我正在开发一个工具,用于将数据从Sitecore迁移到Kentico。我正在寻找一种使用Kentico API 9创建具有两种不同文化的产品的方法。我想从Sitecore提取数据,并使用API将其存储到Kentico 我已经查阅了Kentico文档,它为我们提供了创建产品的代码: // Gets a department DepartmentInfo department = DepartmentInfoProvider.GetDepartmentInfo("NewDepartment", Si

我正在开发一个工具,用于将数据从Sitecore迁移到Kentico。我正在寻找一种使用Kentico API 9创建具有两种不同文化的产品的方法。我想从Sitecore提取数据,并使用API将其存储到Kentico

我已经查阅了Kentico文档,它为我们提供了创建产品的代码:

// Gets a department
DepartmentInfo department = DepartmentInfoProvider.GetDepartmentInfo("NewDepartment", SiteContext.CurrentSiteName);

// Creates a new product object
SKUInfo newProduct = new SKUInfo();

// Sets the product properties
newProduct.SKUName = "NewProduct";
newProduct.SKUPrice = 120;
newProduct.SKUEnabled = true;
if (department != null)
{
   newProduct.SKUDepartmentID = department.DepartmentID;
}
newProduct.SKUSiteID = SiteContext.CurrentSiteID;

// Saves the product to the database
// Note: Only creates the SKU object. You also need to create a connected Product page to add the product to the site.
SKUInfoProvider.SetSKUInfo(newProduct);
但我不知道如何创建一个跨文化的产品,每个文化都有附件


有人会帮助或推荐一种不同的方法将数据从Sitecore迁移到Kentico吗?

您应该使用CMS.DocumentEngine中的DocumentHelper.InsertDocument()将页面保存在第一个区域性中,然后使用DocumentHelper.InsertNewCultureVersion()向页面添加其他区域性。您的代码能够创建SKU,因此要为这些SKU创建产品页面,您应该添加以下内容:

TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

//Get a parent node, under which the product pages will be created.
//Replace "/Store/Products" with page alias of the parent page to use.
TreeNode parentNode = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/Store/Products", "en-us");

//Create a new product page
TreeNode node = TreeNode.New("CMS.Product", tree);

//Set the product page's culture and culture specific properties, according to your needs
node.DocumentCulture = "en-us";
node.DocumentName = "ProductPage - English";
node.NodeSKUID = newProduct.SKUID;

//Save the page
DocumentHelper.InsertDocument(node, parentNode, tree);

//Set the product pages culture and culture specific properties for another culture
node.DocumentCulture = "es-es";
node.DocumentName = "ProductPage - Spanish";
node.NodeSKUID = newProduct.SKUID;

//Save the new culture version
DocumentHelper.InsertNewCultureVersion(node, tree, "es-es"); 
要将附件添加到文档中,请在将文档保存到数据库之前使用DocumentHelper.AddAttachment()
。 然后,对于需要添加的任意数量的区域性,只需在DocumentHelper.InsertDocument之后重复该块

希望这有帮助