コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: mandocaesar/Mesinku
        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),
                        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);
        }