Month: December 2011

Add an Ektron ecommerce product item

Ektron CMS includes an e-commerce package that fully integrates with the rest of the CMS.  This makes it very easy to combine content with products and manage it all through a single interface.  The Ektron API also includes a dedicated e-commerce section which gives full control over the commerce process.

Below is a snippet of code for adding a new commerce product (also known as a catalogue entry) and then assigning the product to a taxonomy.

This code was written using v8.5 of Ektron CMS.

Ektron.Cms.Commerce.CatalogEntryApi entryApi = new Ektron.Cms.Commerce.CatalogEntryApi();
Ektron.Cms.Framework.Organization.TaxonomyItemManager taxItemMgr = new Ektron.Cms.Framework.Organization.TaxonomyItemManager();

Ektron.Cms.Commerce.KitData pd = new Ektron.Cms.Commerce.KitData();

// Do standard product stuff
pd.Title = title;
pd.FolderId = folderId;
pd.Sku = productId;
pd.LanguageId = 2057;
pd.ProductType = new Ektron.Cms.Commerce.ProductTypeData();
pd.ProductType.Id = 10;
pd.TaxClassId = 1;

// Pricing stuff
decimal listPrice = Convert.ToDecimal(price);
decimal salePrice = Convert.ToDecimal(price);

pd.Pricing = new Ektron.Cms.Commerce.PricingData(826, salePrice, listPrice);

// Do the smartform bit
XmlDocument contentXml = new XmlDocument();

XmlElement xelRoot = contentXml.CreateElement("root");
XmlElement xelProductId = contentXml.CreateElement("productId");
XmlElement xelDesc = contentXml.CreateElement("Description");
XmlElement xelColl = contentXml.CreateElement("Collection");

xelProductId.InnerText = productId;
xelDesc.InnerText = summary;
xelColl.InnerText = collection;

xelRoot.AppendChild(xelEAN);
xelRoot.AppendChild(xelDesc);
xelRoot.AppendChild(xelColl);
contentXml.AppendChild(xelRoot);

pd.Html = contentXml.OuterXml;

// Add the product
entryApi.Add(pd);

// Add to taxonomy categories
Ektron.Cms.TaxonomyItemData taxonomyItem1 = new Ektron.Cms.TaxonomyItemData();
taxonomyItem1.TaxonomyId = taxonomyId;
taxonomyItem1.ItemId = pd.Id;
taxonomyItem1.ItemLanguageId = pd.LanguageId;
taxItemMgr.Add(taxonomyItem1);