private static Guid CreateProductInternal(string productTypeName, string title, string description, string sku, double? weight, bool isShippable, decimal price, DateTime saleEndDate, DateTime saleStartDate, decimal salePrice)
{
CatalogManager manager = CatalogManager.GetManager();
if (manager.GetProducts().Where(t => t.Title == title).SingleOrDefault() != null)
{
return Guid.Empty; // Product already exists
}
ProductType productType = manager.GetProductTypes().Where(t => t.Title == productTypeName).SingleOrDefault();
if (productType == null)
{
return Guid.Empty; // Product Type does not exist
}
Product product = manager.CreateProduct(productType.ClrType);
product.ClrType = productType.ClrType;
product.Title = title;
product.AssociateBuyerWithRole = Guid.Empty;
product.DateCreated = DateTime.Now;
product.Description = description;
product.IsShippable = isShippable;
product.Price = price;
product.SaleEndDate = saleEndDate;
product.SaleStartDate = saleStartDate;
product.SalePrice = salePrice;
product.Sku = sku;
product.UrlName = Regex.Replace(title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
product.Visible = true;
product.Weight = weight;
product.Status = GenericContent.Model.ContentLifecycleStatus.Master;
manager.Provider.RecompileItemUrls(product);
manager.SaveChanges();
var contextBag = new Dictionary<string, string>();
contextBag.Add("ContentType", product.GetType().FullName);
string workflowOperation = "Publish";
WorkflowManager.MessageWorkflow(
product.Id,
product.GetType(),
"OpenAccessDataProvider",
workflowOperation,
false,
contextBag);
return product.Id;
}