Reputation: 147
I am developing a tool for migrating data from Sitecore to Kentico. I'm looking for a way to create a product with two different cultures using Kentico API 9. I want to extract data from Sitecore and store it to Kentico using API.
I've checked out the Kentico documentation and it provides us with code to create a product:
// 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);
But I can't figure out how to create a multi-culture product with attachments per culture.
Would any one help or recommend a different way to migrate data from Sitecore to Kentico?
Upvotes: 3
Views: 280
Reputation: 116
You should use DocumentHelper.InsertDocument() located in CMS.DocumentEngine to save the page in the first culture, and then use DocumentHelper.InsertNewCultureVersion() to add other cultures to the page. Your code is capable of creating SKUs, so to create product pages for those SKUs, you should add the following:
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");
To add an attachment to a document, use DocumentHelper.AddAttachment() before saving the document to the database. Then just repeat the block after DocumentHelper.InsertDocument for any number of cultures you need to add.
Hope this helps.
Upvotes: 3