我正在开发一种工具,用于将数据从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吗?
答案 0 :(得分:3)
您应该使用 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 之后重复该块,即可添加任意数量的文化。
希望这有帮助。