public ActionResult Sitemap() { if (!_commonSettings.SitemapEnabled) { return(RedirectToRoute("HomePage")); } var model = new SitemapModel(); if (_commonSettings.SitemapIncludeCategories) { var categories = _categoryService.GetAllCategories(); model.Categories = categories.Select(x => x.ToModel()).ToList(); } if (_commonSettings.SitemapIncludeManufacturers) { var manufacturers = _manufacturerService.GetAllManufacturers(); model.Manufacturers = manufacturers.Select(x => x.ToModel()).ToList(); } if (_commonSettings.SitemapIncludeProducts) { //limit product to 200 until paging is supported on this page IList <int> filterableSpecificationAttributeOptionIds = null; var productSearchContext = new ProductSearchContext(); productSearchContext.OrderBy = ProductSortingEnum.Position; productSearchContext.PageSize = 200; productSearchContext.FilterableSpecificationAttributeOptionIds = filterableSpecificationAttributeOptionIds; productSearchContext.StoreId = _storeContext.CurrentStoreIdIfMultiStoreMode; productSearchContext.VisibleIndividuallyOnly = true; var products = _productService.SearchProducts(productSearchContext); model.Products = products.Select(product => new ProductOverviewModel() { Id = product.Id, Name = product.GetLocalized(x => x.Name).EmptyNull(), ShortDescription = product.GetLocalized(x => x.ShortDescription), FullDescription = product.GetLocalized(x => x.FullDescription), SeName = product.GetSeName(), }).ToList(); } if (_commonSettings.SitemapIncludeTopics) { var topics = _topicService.GetAllTopics(_storeContext.CurrentStore.Id) .ToList() .FindAll(t => t.IncludeInSitemap); model.Topics = topics.Select(topic => new TopicModel() { Id = topic.Id, SystemName = topic.SystemName, IncludeInSitemap = topic.IncludeInSitemap, IsPasswordProtected = topic.IsPasswordProtected, Title = topic.GetLocalized(x => x.Title), }) .ToList(); } return(View(model)); }
public ActionResult Sitemap() { if (!_commonSettings.Value.SitemapEnabled) { return(HttpNotFound()); } var roleIds = _services.WorkContext.CurrentUser.UserRoles.Where(x => x.Active).Select(x => x.Id).ToList(); string cacheKey = ModelCacheEventConsumer.SITEMAP_PAGE_MODEL_KEY.FormatInvariant(_services.WorkContext.WorkingLanguage.Id, string.Join(",", roleIds), _services.SiteContext.CurrentSite.Id); var result = _services.Cache.Get(cacheKey, () => { var model = new SitemapModel(); if (_commonSettings.Value.SitemapIncludeCategories) { var categories = _articleCategoryService.Value.GetAllCategories(); model.ArticleCategories = categories.Select(x => x.ToModel()).ToList(); } if (_commonSettings.Value.SitemapIncludeProducts) { //limit articel to 200 until paging is supported on this page var articleSearchContext = new ArticleSearchContext(); articleSearchContext.OrderBy = ArticleSortingEnum.Position; articleSearchContext.PageSize = 200; articleSearchContext.SiteId = _services.SiteContext.CurrentSiteIdIfMultiSiteMode; articleSearchContext.VisibleIndividuallyOnly = true; var articels = _articleService.Value.SearchArticles(articleSearchContext); model.Articles = articels.Select(articel => new ArticlePostModel() { Id = articel.Id, Title = articel.GetLocalized(x => x.Title).EmptyNull(), ShortContent = articel.GetLocalized(x => x.ShortContent), FullContent = articel.GetLocalized(x => x.FullContent), SeName = articel.GetSeName(), }).ToList(); } if (_commonSettings.Value.SitemapIncludeTopics) { var topics = _topicService.Value.GetAllTopics(_services.SiteContext.CurrentSite.Id) .ToList() .FindAll(t => t.IncludeInSitemap); model.Topics = topics.Select(topic => new TopicModel() { Id = topic.Id, SystemName = topic.SystemName, IncludeInSitemap = topic.IncludeInSitemap, IsPasswordProtected = topic.IsPasswordProtected, Title = topic.GetLocalized(x => x.Title), }) .ToList(); } return(model); }); return(View(result)); }
//sitemap page public ActionResult Sitemap() { if (!_commonSettings.SitemapEnabled) { return(RedirectToAction("Index", "Home")); } var model = new SitemapModel(); if (_commonSettings.SitemapIncludeCategories) { var categories = _categoryService.GetAllCategories(); model.Categories = categories.Select(x => x.ToModel()).ToList(); } if (_commonSettings.SitemapIncludeManufacturers) { var manufacturers = _manufacturerService.GetAllManufacturers(); model.Manufacturers = manufacturers.Select(x => x.ToModel()).ToList(); } if (_commonSettings.SitemapIncludeProducts) { //limit product to 200 until paging is supported on this page var products = _productService.SearchProducts(0, 0, null, null, null, 0, null, false, 0, null, ProductSortingEnum.Position, 0, 200); model.Products = products.Select(x => x.ToModel()).ToList(); } if (_commonSettings.SitemapIncludeTopics) { var topics = _topicService.GetAllTopics().ToList().FindAll(t => t.IncludeInSitemap); model.Topics = topics.Select(x => x.ToModel()).ToList(); } return(View(model)); }
public async Task <ActionResult> Sitemap(int page) { // Get projects List <DomainProject> projectsPage = await _projectService.GetSitemapPageAsync(page); // Build sitemap var sitemap = new SitemapModel(); foreach (DomainProject project in projectsPage) { sitemap.Urls.Add(new SitemapItem { Location = _projectUriProvider.GetUri(project.Id), ChangeFrequency = SitemapUrlChangeFrequency.Monthly, LastModified = project.Modified }); } // Serialize var serializer = new XmlSerializer(typeof(SitemapModel)); var xmlns = new XmlSerializerNamespaces(); xmlns.Add("", "http://www.sitemaps.org/schemas/sitemap/0.9"); var xmlStream = new MemoryStream(); serializer.Serialize(xmlStream, sitemap, xmlns); xmlStream.Seek(0, SeekOrigin.Begin); return(File(xmlStream, "text/xml")); }
public virtual ActionResult Index() { var list = _productService.GetLstItems(); SitemapModel model = new SitemapModel(); if (list.Count() > 0) { model.Add(new Location { Url = Request.Url.GetLeftPart(UriPartial.Authority), Priority = Priority.priority_10, LastModified = list[0].ModifiedDate.ToString("yyyy/MM/dd"), ChangeFrequency = eChangeFrequency.weekly }); foreach (var item in list) { model.Add(new Location { ChangeFrequency = item.ChangeFrequency, LastModified = item.ModifiedDate.ToString("yyyy/MM/dd"), Priority = (double)item.Priority, Url = string.Format("{0}/product/detailsproduct/{1}/{2}", Request.Url.GetLeftPart(UriPartial.Authority), item.Product_Id, item.Product_Name.Replace(' ', '-')) }); } } return(new XmlResult(model)); }
private SitemapModel BuildPageTreeItem(Site site) { var model = new SitemapModel(); model.SiteId = site.ContentId; model.SiteName = site.Name; model.IsFrontendSite = site.IsFrontendSite; var draftSitemap = SitemapBuilder.BuildSitemap(site, ContentEnvironment.Draft, SitemapBuilderFilters.All); foreach (var childNode in draftSitemap.ChildNodes) { model.ChildNodes.Add(CreateSiteMapNode(childNode, 0)); } var liveSitemap = SitemapBuilder.BuildSitemap(site, ContentEnvironment.Live, SitemapBuilderFilters.All); var flatItems = model.GetAllDescendents <SitemapModelNode>(); foreach (var item in flatItems) { var liveNode = liveSitemap.GetSitemapNode(item.PageId); item.IsPublished = liveNode != null; item.IsHomePage = item.PageId == site.HomepageId; } return(model); }
public ActionResult Sitemap() { if (!_commonSettings.SitemapEnabled) { return(RedirectToAction("Index", "Home")); } var model = new SitemapModel(); if (_commonSettings.SitemapIncludeCategories) { var categories = _categoryService.GetAllCategories(); model.Categories = categories.Select(x => x.ToModel()).ToList(); } if (_commonSettings.SitemapIncludePublishers) { var publishers = _publisherService.GetAllPublishers(); model.Publishers = publishers.Select(x => x.ToModel()).ToList(); } if (_commonSettings.SitemapIncludeProducts) { var products = _productService.SearchProducts(0, 0, null, null, null, 0, null, false, 0, null, ProductSortingMode.Position, 0, 200); model.Products = products.Select(x => x.ToModel()).ToList(); } if (_commonSettings.SitemapIncludeTopics) { var topics = _topicService.GetAllTopics().ToList().FindAll(t => t.IncludeInSitemap); model.Topics = topics.Select(x => x.ToModel()).ToList(); } return(View(model)); }
public virtual SitemapModel PrepareSitemapModel() { string cacheKey = string.Format(ModelCacheEventConsumer.SITEMAP_PAGE_MODEL_KEY, _workContext.WorkingLanguage.Id, string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()), _storeContext.CurrentStore.Id); var cachedModel = _cacheManager.Get(cacheKey, () => { var model = new SitemapModel { BlogEnabled = _blogSettings.Enabled, ForumEnabled = _forumSettings.ForumsEnabled, NewsEnabled = _newsSettings.Enabled, }; //categories if (_commonSettings.SitemapIncludeCategories) { var categories = _categoryService.GetAllCategories(storeId: _storeContext.CurrentStore.Id); model.Categories = categories.Select(category => new CategorySimpleModel { Id = category.Id, Name = category.GetLocalized(x => x.Name), SeName = category.GetSeName(), }).ToList(); } //products if (_commonSettings.SitemapIncludeProducts) { //limit product to 200 until paging is supported on this page var products = _productService.SearchProducts(storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true, pageSize: 200); model.Products = products.Select(product => new ProductOverviewModel { Id = product.Id, Name = product.GetLocalized(x => x.Name), ShortDescription = product.GetLocalized(x => x.ShortDescription), FullDescription = product.GetLocalized(x => x.FullDescription), SeName = product.GetSeName(), }).ToList(); } //topics var topics = _topicService.GetAllTopics(_storeContext.CurrentStore.Id) .Where(t => t.IncludeInSitemap) .ToList(); model.Topics = topics.Select(topic => new TopicModel { Id = topic.Id, SystemName = topic.SystemName, IncludeInSitemap = topic.IncludeInSitemap, IsPasswordProtected = topic.IsPasswordProtected, Title = topic.GetLocalized(x => x.Title), }) .ToList(); return(model); }); return(cachedModel); }
public void Serialize_SitemapModel() { SitemapModel sitemap = new SitemapModel(new List<SitemapNode> { new SitemapNode("abc"), new SitemapNode("def") }); string result = _serializer.Serialize(sitemap); result.Should().BeXmlEquivalent("Samples/sitemap.xml"); }
public ActionResult Sitemap() { if (!_commonSettings.SitemapEnabled) { return(RedirectToRoute("HomePage")); } var customerRolesIds = _workContext.CurrentCustomer.CustomerRoles .Where(cr => cr.Active).Select(cr => cr.Id).ToList(); string cacheKey = string.Format(ModelCacheEventConsumer.SITEMAP_PAGE_MODEL_KEY, _workContext.WorkingLanguage.Id, string.Join(",", customerRolesIds), _storeContext.CurrentStore.Id); var cachedModel = _cacheManager.Get(cacheKey, () => { var model = new SitemapModel(); if (_commonSettings.SitemapIncludeCategories) { var categories = _categoryService.GetAllCategories(); model.Categories = categories.Select(x => x.ToModel()).ToList(); } if (_commonSettings.SitemapIncludeManufacturers) { var manufacturers = _manufacturerService.GetAllManufacturers(); model.Manufacturers = manufacturers.Select(x => x.ToModel()).ToList(); } if (_commonSettings.SitemapIncludeProducts) { //limit product to 200 until paging is supported on this page var products = _productService.SearchProducts(storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true, pageSize: 200); model.Products = products.Select(product => new ProductOverviewModel() { Id = product.Id, Name = product.GetLocalized(x => x.Name), ShortDescription = product.GetLocalized(x => x.ShortDescription), FullDescription = product.GetLocalized(x => x.FullDescription), SeName = product.GetSeName(), }).ToList(); } if (_commonSettings.SitemapIncludeTopics) { var topics = _topicService.GetAllTopics(_storeContext.CurrentStore.Id) .ToList() .FindAll(t => t.IncludeInSitemap); model.Topics = topics.Select(topic => new TopicModel() { Id = topic.Id, SystemName = topic.SystemName, IncludeInSitemap = topic.IncludeInSitemap, IsPasswordProtected = topic.IsPasswordProtected, Title = topic.GetLocalized(x => x.Title), }) .ToList(); } return(model); }); return(View(cachedModel)); }
public void CreateSitemap_CreatesSitemapXmlResult() { List<SitemapNode> sitemapNodes = new List<SitemapNode> { new SitemapNode("/relative") }; SitemapModel sitemapModel = new SitemapModel(sitemapNodes); var result = sitemapProvider.CreateSitemap(sitemapModel); result.Should().BeOfType<XmlResult<SitemapModel>>(); }
/// <summary> /// Prepare the sitemap model /// </summary> /// <param name="pageModel">Sitemap page model</param> /// <returns>Sitemap model</returns> public virtual SitemapModel PrepareSitemapModel(SitemapPageModel pageModel) { var cacheKey = string.Format(ModelCacheEventConsumer.SITEMAP_PAGE_MODEL_KEY, _workContext.WorkingLanguage.Id, string.Join(",", _workContext.CurrentUser.GetUserRoleIds())); var cachedModel = _cacheManager.Get(cacheKey, () => { //get URL helper var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext); var model = new SitemapModel(); //prepare common items var commonGroupTitle = _localizationService.GetResource("Sitemap.General"); //home page model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetResource("HomePage"), Url = urlHelper.RouteUrl("HomePage") }); //contact us model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetResource("ContactUs"), Url = urlHelper.RouteUrl("ContactUs") }); //user info model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetResource("Account.MyAccount"), Url = urlHelper.RouteUrl("UserInfo") }); return(model); }); //prepare model with pagination pageModel.PageSize = Math.Max(pageModel.PageSize, _commonSettings.SitemapPageSize); pageModel.PageNumber = Math.Max(pageModel.PageNumber, 1); var pagedItems = new PagedList <SitemapModel.SitemapItemModel>(cachedModel.Items, pageModel.PageNumber - 1, pageModel.PageSize); var sitemapModel = new SitemapModel { Items = pagedItems }; sitemapModel.PageModel.LoadPagedList(pagedItems); return(sitemapModel); }
public void Serialize_SitemapModel() { SitemapModel sitemap = new SitemapModel(new List <SitemapNode> { new SitemapNode("abc"), new SitemapNode("def") }); string result = serializer.Serialize(sitemap); result.Should().BeXmlEquivalent("sitemap.xml"); }
public void CreateSitemap_CreatesSitemapXmlResult() { List <SitemapNode> sitemapNodes = new List <SitemapNode> { new SitemapNode("/relative") }; SitemapModel sitemapModel = new SitemapModel(sitemapNodes); var result = sitemapProvider.CreateSitemap(sitemapModel); result.Should().BeOfType <XmlResult <SitemapModel> >(); }
private static string CreateUrlElement(SitemapModel sitemapItem) { var lastMod = string.Empty; if (sitemapItem.LastModified != DateTime.MaxValue && sitemapItem.LastModified != DateTime.MinValue) { lastMod = $"<lastmod>{sitemapItem.LastModified:yyyy-MM-dd}</lastmod>"; } return($"<url><loc>{sitemapItem.Url}</loc>{lastMod}</url>"); }
public ActionResult Sitemap() { if (!_commonSettings.SitemapEnabled) { return(RedirectToRoute("HomePage")); } var model = new SitemapModel(); if (_commonSettings.SitemapIncludeCategories) { var categories = _categoryService.GetAllCategories(); model.Categories = categories.Select(x => x.ToModel()).ToList(); } if (_commonSettings.SitemapIncludeManufacturers) { var manufacturers = _manufacturerService.GetAllManufacturers(); model.Manufacturers = manufacturers.Select(x => x.ToModel()).ToList(); } if (_commonSettings.SitemapIncludeProducts) { //limit product to 200 until paging is supported on this page var products = _productService.SearchProducts(storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true, pageSize: 200); model.Products = products.Select(product => new ProductOverviewModel() { Id = product.Id, Name = product.GetLocalized(x => x.Name), ShortDescription = product.GetLocalized(x => x.ShortDescription), FullDescription = product.GetLocalized(x => x.FullDescription), SeName = product.GetSeName(), }).ToList(); } if (_commonSettings.SitemapIncludeTopics) { var topics = _topicService.GetAllTopics(_storeContext.CurrentStore.Id) .ToList() .FindAll(t => t.IncludeInSitemap); model.Topics = topics.Select(topic => new TopicModel() { Id = topic.Id, SystemName = topic.SystemName, IncludeInSitemap = topic.IncludeInSitemap, IsPasswordProtected = topic.IsPasswordProtected, Title = topic.GetLocalized(x => x.Title), }) .ToList(); } return(View(model)); }
public ActionResult Sitemap() { if (!_commonSettings.SitemapEnabled) { return(RedirectToRoute("HomePage")); } var model = new SitemapModel(); if (_commonSettings.SitemapIncludeCategories) { var categories = _categoryService.GetAllCategories(); model.Categories = categories.Select(x => x.ToModel()).ToList(); } if (_commonSettings.SitemapIncludeManufacturers) { var manufacturers = _manufacturerService.GetAllManufacturers(); model.Manufacturers = manufacturers.Select(x => x.ToModel()).ToList(); } if (_commonSettings.SitemapIncludeProducts) { //limit product to 200 until paging is supported on this page IList <int> filterableSpecificationAttributeOptionIds = null; var products = _productService.SearchProducts(0, 0, null, null, null, 0, null, false, false, 0, null, ProductSortingEnum.Position, 0, 200, false, out filterableSpecificationAttributeOptionIds); model.Products = products.Select(product => new ProductOverviewModel() { Id = product.Id, Name = product.GetLocalized(x => x.Name), ShortDescription = product.GetLocalized(x => x.ShortDescription), FullDescription = product.GetLocalized(x => x.FullDescription), SeName = product.GetSeName(), }).ToList(); } if (_commonSettings.SitemapIncludeTopics) { var topics = _topicService.GetAllTopics().ToList().FindAll(t => t.IncludeInSitemap); model.Topics = topics.Select(topic => new TopicModel() { Id = topic.Id, SystemName = topic.SystemName, IncludeInSitemap = topic.IncludeInSitemap, IsPasswordProtected = topic.IsPasswordProtected, Title = topic.GetLocalized(x => x.Title), }) .ToList(); } return(View(model)); }
/// <summary> /// Prepare the sitemap model /// </summary> /// <returns>Sitemap model</returns> public virtual SitemapModel PrepareSitemapModel() { var cacheKey = string.Format(ModelCacheEventConsumer.SITEMAP_PAGE_MODEL_KEY, _workContext.WorkingLanguage.Id, string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds())); var cachedModel = _cacheManager.Get(cacheKey, () => { var model = new SitemapModel { }; return(model); }); return(cachedModel); }
public ActionResult Sitemap() { if (!_commonSettings.SitemapEnabled) { return(RedirectToRoute("HomePage")); } var model = new SitemapModel(); if (_commonSettings.SitemapIncludeCategories) { var categories = _categoryService.GetAllCategoriesByParentCategoryId(0); foreach (var category in categories) { ((List <SmCategoryModel>)model.Categories).AddRange(PrepareCategoriesList(category)); } } return(View(model)); }
public ActionResult Sitemap() { if (!_commonSettings.SitemapEnabled) { return(RedirectToRoute("HomePage")); } string cacheKey = string.Format(ModelCacheEventConsumer.SITEMAP_PAGE_MODEL_KEY, _workContext.WorkingLanguage.Id, string.Join(",", _workContext.CurrentUser.GetUserRoleIds())); var cachedModel = _cacheManager.Get(cacheKey, () => { var model = new SitemapModel { }; return(model); }); return(View(cachedModel)); }
public async Task <IActionResult> SitemapXmlAsync([FromServices] IPageService pageService, [FromServices] IPageLinkGenerator pageLinkGenerator) { if (pageService == null) { throw new ArgumentNullException(nameof(pageService)); } if (pageLinkGenerator == null) { throw new ArgumentNullException(nameof(pageLinkGenerator)); } var request = Request; var dateNow = DateTime.Now.ToString("s"); var model = new SitemapModel { Urls = new List <SitemapUrl>() }; var pages = await pageService.GetPublishedPagesAsync(HttpContext.RequestAborted); foreach (var page in pages) { var url = await pageLinkGenerator.GetUriAsync(page); model.Urls.Add(new SitemapUrl { Location = url, LastMod = dateNow, ChangeFreq = "daily", Priority = "1" }); } model.Urls = model.Urls.OrderBy(it => it.Location).ToList(); model.Urls[0].ChangeFreq = "daily"; model.Urls[0].Priority = "1"; return(new XmlResult(model)); }
public virtual ActionResult Sitemap() { var model = new SitemapModel(new[] { MapHelpers.Map(Url, MVC.Product.List(null, null, null, null, null)) }); var categories = _categoryRepository.GetAll(); var products = _productRepository.GetAll(); foreach (var sitemap in categories.ToList().Select(c => MapHelpers.Map(Url, c))) { model.Add(sitemap); } foreach (var sitemap in products.ToList().Select(p => MapHelpers.Map(Url, p))) { model.Add(sitemap); } model.Add(MapHelpers.Map(Url, MVC.Home.Sitemap())); return(Sitemap(model)); }
public SitemapResult(SitemapModel model) { _model = model; }
public XmlResult(SitemapModel model) { this.model = model; }
public ActionResult Sitemap() { if (!_commonSettings.SitemapEnabled) return RedirectToRoute("HomePage"); var customerRolesIds = _workContext.CurrentCustomer.CustomerRoles .Where(cr => cr.Active).Select(cr => cr.Id).ToList(); string cacheKey = string.Format(ModelCacheEventConsumer.SITEMAP_PAGE_MODEL_KEY, _workContext.WorkingLanguage.Id, string.Join(",", customerRolesIds), _storeContext.CurrentStore.Id); var cachedModel = _cacheManager.Get(cacheKey, () => { var model = new SitemapModel { BlogEnabled = _blogSettings.Enabled, ForumEnabled = _forumSettings.ForumsEnabled, NewsEnabled = _newsSettings.Enabled, }; //categories if (_commonSettings.SitemapIncludeCategories) { var categories = _categoryService.GetAllCategories(); model.Categories = categories.Select(x => x.ToModel()).ToList(); } //manufacturers if (_commonSettings.SitemapIncludeManufacturers) { var manufacturers = _manufacturerService.GetAllManufacturers(); model.Manufacturers = manufacturers.Select(x => x.ToModel()).ToList(); } //products if (_commonSettings.SitemapIncludeProducts) { //limit product to 200 until paging is supported on this page var products = _productService.SearchProducts(storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true, pageSize: 200); model.Products = products.Select(product => new ProductOverviewModel { Id = product.Id, Name = product.GetLocalized(x => x.Name), ShortDescription = product.GetLocalized(x => x.ShortDescription), FullDescription = product.GetLocalized(x => x.FullDescription), SeName = product.GetSeName(), }).ToList(); } //topics var topics = _topicService.GetAllTopics(_storeContext.CurrentStore.Id) .Where(t => t.IncludeInSitemap) .ToList(); model.Topics = topics.Select(topic => new TopicModel { Id = topic.Id, SystemName = topic.SystemName, IncludeInSitemap = topic.IncludeInSitemap, IsPasswordProtected = topic.IsPasswordProtected, Title = topic.GetLocalized(x => x.Title), }) .ToList(); return model; }); return View(cachedModel); }
/// <summary> /// Prepare the sitemap model /// </summary> /// <param name="pageModel">Sitemap page model</param> /// <returns>Sitemap model</returns> public virtual async Task <SitemapModel> PrepareSitemapModelAsync(SitemapPageModel pageModel) { if (pageModel == null) { throw new ArgumentNullException(nameof(pageModel)); } var cacheKey = _staticCacheManager.PrepareKeyForDefaultCache(NopModelCacheDefaults.SitemapPageModelKey, await _workContext.GetWorkingLanguageAsync(), _customerService.GetCustomerRoleIdsAsync(await _workContext.GetCurrentCustomerAsync()), await _storeContext.GetCurrentStoreAsync()); var cachedModel = await _staticCacheManager.GetAsync(cacheKey, async() => { //get URL helper var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext); var model = new SitemapModel(); //prepare common items var commonGroupTitle = await _localizationService.GetResourceAsync("Sitemap.General"); //home page model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = await _localizationService.GetResourceAsync("Homepage"), Url = urlHelper.RouteUrl("Homepage") }); //search model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = await _localizationService.GetResourceAsync("Search"), Url = urlHelper.RouteUrl("ProductSearch") }); //news if (_newsSettings.Enabled) { model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = await _localizationService.GetResourceAsync("News"), Url = urlHelper.RouteUrl("NewsArchive") }); } //blog if (_blogSettings.Enabled) { model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = await _localizationService.GetResourceAsync("Blog"), Url = urlHelper.RouteUrl("Blog") }); } //forums if (_forumSettings.ForumsEnabled) { model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = await _localizationService.GetResourceAsync("Forum.Forums"), Url = urlHelper.RouteUrl("Boards") }); } //contact us model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = await _localizationService.GetResourceAsync("ContactUs"), Url = urlHelper.RouteUrl("ContactUs") }); //customer info model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = await _localizationService.GetResourceAsync("Account.MyAccount"), Url = urlHelper.RouteUrl("CustomerInfo") }); //at the moment topics are in general category too if (_sitemapSettings.SitemapIncludeTopics) { var topics = (await _topicService.GetAllTopicsAsync(storeId: (await _storeContext.GetCurrentStoreAsync()).Id)) .Where(topic => topic.IncludeInSitemap); model.Items.AddRange(await topics.SelectAwait(async topic => new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = await _localizationService.GetLocalizedAsync(topic, x => x.Title), Url = urlHelper.RouteUrl("Topic", new { SeName = await _urlRecordService.GetSeNameAsync(topic) }) }).ToListAsync()); } //blog posts if (_sitemapSettings.SitemapIncludeBlogPosts && _blogSettings.Enabled) { var blogPostsGroupTitle = await _localizationService.GetResourceAsync("Sitemap.BlogPosts"); var blogPosts = (await _blogService.GetAllBlogPostsAsync(storeId: (await _storeContext.GetCurrentStoreAsync()).Id)) .Where(p => p.IncludeInSitemap); model.Items.AddRange(await blogPosts.SelectAwait(async post => new SitemapModel.SitemapItemModel { GroupTitle = blogPostsGroupTitle, Name = post.Title, Url = urlHelper.RouteUrl("BlogPost", new { SeName = await _urlRecordService.GetSeNameAsync(post, post.LanguageId, ensureTwoPublishedLanguages: false) }) }).ToListAsync()); } //news if (_sitemapSettings.SitemapIncludeNews && _newsSettings.Enabled) { var newsGroupTitle = await _localizationService.GetResourceAsync("Sitemap.News"); var news = await _newsService.GetAllNewsAsync(storeId: (await _storeContext.GetCurrentStoreAsync()).Id); model.Items.AddRange(await news.SelectAwait(async newsItem => new SitemapModel.SitemapItemModel { GroupTitle = newsGroupTitle, Name = newsItem.Title, Url = urlHelper.RouteUrl("NewsItem", new { SeName = await _urlRecordService.GetSeNameAsync(newsItem, newsItem.LanguageId, ensureTwoPublishedLanguages: false) }) }).ToListAsync()); } //categories if (_sitemapSettings.SitemapIncludeCategories) { var categoriesGroupTitle = await _localizationService.GetResourceAsync("Sitemap.Categories"); var categories = await _categoryService.GetAllCategoriesAsync(storeId: (await _storeContext.GetCurrentStoreAsync()).Id); model.Items.AddRange(await categories.SelectAwait(async category => new SitemapModel.SitemapItemModel { GroupTitle = categoriesGroupTitle, Name = await _localizationService.GetLocalizedAsync(category, x => x.Name), Url = urlHelper.RouteUrl("Category", new { SeName = await _urlRecordService.GetSeNameAsync(category) }) }).ToListAsync()); } //manufacturers if (_sitemapSettings.SitemapIncludeManufacturers) { var manufacturersGroupTitle = await _localizationService.GetResourceAsync("Sitemap.Manufacturers"); var manufacturers = await _manufacturerService.GetAllManufacturersAsync(storeId: (await _storeContext.GetCurrentStoreAsync()).Id); model.Items.AddRange(await manufacturers.SelectAwait(async manufacturer => new SitemapModel.SitemapItemModel { GroupTitle = manufacturersGroupTitle, Name = await _localizationService.GetLocalizedAsync(manufacturer, x => x.Name), Url = urlHelper.RouteUrl("Manufacturer", new { SeName = await _urlRecordService.GetSeNameAsync(manufacturer) }) }).ToListAsync()); } //products if (_sitemapSettings.SitemapIncludeProducts) { var productsGroupTitle = await _localizationService.GetResourceAsync("Sitemap.Products"); var products = await _productService.SearchProductsAsync(0, storeId: (await _storeContext.GetCurrentStoreAsync()).Id, visibleIndividuallyOnly: true); model.Items.AddRange(await products.SelectAwait(async product => new SitemapModel.SitemapItemModel { GroupTitle = productsGroupTitle, Name = await _localizationService.GetLocalizedAsync(product, x => x.Name), Url = urlHelper.RouteUrl("Product", new { SeName = await _urlRecordService.GetSeNameAsync(product) }) }).ToListAsync()); } //product tags if (_sitemapSettings.SitemapIncludeProductTags) { var productTagsGroupTitle = await _localizationService.GetResourceAsync("Sitemap.ProductTags"); var productTags = await _productTagService.GetAllProductTagsAsync(); model.Items.AddRange(await productTags.SelectAwait(async productTag => new SitemapModel.SitemapItemModel { GroupTitle = productTagsGroupTitle, Name = await _localizationService.GetLocalizedAsync(productTag, x => x.Name), Url = urlHelper.RouteUrl("ProductsByTag", new { SeName = await _urlRecordService.GetSeNameAsync(productTag) }) }).ToListAsync()); } return(model); }); //prepare model with pagination pageModel.PageSize = Math.Max(pageModel.PageSize, _sitemapSettings.SitemapPageSize); pageModel.PageNumber = Math.Max(pageModel.PageNumber, 1); var pagedItems = new PagedList <SitemapModel.SitemapItemModel>(cachedModel.Items, pageModel.PageNumber - 1, pageModel.PageSize); var sitemapModel = new SitemapModel { Items = pagedItems }; sitemapModel.PageModel.LoadPagedList(pagedItems); return(sitemapModel); }
/// <summary> /// Prepare the sitemap model /// </summary> /// <param name="pageModel">Sitemap page model</param> /// <returns>Sitemap model</returns> public virtual SitemapModel PrepareSitemapModel(SitemapPageModel pageModel) { var cacheKey = string.Format(ModelCacheEventConsumer.SITEMAP_PAGE_MODEL_KEY, _workContext.WorkingLanguage.Id, string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()), _storeContext.CurrentStore.Id); var cachedModel = _cacheManager.Get(cacheKey, () => { //get URL helper var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext); var model = new SitemapModel(); //prepare common items var commonGroupTitle = _localizationService.GetResource("Sitemap.General"); //home page model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetResource("HomePage"), Url = urlHelper.RouteUrl("HomePage") }); //search model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetResource("Search"), Url = urlHelper.RouteUrl("ProductSearch") }); //news if (_newsSettings.Enabled) { model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetResource("News"), Url = urlHelper.RouteUrl("NewsArchive") }); } //blog if (_blogSettings.Enabled) { model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetResource("Blog"), Url = urlHelper.RouteUrl("Blog") }); } //forums if (_forumSettings.ForumsEnabled) { model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetResource("Forum.Forums"), Url = urlHelper.RouteUrl("Boards") }); } //contact us model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetResource("ContactUs"), Url = urlHelper.RouteUrl("ContactUs") }); //customer info model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetResource("Account.MyAccount"), Url = urlHelper.RouteUrl("CustomerInfo") }); //at the moment topics are in general category too var topics = _topicService.GetAllTopics(_storeContext.CurrentStore.Id).Where(topic => topic.IncludeInSitemap); model.Items.AddRange(topics.Select(topic => new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetLocalized(topic, x => x.Title), Url = urlHelper.RouteUrl("Topic", new { SeName = _urlRecordService.GetSeName(topic) }) })); //categories if (_commonSettings.SitemapIncludeCategories) { var categoriesGroupTitle = _localizationService.GetResource("Sitemap.Categories"); var categories = _categoryService.GetAllCategories(storeId: _storeContext.CurrentStore.Id); model.Items.AddRange(categories.Select(category => new SitemapModel.SitemapItemModel { GroupTitle = categoriesGroupTitle, Name = _localizationService.GetLocalized(category, x => x.Name), Url = urlHelper.RouteUrl("Category", new { SeName = _urlRecordService.GetSeName(category) }) })); } //manufacturers if (_commonSettings.SitemapIncludeManufacturers) { var manufacturersGroupTitle = _localizationService.GetResource("Sitemap.Manufacturers"); var manufacturers = _manufacturerService.GetAllManufacturers(storeId: _storeContext.CurrentStore.Id); model.Items.AddRange(manufacturers.Select(manufacturer => new SitemapModel.SitemapItemModel { GroupTitle = manufacturersGroupTitle, Name = _localizationService.GetLocalized(manufacturer, x => x.Name), Url = urlHelper.RouteUrl("Manufacturer", new { SeName = _urlRecordService.GetSeName(manufacturer) }) })); } //products if (_commonSettings.SitemapIncludeProducts) { var productsGroupTitle = _localizationService.GetResource("Sitemap.Products"); var products = _productService.SearchProducts(storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true); model.Items.AddRange(products.Select(product => new SitemapModel.SitemapItemModel { GroupTitle = productsGroupTitle, Name = _localizationService.GetLocalized(product, x => x.Name), Url = urlHelper.RouteUrl("Product", new { SeName = _urlRecordService.GetSeName(product) }) })); } //product tags if (_commonSettings.SitemapIncludeProductTags) { var productTagsGroupTitle = _localizationService.GetResource("Sitemap.ProductTags"); var productTags = _productTagService.GetAllProductTags(); model.Items.AddRange(productTags.Select(productTag => new SitemapModel.SitemapItemModel { GroupTitle = productTagsGroupTitle, Name = _localizationService.GetLocalized(productTag, x => x.Name), Url = urlHelper.RouteUrl("ProductsByTag", new { SeName = _urlRecordService.GetSeName(productTag) }) })); } return(model); }); //prepare model with pagination pageModel.PageSize = Math.Max(pageModel.PageSize, _commonSettings.SitemapPageSize); pageModel.PageNumber = Math.Max(pageModel.PageNumber, 1); var pagedItems = new PagedList <SitemapModel.SitemapItemModel>(cachedModel.Items, pageModel.PageNumber - 1, pageModel.PageSize); var sitemapModel = new SitemapModel { Items = pagedItems }; sitemapModel.PageModel.LoadPagedList(pagedItems); return(sitemapModel); }
protected virtual SitemapResult Sitemap(SitemapModel model) { return(new SitemapResult(model)); }
public ActionResult Sitemap() { if (!_commonSettings.Value.SitemapEnabled) { return(HttpNotFound()); } var roleIds = _services.WorkContext.CurrentCustomer.CustomerRoles.Where(x => x.Active).Select(x => x.Id).ToList(); string cacheKey = ModelCacheEventConsumer.SITEMAP_PAGE_MODEL_KEY.FormatInvariant(_services.WorkContext.WorkingLanguage.Id, string.Join(",", roleIds), _services.StoreContext.CurrentStore.Id); var result = _services.Cache.Get(cacheKey, () => { var model = new SitemapModel(); if (_commonSettings.Value.SitemapIncludeCategories) { var categories = _categoryService.Value.GetAllCategories(); model.Categories = categories.Select(x => x.ToModel()).ToList(); } if (_commonSettings.Value.SitemapIncludeManufacturers) { var manufacturers = _manufacturerService.Value.GetAllManufacturers(); model.Manufacturers = manufacturers.Select(x => x.ToModel()).ToList(); } if (_commonSettings.Value.SitemapIncludeProducts) { //limit product to 200 until paging is supported on this page IList <int> filterableSpecificationAttributeOptionIds = null; var productSearchContext = new ProductSearchContext(); productSearchContext.OrderBy = ProductSortingEnum.Position; productSearchContext.PageSize = 200; productSearchContext.FilterableSpecificationAttributeOptionIds = filterableSpecificationAttributeOptionIds; productSearchContext.StoreId = _services.StoreContext.CurrentStoreIdIfMultiStoreMode; productSearchContext.VisibleIndividuallyOnly = true; var products = _productService.Value.SearchProducts(productSearchContext); model.Products = products.Select(product => new ProductOverviewModel() { Id = product.Id, Name = product.GetLocalized(x => x.Name).EmptyNull(), ShortDescription = product.GetLocalized(x => x.ShortDescription), FullDescription = product.GetLocalized(x => x.FullDescription), SeName = product.GetSeName(), }).ToList(); } if (_commonSettings.Value.SitemapIncludeTopics) { var topics = _topicService.Value.GetAllTopics(_services.StoreContext.CurrentStore.Id) .ToList() .FindAll(t => t.IncludeInSitemap); model.Topics = topics.Select(topic => new TopicModel() { Id = topic.Id, SystemName = topic.SystemName, IncludeInSitemap = topic.IncludeInSitemap, IsPasswordProtected = topic.IsPasswordProtected, Title = topic.GetLocalized(x => x.Title), }) .ToList(); } return(model); }); return(View(result)); }