public ActionResult ProductTags(int productId) { var product = _productService.GetProductById(productId); if (product == null) { throw new ArgumentException(T("Products.NotFound", productId)); } var cacheKey = string.Format(ModelCacheEventConsumer.PRODUCTTAG_BY_PRODUCT_MODEL_KEY, product.Id, _services.WorkContext.WorkingLanguage.Id, _services.StoreContext.CurrentStore.Id); var cacheModel = _services.Cache.Get(cacheKey, () => { var model = product.ProductTags // Filter by store .Where(x => _productTagService.GetProductCount(x.Id, _services.StoreContext.CurrentStore.Id) > 0) .Select(x => { var ptModel = new ProductTagModel { Id = x.Id, Name = x.GetLocalized(y => y.Name), SeName = x.GetSeName(), ProductCount = _productTagService.GetProductCount(x.Id, _services.StoreContext.CurrentStore.Id) }; return(ptModel); }) .ToList(); return(model); }); return(PartialView("Product.Tags", cacheModel)); }
/// <summary> /// Prepare paged product tag list model /// </summary> /// <param name="searchModel">Product tag search model</param> /// <returns>Product tag list model</returns> public virtual ProductTagListModel PrepareProductTagListModel(ProductTagSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get product tags var productTags = _productTagService.GetAllProductTags() .OrderByDescending(tag => _productTagService.GetProductCount(tag.Id, storeId: 0)).ToList(); //prepare list model var model = new ProductTagListModel { Data = productTags.PaginationByRequestModel(searchModel).Select(tag => { //fill in model values from the entity var productTagModel = new ProductTagModel { Id = tag.Id, Name = tag.Name }; //fill in additional values (not existing in the entity) productTagModel.ProductCount = _productTagService.GetProductCount(tag.Id, storeId: 0); return(productTagModel); }), Total = productTags.Count }; return(model); }
public ActionResult PopularProductTags() { if (!_catalogSettings.ShowPopularProductTagsOnHomepage) { return(new EmptyResult()); } var store = Services.StoreContext.CurrentStore; var cacheKey = string.Format(ModelCacheEventConsumer.PRODUCTTAG_POPULAR_MODEL_KEY, Services.WorkContext.WorkingLanguage.Id, store.Id); var cacheModel = Services.Cache.Get(cacheKey, () => { var model = new PopularProductTagsModel(); var allTags = _productTagService .GetAllProductTags() .Where(x => _productTagService.GetProductCount(x.Id, store.Id) > 0) .OrderByDescending(x => _productTagService.GetProductCount(x.Id, store.Id)) .ToList(); var tags = allTags .Take(_catalogSettings.NumberOfProductTags) .ToList(); 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, store.Id) }); } return(model); }); return(PartialView(cacheModel)); }
public IActionResult List(DataSourceRequest command) { var tags = _productTagService.GetAllProductTags() //order by product count .OrderByDescending(x => _productTagService.GetProductCount(x.Id, "")) .Select(x => new ProductTagModel { Id = x.Id, Name = x.Name, ProductCount = _productTagService.GetProductCount(x.Id, "") }) .ToList(); var gridModel = new DataSourceResult { Data = tags.PagedForCommand(command), Total = tags.Count }; return(Json(gridModel)); }
public virtual PopularProductTagsModel PreparePopularProductTagsModel() { var cacheKey = string.Format(ModelCacheEventConsumer.PRODUCTTAG_POPULAR_MODEL_KEY, _workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id); var cachedModel = _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(cachedModel); }
public async Task <IActionResult> List(DataSourceRequest command) { var tags = (await _productTagService.GetAllProductTags()); var productTags = new List <ProductTagModel>(); foreach (var item in tags) { var ptag = new ProductTagModel(); ptag.Id = item.Id; ptag.Name = item.Name; ptag.ProductCount = await _productTagService.GetProductCount(item.Id, ""); productTags.Add(ptag); } var gridModel = new DataSourceResult { Data = productTags.OrderByDescending(x => x.ProductCount).PagedForCommand(command), Total = tags.Count() }; return(Json(gridModel)); }
protected virtual IList <ProductTagModel> PrepareProductTagModels(Product product) { if (product == null) { throw new ArgumentNullException("product"); } var productTagsCacheKey = string.Format(ModelCacheEventConsumer.PRODUCTTAG_BY_PRODUCT_MODEL_KEY, product.Id, _workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id); var model = _cacheManager.Get(productTagsCacheKey, () => product.ProductTags //filter by store .Where(x => _productTagService.GetProductCount(x.Id, _storeContext.CurrentStore.Id) > 0) .Select(x => new ProductTagModel { Id = x.Id, Name = x.GetLocalized(y => y.Name), SeName = x.GetSeName(), ProductCount = _productTagService.GetProductCount(x.Id, _storeContext.CurrentStore.Id) }) .ToList()); return(model); }
public async Task <PopularProductTagsModel> Handle(GetProductTagsAll request, CancellationToken cancellationToken) { var model = new PopularProductTagsModel(); var tagsTask = (await _productTagService .GetAllProductTags()) .OrderBy(x => x.Name) .Select(async x => { var ptModel = new ProductTagModel { Id = x.Id, Name = x.GetLocalized(y => y.Name, request.Language.Id), SeName = x.SeName, ProductCount = await _productTagService.GetProductCount(x.Id, request.Store.Id) }; return(ptModel); }); model.Tags = await Task.WhenAll(tagsTask); return(model); }