编程语言
首页 > 编程语言> > c#-使用Kentico API 9创建多元文化产品

c#-使用Kentico API 9创建多元文化产品

作者:互联网

我正在开发一种用于将数据从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之后重复此块,即可添加需要添加的任意数量的区域性.

希望这可以帮助.

标签:kentico,c
来源: https://codeday.me/bug/20191118/2027971.html