public ActionResult Manufacturer(int manufacturerId, CatalogSearchQuery query) { var manufacturer = _manufacturerService.GetManufacturerById(manufacturerId); if (manufacturer == null || manufacturer.Deleted) { return(HttpNotFound()); } // Check whether the current user has a "Manage catalog" permission. // It allows him to preview a manufacturer before publishing. if (!manufacturer.Published && !Services.Permissions.Authorize(Permissions.Catalog.Manufacturer.Read)) { return(HttpNotFound()); } // ACL (access control list). if (!_aclService.Authorize(manufacturer)) { return(HttpNotFound()); } // Store mapping. if (!_storeMappingService.Authorize(manufacturer)) { return(HttpNotFound()); } var store = Services.StoreContext.CurrentStore; var customer = Services.WorkContext.CurrentCustomer; // 'Continue shopping' URL. if (!customer.IsSystemAccount) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.LastContinueShoppingPage, Services.WebHelper.GetThisPageUrl(false), store.Id); } var model = manufacturer.ToModel(); if (query.IsSubPage && !_catalogSettings.ShowDescriptionInSubPages) { model.Description.ChangeValue(string.Empty); model.BottomDescription.ChangeValue(string.Empty); } model.PictureModel = _helper.PrepareManufacturerPictureModel(manufacturer, model.Name); // Featured products. var hideFeaturedProducts = _catalogSettings.IgnoreFeaturedProducts || (query.IsSubPage && !_catalogSettings.IncludeFeaturedProductsInSubPages); if (!hideFeaturedProducts) { CatalogSearchResult featuredProductsResult = null; var customerRolesIds = customer.CustomerRoleMappings .Select(x => x.CustomerRole) .Where(x => x.Active) .Select(x => x.Id) .ToList(); var cacheKey = ModelCacheEventConsumer.MANUFACTURER_HAS_FEATURED_PRODUCTS_KEY.FormatInvariant(manufacturerId, string.Join(",", customerRolesIds), store.Id); var hasFeaturedProductsCache = Services.Cache.Get <bool?>(cacheKey); var featuredProductsQuery = new CatalogSearchQuery() .VisibleOnly(customer) .WithVisibility(ProductVisibility.Full) .WithManufacturerIds(true, manufacturerId) .HasStoreId(store.Id) .WithLanguage(Services.WorkContext.WorkingLanguage) .WithCurrency(Services.WorkContext.WorkingCurrency); if (!hasFeaturedProductsCache.HasValue) { featuredProductsResult = _catalogSearchService.Search(featuredProductsQuery); hasFeaturedProductsCache = featuredProductsResult.TotalHitsCount > 0; Services.Cache.Put(cacheKey, hasFeaturedProductsCache, TimeSpan.FromHours(6)); } if (hasFeaturedProductsCache.Value && featuredProductsResult == null) { featuredProductsResult = _catalogSearchService.Search(featuredProductsQuery); } if (featuredProductsResult != null) { // TODO: (mc) determine settings properly var featuredProductsmappingSettings = _helper.GetBestFitProductSummaryMappingSettings(ProductSummaryViewMode.Grid); model.FeaturedProducts = _helper.MapProductSummaryModel(featuredProductsResult.Hits, featuredProductsmappingSettings); } } // Products query.WithManufacturerIds(_catalogSettings.IncludeFeaturedProductsInNormalLists ? null : (bool?)false, manufacturerId); var searchResult = _catalogSearchService.Search(query); model.SearchResult = searchResult; var mappingSettings = _helper.GetBestFitProductSummaryMappingSettings(query.GetViewMode()); model.Products = _helper.MapProductSummaryModel(searchResult.Hits, mappingSettings); // Prepare paging/sorting/mode stuff _helper.MapListActions(model.Products, manufacturer, _catalogSettings.DefaultPageSizeOptions); // Template var templateCacheKey = string.Format(ModelCacheEventConsumer.MANUFACTURER_TEMPLATE_MODEL_KEY, manufacturer.ManufacturerTemplateId); var templateViewPath = Services.Cache.Get(templateCacheKey, () => { var template = _manufacturerTemplateService.GetManufacturerTemplateById(manufacturer.ManufacturerTemplateId); if (template == null) { template = _manufacturerTemplateService.GetAllManufacturerTemplates().FirstOrDefault(); } return(template.ViewPath); }); //activity log Services.CustomerActivity.InsertActivity("PublicStore.ViewManufacturer", T("ActivityLog.PublicStore.ViewManufacturer"), manufacturer.Name); Services.DisplayControl.Announce(manufacturer); return(View(templateViewPath, model)); }