public static void CreateProductType(string titleSingular, string titlePlural, ProductDeliveryType deliveryType)
{
MetadataManager metadataManager = MetadataManager.GetManager();
CatalogDefinitionManager catalogDefinitionManager = new CatalogDefinitionManager();
using (CatalogManager catalogManager = CatalogManager.GetManager())
{
int productTypesCount = catalogManager.GetProductTypes().Count();
ProductType productType = catalogManager.CreateProductType();
productType.Title = titleSingular;
productType.TitlePlural = titlePlural;
productType.ProductDeliveryType = deliveryType;
string productClrType;
catalogManager.CreateProductTypePersistance(productType, metadataManager, out productClrType);
productType.ClrType = productClrType;
catalogDefinitionManager.AddProductTypeDefinition(productType);
if (productTypesCount == 1)
{
var singleType = catalogManager.GetProductTypes().Single();
catalogDefinitionManager.AdjustForMultipleProductTypes(singleType);
}
catalogManager.SaveChanges();
metadataManager.SaveChanges(true);
ProductTypeResolver.RestartProductServiceHost();
}
}