Skip to content

Instantly share code, notes, and snippets.

View casper-rasmussen's full-sized avatar

Casper Aagaard Rasmussen casper-rasmussen

View GitHub Profile
[Component()]
// Adding the Pagetree to the product catalog, allowing to drag & drop Page in ContentArea
public class PageNavigationComponent : ComponentDefinitionBase
{
public PageNavigationComponent()
: base("epi-cms.component.MainNavigationComponent")
{
LanguagePath = "/episerver/cms/components/pagetree";
SortOrder = 150;
PlugInAreas = new string[] { "/episerver/commerce/mainnavigation/defaultgroup" };
[Serializable]
[PropertyDefinitionTypePlugIn(DisplayName = "PropertyCategoryList")]
public class PropertyCategoryListPropertyDefinition : PropertyData
{
private EPiServer.Core.CategoryList _inner;
public PropertyCategoryListPropertyDefinition()
: this(new EPiServer.Core.CategoryList()) { }
public PropertyCategoryListPropertyDefinition(EPiServer.Core.CategoryList inner)
//Registration of Content goes here
public class BaseProductType : ProductContent
{
[Display(Name = "Category", Order = 0, GroupName = "EPiServerCMS_SettingsPanel")]
[BackingType(typeof(PropertyCategoryListPropertyDefinition))]
public virtual CategoryList Category { get; set; }
//Additional Properties
}
[InitializableModule]
[ModuleDependency(typeof(ServiceContainerInitialization))]
public class SetDefaultAssetGroupInitialization : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
AssetUrlConventions assetUrlConventions = context.Locate.Advanced.GetInstance<AssetUrlConventions>();
//Add the default group to be Image
assetUrlConventions.AddDefaultGroup<BaseProductType>("Image");
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Commerce.Initialization.InitializationModule))]
public class AccessoryTypeRegistrationInitialization : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
var associationDefinitionRepository = context.Locate.Advanced.GetInstance<GroupDefinitionRepository<AssociationGroupDefinition>>();
associationDefinitionRepository.Add(new AssociationGroupDefinition { Name = RelatedTypeConstants.Accessory });
public class SectionHierachicalCatalogRouter : HierarchicalCatalogPartialRouter
{
public const string SectionRouteValue = "section";
//Predefined segments that will not be resolved to content
private IEnumerable<string> _segments = new string[] { "specifications", "specifications/", "interior", "interior/", "quote", "quote/", "technology", "technology/", "accessories", "accessories/", "design", "design/" };
private readonly IContentLoader _contentLoader;
public TabHierachicalCatalogRouter(CatalogContentBase commerceRoot, Func<ContentReference> func)
public override PartialRouteData GetPartialVirtualPath(CatalogContentBase content, string language, RouteValueDictionary routeValues,
RequestContext requestContext)
{
//Ensure that we don't include the section segment in our Commrece route lookup
object value;
bool found = routeValues.TryGetValue(SectionRouteValue, out value);
//Let's remove our section route value
routeValues.Remove(SectionRouteValue);
this._urlResolver.GetUrl(product.ContentLink, ContentLanguage.PreferredCulture.Name,
new VirtualPathArguments()
{
RouteValues = new RouteValueDictionary(new { section = "specifications" })
});
public override object RoutePartial(PageData content, SegmentContext segmentContext)
{
//Ask Episerver to resolve the object for requested URL
object ob = base.RoutePartial(content, segmentContext);
if (ob != null)
{
SegmentPair segment = segmentContext.GetNextValue(segmentContext.RemainingPath);
if (!String.IsNullOrWhiteSpace(segment.Next))
protected override CatalogContentBase FindNextContentInSegmentPair(CatalogContentBase catalogContent, SegmentPair segmentPair, SegmentContext segmentContext, CultureInfo cultureInfo)
{
CatalogContentBase currentCatalog = base.FindNextContentInSegmentPair(catalogContent, segmentPair, segmentContext, cultureInfo);
if (_segments.Contains(segmentPair.Next, StringComparer.InvariantCultureIgnoreCase))
{
//Let's tell Episerver to route to parent product
var parentProduct = this._contentLoader.GetBySegment(catalogContent.ParentLink, segmentContext.LastConsumedFragment, cultureInfo) as CatalogContentBase;
return parentProduct;