コード例 #1
0
        /// <summary>
        /// Configure default routing for EPiServer Commerce catalog content
        /// </summary>
        /// <remarks>
        /// TODO: If you want to remove the name of the catalog from the url, set the
        /// Catalog:RemoveCatalogFromUrl appSetting to true
        /// </remarks>
        /// <param name="routes"></param>
        private void MapCatalogRoute(RouteCollection routes)
        {
            string removeCatalogFromUrlSetting = System.Configuration.ConfigurationManager.AppSettings["Catalog:RemoveCatalogFromUrl"];
            bool   removeCatalogFromUrl        = false;

            bool.TryParse(removeCatalogFromUrlSetting, out removeCatalogFromUrl);
            if (removeCatalogFromUrl == false)
            {
                CatalogRouteHelper.MapDefaultHierarchialRouter(routes, false);
            }
            else
            {
                // This will pick the first catalog, and strip it from all urls (in and out)
                var contentLoader      = ServiceLocator.Current.GetInstance <IContentLoader>();
                var referenceConverter = ServiceLocator.Current.GetInstance <ReferenceConverter>();

                var firstCatalog =
                    contentLoader.GetChildren <CatalogContent>(referenceConverter.GetRootLink()).FirstOrDefault();

                var partialRouter2 = new HierarchicalCatalogPartialRouter(
                    () => SiteDefinition.Current.StartPage, firstCatalog, false);

                if (firstCatalog != null)
                {
                    routes.RegisterPartialRouter(partialRouter2);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Configure default routing for EPiServer Commerce catalog content
        /// </summary>
        /// <remarks>
        /// TODO: If you want to remove the name of the catalog from the url, set the
        /// Catalog:RemoveCatalogFromUrl appSetting to true
        /// </remarks>
        /// <param name="routes"></param>
        private void MapCatalogRoute(RouteCollection routes)
        {
            string removeCatalogFromUrlSetting = System.Configuration.ConfigurationManager.AppSettings["Catalog:RemoveCatalogFromUrl"];
            bool   removeCatalogFromUrl        = false;

            bool.TryParse(removeCatalogFromUrlSetting, out removeCatalogFromUrl);
            if (removeCatalogFromUrl == false)
            {
                CatalogRouteHelper.MapDefaultHierarchialRouter(routes, false);
            }
            else
            {
                // This will pick the first catalog, and strip it from all urls (in and out)
                var contentLoader                  = ServiceLocator.Current.GetInstance <IContentLoader>();
                var referenceConverter             = ServiceLocator.Current.GetInstance <ReferenceConverter>();
                var languageSelectionFactory       = ServiceLocator.Current.GetInstance <LanguageSelectorFactory>();
                var routingSegmentLoader           = ServiceLocator.Current.GetInstance <IRoutingSegmentLoader>();
                var contentVersionRepo             = ServiceLocator.Current.GetInstance <IContentVersionRepository>();
                var urlSegmentRouter               = ServiceLocator.Current.GetInstance <IUrlSegmentRouter>();
                var contentLanguageSettingsHandler = ServiceLocator.Current.GetInstance <IContentLanguageSettingsHandler>();

                var firstCatalog =
                    contentLoader.GetChildren <CatalogContent>(referenceConverter.GetRootLink()).FirstOrDefault();

                var partialRouter = new HierarchicalCatalogPartialRouter(
                    () => SiteDefinition.Current.StartPage,
                    commerceRoot: firstCatalog,
                    supportSeoUri: false,
                    contentLoader: contentLoader,
                    languageSelectorFactory: languageSelectionFactory,
                    routingSegmentLoader: routingSegmentLoader,
                    contentVersionRepository: contentVersionRepo,
                    urlSegmentRouter: urlSegmentRouter,
                    contentLanguageSettingsHandler: contentLanguageSettingsHandler);

                var partialRouter2 = new HierarchicalCatalogPartialRouter(
                    () => SiteDefinition.Current.StartPage, firstCatalog, false);

                if (firstCatalog != null)
                {
                    routes.RegisterPartialRouter(partialRouter2);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Configure default routing for EPiServer Commerce catalog content
        /// </summary>
        /// <remarks>
        /// TODO: If you want to remove the name of the catalog from the url, set the
        /// Catalog:RemoveCatalogFromUrl appSetting to true
        /// </remarks>
        /// <param name="routes"></param>
        private void MapCatalogRoute(RouteCollection routes)
        {
            string removeCatalogFromUrlSetting = System.Configuration.ConfigurationManager.AppSettings["Catalog:RemoveCatalogFromUrl"];
            bool removeCatalogFromUrl = false;
            bool.TryParse(removeCatalogFromUrlSetting, out removeCatalogFromUrl);
            if (removeCatalogFromUrl == false)
            {
                CatalogRouteHelper.MapDefaultHierarchialRouter(routes, false);

            }
            else
            {
                // This will pick the first catalog, and strip it from all urls (in and out)
                var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
                var referenceConverter = ServiceLocator.Current.GetInstance<ReferenceConverter>();
                var languageSelectionFactory = ServiceLocator.Current.GetInstance<LanguageSelectorFactory>();
                var routingSegmentLoader = ServiceLocator.Current.GetInstance<IRoutingSegmentLoader>();
                var contentVersionRepo = ServiceLocator.Current.GetInstance<IContentVersionRepository>();
                var urlSegmentRouter = ServiceLocator.Current.GetInstance<IUrlSegmentRouter>();
                var contentLanguageSettingsHandler = ServiceLocator.Current.GetInstance<IContentLanguageSettingsHandler>();

                var firstCatalog =
                    contentLoader.GetChildren<CatalogContent>(referenceConverter.GetRootLink()).FirstOrDefault();

                var partialRouter = new HierarchicalCatalogPartialRouter(
                    () => SiteDefinition.Current.StartPage,
                    commerceRoot: firstCatalog,
                    supportSeoUri: false,
                    contentLoader: contentLoader,
                    routingSegmentLoader: routingSegmentLoader,
                    contentVersionRepository: contentVersionRepo,
                    urlSegmentRouter: urlSegmentRouter,
                    contentLanguageSettingsHandler: contentLanguageSettingsHandler);

                var partialRouter2 = new HierarchicalCatalogPartialRouter(
                    () => SiteDefinition.Current.StartPage, firstCatalog, false);

                if (firstCatalog != null)
                {

                    routes.RegisterPartialRouter(partialRouter2);
                }
            }
        }