public ActionResult ProductTagsAll() { var model = new PopularProductTagsModel(); model.Tags = _productTagService .GetAllProductTags() //filter by current store .Where(x => _productTagService.GetProductCount(x.Id, _storeContext.CurrentStore.Id) > 0) //sort by name .OrderBy(x => x.GetLocalized(y => y.Name)) .Select(x => { var ptModel = new ProductTagModel() { Id = x.Id, Name = x.GetLocalized(y => y.Name), SeName = x.GetSeName(), ProductCount = _productTagService.GetProductCount(x.Id, _storeContext.CurrentStore.Id) }; return ptModel; }) .ToList(); return View(model); }
public ActionResult PopularProductTags() { var cacheKey = string.Format(ModelCacheEventConsumer.PRODUCTTAG_POPULAR_MODEL_KEY, _workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id); var cacheModel = _cacheManager.Get(cacheKey, () => { var model = new PopularProductTagsModel(); //get all tags var allTags = _productTagService .GetAllProductTags() //filter by current store .Where(x => _productTagService.GetProductCount(x.Id, _storeContext.CurrentStore.Id) > 0) //order by product count .OrderByDescending(x => _productTagService.GetProductCount(x.Id, _storeContext.CurrentStore.Id)) .ToList(); var tags = allTags .Take(_catalogSettings.NumberOfProductTags) .ToList(); //sorting tags = tags.OrderBy(x => x.GetLocalized(y => y.Name)).ToList(); model.TotalTags = allTags.Count; foreach (var tag in tags) model.Tags.Add(new ProductTagModel() { Id = tag.Id, Name = tag.GetLocalized(y => y.Name), SeName = tag.GetSeName(), ProductCount = _productTagService.GetProductCount(tag.Id, _storeContext.CurrentStore.Id) }); return model; }); return PartialView(cacheModel); }