public override void Install(SiteInitializer initializer)
{
base.Install(initializer);
string resourceAssembly = this.GetType().Assembly.FullName;
string customTemplatesArea = "Product catalog SDK sample";
string friendlyWidgetName = "Products catalog sample widget";
initializer.RegisterControlTemplate(MasterListView.titlesOnlyLayoutTemplateName, typeof(MasterListView).FullName, ProductsDefinitions.FrontendTitlesOnlyListViewName, null, customTemplatesArea, Presentation.AspNetTemplate, friendlyControlName:friendlyWidgetName );
initializer.RegisterControlTemplate(MasterListView.titlesDatesLayoutTemplateName, typeof(MasterListView).FullName, ProductsDefinitions.FrontendTitlesDatesListViewName, null, customTemplatesArea, Presentation.AspNetTemplate, friendlyControlName: friendlyWidgetName);
initializer.RegisterControlTemplate(MasterListView.titlesDatesSummariesLayoutTemplateName, typeof(MasterListView).FullName, ProductsDefinitions.FrontendTitlesDatesSummariesListViewName, null, customTemplatesArea, Presentation.AspNetTemplate, friendlyControlName: friendlyWidgetName);
initializer.RegisterControlTemplate(MasterListView.titlesDatesContentsLayoutTemplateName, typeof(MasterListView).FullName, ProductsDefinitions.FrontendTitlesDatesContentsListViewName, null, customTemplatesArea, Presentation.AspNetTemplate, friendlyControlName: friendlyWidgetName);
initializer.RegisterControlTemplate(ProductDetailsView.layoutTemplateName, typeof(ProductDetailsView).FullName, ProductsDefinitions.FrontendFullProductItemDetailViewName, null, customTemplatesArea, Presentation.AspNetTemplate, resourceAssembly, friendlyWidgetName);
this.InstallCustomVirtualPaths(initializer);
this.InstallCustomTaxonomies(initializer);
}
private void InstallCustomVirtualPaths(SiteInitializer initializer)
{
var virtualPathConfig = initializer.Context.GetConfig<VirtualPathSettingsConfig>();
ConfigManager.Executed += new EventHandler<ExecutedEventArgs>(ConfigManager_Executed);
var productsModuleVirtualPathConfig = new VirtualPathElement(virtualPathConfig.VirtualPaths)
{
VirtualPath = ProductsModule.ProductsVirtualPath + "*",
ResolverName = "EmbeddedResourceResolver",
ResourceLocation = "ProductCatalogSample"
};
if (!virtualPathConfig.VirtualPaths.ContainsKey(ProductsModule.ProductsVirtualPath + "*"))
virtualPathConfig.VirtualPaths.Add(productsModuleVirtualPathConfig);
}
private void ConfigManager_Executed(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs args)
{
if (args.CommandName == "SaveSection")
{
var section = args.CommandArguments as VirtualPathSettingsConfig;
if (section != null)
{
// Reset the VirtualPathManager whenever we save the VirtualPathConfig section.
// This is needed so that our prefixes for the widget templates in the module assembly are taken into account.
VirtualPathManager.Reset();
}
}
}
protected void InstallCustomTaxonomies(SiteInitializer initializer)
{
//installs the default Tags and Category taxonomies
this.InstallTaxonomy(initializer, typeof(ProductItem));
var metaMan = initializer.MetadataManager;
var taxMan = initializer.TaxonomyManager;
var flatTaxonomy = this.CreateTaxonomy<FlatTaxonomy>(initializer, "Colors", ColorsTaxonomyId, "Color");
//if the module is reinstalled the taxa will be re-added so a check is needed
if (initializer.TaxonomyManager.GetTaxonomy<FlatTaxonomy>(ColorsTaxonomyId).Taxa.Count() == 0)
{
var taxon1 = initializer.TaxonomyManager.CreateTaxon<FlatTaxon>();
taxon1.Title = "Red";
taxon1.Name = "Red";
var taxon2 = initializer.TaxonomyManager.CreateTaxon<FlatTaxon>();
taxon2.Title = "Blue";
taxon2.Name = "Blue";
flatTaxonomy.Taxa.Add(taxon1);
flatTaxonomy.Taxa.Add(taxon2);
}
var type = metaMan.GetMetaType(typeof(ProductItem));
if (type == null)
{
type = metaMan.CreateMetaType(typeof(ProductItem));
}
if (!type.Fields.ToList().Any(fld => fld.FieldName == "Colors"))
{
var field = metaMan.CreateMetafield("Colors");
field.TaxonomyProvider = taxMan.Provider.Name;
field.TaxonomyId = ColorsTaxonomyId;
field.IsSingleTaxon = false;
type.Fields.Add(field);
}
if (!type.Fields.ToList().Any(fld => fld.FieldName == "ProductImage"))
{
type.Fields.Add(ContentLinksExtensions.CreateContentLinkField("ProductImage", "OpenAccessDataProvider", metaMan, RelationshipType.OneToOne));
}
}