public virtual ActionResult RelatedProducts(int productId, int?productThumbPictureSize) { //load and cache report var productIds = _cacheManager.Get(string.Format(ModelCacheEventConsumer.PRODUCTS_RELATED_IDS_KEY, productId, _storeContext.CurrentStore.Id), () => _productService.GetRelatedProductsByProductId1(productId).Select(x => x.ProductId2).ToArray() ); //load products var products = _productService.GetProductsByIds(productIds); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList(); //availability dates products = products.Where(p => p.IsAvailable()).ToList(); if (!products.Any()) { return(Content("")); } var model = _productModelFactory.PrepareProductOverviewModels(products, true, true, productThumbPictureSize).ToList(); return(PartialView(model)); }
public virtual IActionResult RecentlyViewedProducts() { if (!_catalogSettings.RecentlyViewedProductsEnabled) { return(Content("")); } var products = _recentlyViewedProductsService.GetRecentlyViewedProducts(_catalogSettings.DefaultCategoryPageSize); var model = _productModelFactory.PrepareProductOverviewModels(products); return(View(model)); }
public virtual IActionResult RecentlyViewedProducts() { if (!_catalogSettings.RecentlyViewedProductsEnabled) { return(Content("")); } var products = _recentlyViewedProductsService.GetRecentlyViewedProducts(_catalogSettings.RecentlyViewedProductsNumber); var model = new List <ProductOverviewModel>(); model.AddRange(_productModelFactory.PrepareProductOverviewModels(products)); return(View(model)); }
public IViewComponentResult Invoke(int warehouseId) { if (warehouseId == 0) { return(Content("")); } var products = _productService.SearchProducts( storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true, warehouseId: warehouseId, orderBy: ProductSortingEnum.CreatedOn, pageSize: 6).ToList(); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList(); //availability dates products = products.Where(p => _productService.ProductIsAvailable(p)).ToList(); if (!products.Any()) { return(Content("")); } //prepare model var model = _productModelFactory.PrepareProductOverviewModels(products, true, true, null).ToList(); ViewBag.WarehouseId = warehouseId; return(View(model)); }
public IViewComponentResult Invoke(int productId, int?productThumbPictureSize) { if (!_catalogSettings.ProductsAlsoPurchasedEnabled) { return(Content("")); } //load and cache report var productIds = _cacheManager.Get(string.Format(ModelCacheEventConsumer.PRODUCTS_ALSO_PURCHASED_IDS_KEY, productId, 0), () => _orderReportService.GetAlsoPurchasedProductsIds(0, productId, _catalogSettings.ProductsAlsoPurchasedNumber) ); //load products var products = _productService.GetProductsByIds(productIds); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList(); //availability dates products = products.Where(p => p.IsAvailable()).ToList(); if (!products.Any()) { return(Content("")); } var model = _productModelFactory.PrepareProductOverviewModels(products, true, true, productThumbPictureSize).ToList(); return(View(model)); }
public virtual IActionResult SearchTermAutoComplete(string term) { if (string.IsNullOrWhiteSpace(term) || term.Length < _catalogSettings.ProductSearchTermMinimumLength) { return(Content("")); } //products var productNumber = _catalogSettings.ProductSearchAutoCompleteNumberOfProducts > 0 ? _catalogSettings.ProductSearchAutoCompleteNumberOfProducts : 10; var products = _productService.SearchProducts( storeId: _storeContext.CurrentStore.Id, keywords: term, languageId: _workContext.WorkingLanguage.Id, visibleIndividuallyOnly: true, pageSize: productNumber); var showLinkToResultSearch = _catalogSettings.ShowLinkToAllResultInSearchAutoComplete && (products.TotalCount > productNumber); var models = _productModelFactory.PrepareProductOverviewModels(products, false, _catalogSettings.ShowProductImagesInSearchAutoComplete, _mediaSettings.AutoCompleteSearchThumbPictureSize).ToList(); var result = (from p in models select new { label = p.Name, producturl = Url.RouteUrl("Product", new { SeName = p.SeName }), productpictureurl = p.DefaultPictureModel.ImageUrl, showlinktoresultsearch = showLinkToResultSearch }) .ToList(); return(Json(result)); }
public virtual dynamic GetWarehouseProducts(int warehouseId) { if (warehouseId == 0) { return(Content("")); } IEnumerable <Product> products = _productService.SearchProducts( storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true, warehouseId: warehouseId, orderBy: ProductSortingEnum.CreatedOn); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)); //availability dates products = products.Where(p => _productService.ProductIsAvailable(p)); if (!products.Any()) { return(Content("")); } //prepare model var model = _productModelFactory.PrepareProductOverviewModels(products, true, true, 250); return(new { model }); }
public IViewComponentResult Invoke(int?productThumbPictureSize) { //load products var products = _productService.GetAllProducts(); //availability dates var numberOfProducts = _settingService.LoadSetting <HomePageNewProductsPluginSettings>().NumberOfProducts; products = products.Where(p => _productService.ProductIsAvailable(p)) .OrderByDescending(p => p.CreatedOnUtc).Take(numberOfProducts).ToList(); if (!products.Any()) { return(Content("No products found")); } //prepare model var model = new PublicInfoModel(); model.Products = products; model.ProductModels = _productModelFactory.PrepareProductOverviewModels(products).ToList(); return(View("~/Plugins/Widgets.HomePageNewProductsPlugin/Views/PublicInfo.cshtml", model)); //return View(model); }
public IViewComponentResult Invoke(int?productThumbPictureSize) { var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentCustomer, ShoppingCartType.ShoppingCart, _storeContext.CurrentStore.Id); var products = _productService.GetCrosssellProductsByShoppingCart(cart, _shoppingCartSettings.CrossSellsNumber); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList(); //availability dates products = products.Where(p => _productService.ProductIsAvailable(p)).ToList(); //visible individually products = products.Where(p => p.VisibleIndividually).ToList(); if (!products.Any()) { return(Content("")); } //Cross-sell products are displayed on the shopping cart page. //We know that the entire shopping cart page is not refresh //even if "ShoppingCartSettings.DisplayCartAfterAddingProduct" setting is enabled. //That's why we force page refresh (redirect) in this case var model = _productModelFactory.PrepareProductOverviewModels(products, preparePictureModel: false, productThumbPictureSize: productThumbPictureSize, forceRedirectionAfterAddingToCart: true) .ToList(); return(View(model)); }
public IViewComponentResult Invoke(string makeCode, string colorName, string productName, int productId = 0) { if (string.IsNullOrEmpty(makeCode)) { return(Content("")); } IEnumerable <Product> products = _productService.SearchProducts( storeId: _storeContext.CurrentStore.Id, orderBy: ProductSortingEnum.CreatedOn); Product product = products.FirstOrDefault(x => x.Id == productId); ViewBag.ProductName = productName; //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)); //availability dates products = products.Where(p => _productService.ProductIsAvailable(p) && p.MakeCode == makeCode && p.Id != productId); if (!products.Any()) { return(Content("")); } var productIds = _specificationAttributeService.GetSimilarProductIdsByColor(makeCode, colorName, product); products = products.Where(x => productIds.Contains(x.Id)); //prepare model var model = _productModelFactory.PrepareProductOverviewModels(products, true, true, 250, false); return(View(model)); }
public IViewComponentResult Invoke(int categoryId, int pageIndex) { List <int> categories = new List <int>() { categoryId }; var products = _productService.SearchProducts( storeId: _storeContext.CurrentStore.Id, categoryIds: categories, pageIndex: pageIndex, pageSize: 6).ToList(); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList(); //availability dates products = products.Where(p => _productService.ProductIsAvailable(p)).ToList(); if (!products.Any()) { return(Content("")); } //prepare model var model = _productModelFactory.PrepareProductOverviewModels(products, true, true).ToList(); return(View(model)); }
public IViewComponentResult Invoke(int productId, int?productThumbPictureSize) { //load and cache report var productIds = _cacheManager.Get(string.Format(NopModelCacheDefaults.ProductsRelatedIdsKey, productId, _storeContext.CurrentStore.Id), () => _productService.GetRelatedProductsByProductId1(productId).Select(x => x.ProductId2).ToArray()); //load products var products = _productService.GetProductsByIds(productIds); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList(); //availability dates products = products.Where(p => _productService.ProductIsAvailable(p)).ToList(); //visible individually products = products.Where(p => p.VisibleIndividually).ToList(); if (!products.Any()) { return(Content("")); } var model = _productModelFactory.PrepareProductOverviewModels(products, true, false).ToList(); return(View(model)); }
public IViewComponentResult Invoke(int?productThumbPictureSize) { IEnumerable <Product> products = _productService.SearchProducts( storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true, markedAsNewOnly: true, orderBy: ProductSortingEnum.CreatedOn, pageSize: _catalogSettings.NewProductsNumber); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)); //availability dates products = products.Where(p => _productService.ProductIsAvailable(p)); if (!products.Any()) { return(Content("")); } //prepare model var model = _productModelFactory.PrepareProductOverviewModels(products, true, true, 250); return(View(model)); }
public IViewComponentResult Invoke(string widgetZone, object additionalData) { // Loading the seting value var homePageSettings = _settingService.LoadSetting <HomePageNewProductsSettings>(_storeContext.CurrentStore.Id); int NumberOfProducts = homePageSettings.NumberOfProducts; //load and cache report var report = _cacheManager.Get(string.Format(ModelCacheEventConsumer.HOMEPAGE_BESTSELLERS_IDS_KEY, _storeContext.CurrentStore.Id), () => _orderReportService.BestSellersReport( storeId: _storeContext.CurrentStore.Id) .ToList()); //load products var products = _productService.GetProductsByIds(report.Select(x => x.ProductId).ToArray()); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList(); //Order by MarkAsNewStartDate Descending, in order to get the newest first // Then get the first NumberOfProducts Specified in the Settings // Getting the first ones guarantees that they are the Newest products = products.OrderByDescending(p => p.MarkAsNewStartDateTimeUtc).Take(NumberOfProducts).ToList(); //prepare model var model = _productModelFactory.PrepareProductOverviewModels(products, true, true).ToList(); return(View("~/Plugins/Widgets.HomePageNewProducts/Views/PublicInfo.cshtml", model)); }
public IViewComponentResult Invoke(int?productThumbPictureSize) { if (!_catalogSettings.ShowBestsellersOnHomepage || _catalogSettings.NumberOfBestsellersOnHomepage == 0) { return(Content("")); } //load and cache report var report = _cacheManager.Get(string.Format(ModelCacheEventConsumer.HOMEPAGE_BESTSELLERS_IDS_KEY, _storeContext.CurrentStore.Id), () => _orderReportService.BestSellersReport( storeId: _storeContext.CurrentStore.Id, pageSize: _catalogSettings.NumberOfBestsellersOnHomepage) .ToList()); //load products var products = _productService.GetProductsByIds(report.Select(x => x.ProductId).ToArray()); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList(); //availability dates products = products.Where(p => _productService.ProductIsAvailable(p)).ToList(); if (!products.Any()) { return(Content("")); } //prepare model var model = _productModelFactory.PrepareProductOverviewModels(products, true, true, productThumbPictureSize).ToList(); return(View(model)); }
public IViewComponentResult Invoke(int?productThumbPictureSize, bool?preparePriceModel) { if (!_catalogSettings.RecentlyViewedProductsEnabled) { return(Content("")); } var preparePictureModel = productThumbPictureSize.HasValue; var products = _recentlyViewedProductsService.GetRecentlyViewedProducts(_catalogSettings.RecentlyViewedProductsNumber); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList(); //availability dates products = products.Where(p => _productService.ProductIsAvailable(p)).ToList(); if (!products.Any()) { return(Content("")); } //prepare model var model = new List <ProductOverviewModel>(); model.AddRange(_productModelFactory.PrepareProductOverviewModels(products, preparePriceModel.GetValueOrDefault(), preparePictureModel, productThumbPictureSize)); return(View(model)); }
public IActionResult AccessoryCrossSells(int productId, int?productThumbPictureSize) { IProductService productService = EngineContext.Current.Resolve <IProductService>(); IProductModelFactory productModelFactory = EngineContext.Current.Resolve <IProductModelFactory>(); List <Product> crossSellProductList = new List <Product>(); var products = productService.GetCrossSellProductsByProductId1(productId); if (!products.Any()) { return(Content("")); } foreach (var product in products) { Product crossSellProduct = productService.GetProductById(product.ProductId2); crossSellProductList.Add(crossSellProduct); } var model = productModelFactory.PrepareProductOverviewModels(crossSellProductList, productThumbPictureSize: productThumbPictureSize, forceRedirectionAfterAddingToCart: true) .ToList(); return(PartialView("CrossSellProducts", model)); //return View(); }
public IViewComponentResult Invoke(int productId, int?productThumbPictureSize) { if (!_catalogSettings.ProductsAlsoPurchasedEnabled) { return(Content("")); } //load and cache report var productIds = _cacheManager.Get(string.Format(NopModelCacheDefaults.ProductsAlsoPurchasedIdsKey, productId, _storeContext.CurrentStore.Id), () => _orderReportService.GetAlsoPurchasedProductsIds(_storeContext.CurrentStore.Id, productId, _catalogSettings.ProductsAlsoPurchasedNumber) ); //load products var products = _productService.GetProductsByIds(productIds); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList(); //availability dates products = products.Where(p => _productService.ProductIsAvailable(p)).ToList(); if (!products.Any()) { return(Content("")); } var model = _productModelFactory.PrepareProductOverviewModels(products, true, true, productThumbPictureSize).ToList(); return(View(model)); }
public IViewComponentResult Invoke(int?productThumbPictureSize, int[] productIds = null) { IEnumerable <Product> products = new Product[] { }; List <Product> result = new List <Product>(); if (productIds == null) { var cart = _workContext.CurrentCustomer.ShoppingCartItems .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart) .LimitPerStore(_storeContext.CurrentStore.Id); products = _productService.GetCrosssellProductsByShoppingCart(cart, _shoppingCartSettings.CrossSellsNumber); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)); //availability dates products = products.Where(p => _productService.ProductIsAvailable(p)); //visible individually products = products.Where(p => p.VisibleIndividually); } else { var crosSellProducts = _productService.GetCrossSellProductsByProductIds(productIds); foreach (var crossSell in crosSellProducts) { //validate that this product is not added to result yet //validate that this product is not in the cart if (result.Find(p => p.Id == crossSell.ProductId2) != null || productIds.Contains(crossSell.ProductId2)) { continue; } var productToAdd = _productService.GetProductById(crossSell.ProductId2); //validate product if (productToAdd == null || productToAdd.Deleted || !productToAdd.Published) { continue; } //add a product to result result.Add(productToAdd); } products = result; } if (!products.Any()) { return(Content("")); } //Cross-sell products are displayed on the shopping cart page. //We know that the entire shopping cart page is not refresh //even if "ShoppingCartSettings.DisplayCartAfterAddingProduct" setting is enabled. //That's why we force page refresh (redirect) in this case var model = _productModelFactory.PrepareProductOverviewModels(products, productThumbPictureSize: productThumbPictureSize ?? 250, forceRedirectionAfterAddingToCart: false); return(View(model)); }
public virtual IActionResult NewProducts() { if (!_catalogSettings.NewProductsEnabled) { return(Content("")); } var products = _productService.SearchProducts( storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true, markedAsNewOnly: true, orderBy: ProductSortingEnum.CreatedOn, pageSize: _catalogSettings.NewProductsNumber); var model = new List <ProductOverviewModel>(); model.AddRange(_productModelFactory.PrepareProductOverviewModels(products)); return(View(model)); }
public IViewComponentResult Invoke(string widgetZone, int productThumbPictureSize) { var numberOfProductsToShow = this._settingService.GetSettingByKey <int>("HomePageNewProductsSettings.NumberOfProductsToShow"); var products = _productService.SearchProducts(orderBy: ProductSortingEnum.CreatedOn).Take(numberOfProductsToShow); var model = new List <ProductOverviewModel>(); model.AddRange(_productModelFactory.PrepareProductOverviewModels(products, true, true, productThumbPictureSize)); return(View("~/Plugins/Widgets.HomePageNewProducts/Views/PublicInfo.cshtml", model)); }
public IViewComponentResult Invoke(int?productThumbPictureSize) { var products = _productService.GetAllProductsDisplayedOnHomePage(); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList(); if (!products.Any()) { return(Content("")); } var model = _productModelFactory.PrepareProductOverviewModels(products, true, productThumbPictureSize).ToList(); return(View(model)); }
public IViewComponentResult Invoke(string widgetZone, object additionalData) { var homePageNewProductsSettings = _settingService.LoadSetting <HomePageNewProductsSettings>(_storeContext.CurrentStore.Id); var numberOfNewProductsToShow = _settingService.GetSettingByKey <int>(typeof(HomePageNewProductsSettings).Name + "." + "NumberOfProducts"); var newProducts = _productService.SearchProducts(storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true, markedAsNewOnly: true).OrderByDescending(p => p.CreatedOnUtc).Take(numberOfNewProductsToShow).ToList(); if (!newProducts.Any()) { return(Content("")); } var model = _productModelFactory.PrepareProductOverviewModels(newProducts, true, true).ToList(); return(View("~/Plugins/Widgets.HomePageNewProducts/Views/Default.cshtml", model)); }
public IViewComponentResult Invoke(int?productThumbPictureSize) { var products = new List <Product>(); foreach (var customerVendor in _workContext.CurrentCustomer.CustomerVendorMappings) { var vendorProducts = _productService.SearchProducts(vendorId: customerVendor.VendorId, visibleIndividuallyOnly: true); products.AddRange(vendorProducts); } if (!products.Any()) { return(Content("")); } var model = _productModelFactory.PrepareProductOverviewModels(products, true, true, productThumbPictureSize).ToList(); return(View(model)); }
public IViewComponentResult Invoke(int categoryId) { var products = _productService.GetAllProductsDisplayedOnHomepage(categoryId); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList(); //availability dates products = products.Where(p => _productService.ProductIsAvailable(p)).ToList(); products = products.Where(p => p.VisibleIndividually).ToList(); if (!products.Any()) { return(Content("")); } var model = _productModelFactory.PrepareProductOverviewModels(products, true, false).ToList(); return(View(model)); }
public ActionResult PublicInfo(int?categoryid) { var cid = Convert.ToInt32(categoryid); var product = _mostviewService.GetProductByCategory(cid); int[] id = new Int32[3]; if (product != null) { int co = product.Count; for (int i = 0; i < co; i++) { id[i] = product[i].ProductId; } } var products = _productService.GetProductsByIds(id); var model = new List <ProductOverviewModel>(); // model.AddRange(_productModelFactory.Mostviewproducts(products)); model.AddRange(_productModelFactory.PrepareProductOverviewModels(products)); return(View("~/Plugins/Misc.HelloWorldPlugin/Views/PublicInfo/PublicInfo.cshtml", model)); }
public dynamic GetProducts(int categoryId, int pageIndex) { //include subcategories IList <int> categoryIds = _categoryService.GetChildCategoryIds(categoryId, _storeContext.CurrentStore.Id); var category = _categoryService.GetCategoryById(categoryId); if (category.ParentCategoryId != 0 || categoryIds.Count() == 0) { categoryIds.Add(categoryId); } decimal?minPrice = null, maxPrice = null; if (!string.IsNullOrEmpty(_webHelper.QueryString <string>("price"))) { minPrice = decimal.Parse(_webHelper.QueryString <string>("price").Split('-')[0]); maxPrice = decimal.Parse(_webHelper.QueryString <string>("price").Split('-')[1]); } decimal?minLength = null, maxLength = null; if (!string.IsNullOrEmpty(_webHelper.QueryString <string>("length"))) { minLength = decimal.Parse(_webHelper.QueryString <string>("length").Split('-')[0]); maxLength = decimal.Parse(_webHelper.QueryString <string>("length").Split('-')[1]); } decimal?minWidth = null, maxWidth = null; if (!string.IsNullOrEmpty(_webHelper.QueryString <string>("width"))) { minWidth = decimal.Parse(_webHelper.QueryString <string>("width").Split('-')[0]); maxWidth = decimal.Parse(_webHelper.QueryString <string>("width").Split('-')[1]); } decimal?minHeight = null, maxHeight = null; if (!string.IsNullOrEmpty(_webHelper.QueryString <string>("height"))) { minHeight = decimal.Parse(_webHelper.QueryString <string>("height").Split('-')[0]); maxHeight = decimal.Parse(_webHelper.QueryString <string>("height").Split('-')[1]); } decimal?minSleepLength = null, maxSleepLength = null; if (!string.IsNullOrEmpty(_webHelper.QueryString <string>("sleeplength"))) { minSleepLength = decimal.Parse(_webHelper.QueryString <string>("sleeplength").Split('-')[0]); maxSleepLength = decimal.Parse(_webHelper.QueryString <string>("sleeplength").Split('-')[1]); } decimal?minSleepWidth = null, maxSleepWidth = null; if (!string.IsNullOrEmpty(_webHelper.QueryString <string>("sleepwidth"))) { minSleepWidth = decimal.Parse(_webHelper.QueryString <string>("sleepwidth").Split('-')[0]); maxSleepWidth = decimal.Parse(_webHelper.QueryString <string>("sleepwidth").Split('-')[1]); } IEnumerable <Product> products = _productService.SearchProducts(out IList <int> filterableSpecificationAttributeOptionIds, true, categoryIds: categoryIds, storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true, featuredProducts: _catalogSettings.IncludeFeaturedProductsInNormalLists ? null : (bool?)false, priceMin: minPrice, priceMax: maxPrice, MinHeight: minHeight, MaxHeight: maxHeight, MinLength: minLength, MaxLength: maxLength, MinWidth: minWidth, MaxWidth: maxWidth, MinSleepLength: minSleepLength, MaxSleepLength: maxSleepLength, MinSleepWidth: minSleepWidth, MaxSleepWidth: maxSleepWidth, pageIndex: pageIndex - 1, pageSize: 32); // IEnumerable<Product> products = _productService.SearchProducts( //storeId: _storeContext.CurrentStore.Id, //categoryIds: categories, //pageIndex: pageIndex - 1, //pageSize: 32); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)); //availability dates products = products.Where(p => _productService.ProductIsAvailable(p) && !p.Deleted && p.Published); if (!products.Any()) { return(Content("")); } //prepare model var model = _productModelFactory.PrepareProductOverviewModels(products, true, true); return(new { model }); }
public IActionResult SendNotificationOffer(SentNotificationModel model) { if (model.SelectedIds == null) { return(Json(new ResultMessageModel { Success = false, Message = "No Customers select" })); } var customerIds = model.SelectedIds .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => Convert.ToInt32(x)) .ToArray(); string payload; switch (model.OfferType) { case OfferType.Product: var products = new List <Product> { _productService.GetProductById(model.OfferId) }; var productModel = _productModelFactory.PrepareProductOverviewModels(products).FirstOrDefault(); if (productModel == null) { return(Json(new ResultMessageModel { Success = false, Message = "No product found" })); } payload = JsonConvert.SerializeObject(new { offer = new { productModel.Id, productModel.Name, productModel.SeName, productModel.ProductPrice.Price, productModel.DefaultPictureModel.ImageUrl }, notificationType = NotificationType.Offer.ToString() }); break; case OfferType.Category: var category = _categoryService.GetCategoryById(model.OfferId); var categoryModel = _catalogModelFactory.PrepareCategoryModel(category, new CatalogPagingFilteringModel()); if (categoryModel == null) { return(Json(new ResultMessageModel { Success = false, Message = "No category found" })); } payload = JsonConvert.SerializeObject(new{ offer = new{ categoryModel.Id, categoryModel.Name, categoryModel.SeName, categoryModel.PictureModel.ImageUrl }, notificationType = NotificationType.Offer.ToString() }); break; default: return(Json(new ResultMessageModel { Success = false, Message = "No offer type selected" })); } return(Json(SentNotification(customerIds, payload))); }
public virtual CategoryModel PrepareCategoryModel(Category category, CatalogPagingFilteringModel command) { if (category == null) { throw new ArgumentNullException("category"); } var model = new CategoryModel { Id = category.Id, Name = category.GetLocalized(x => x.Name), Description = category.GetLocalized(x => x.Description), MetaKeywords = category.GetLocalized(x => x.MetaKeywords), MetaDescription = category.GetLocalized(x => x.MetaDescription), MetaTitle = category.GetLocalized(x => x.MetaTitle), SeName = category.GetSeName(), }; //sorting PrepareSortingOptions(model.PagingFilteringContext, command); //view mode PrepareViewModes(model.PagingFilteringContext, command); //page size PreparePageSizeOptions(model.PagingFilteringContext, command, category.AllowCustomersToSelectPageSize, category.PageSizeOptions, category.PageSize); //category breadcrumb if (_catalogSettings.CategoryBreadcrumbEnabled) { model.DisplayCategoryBreadcrumb = true; string breadcrumbCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_BREADCRUMB_KEY, category.Id, string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()), _storeContext.CurrentStore.Id, _workContext.WorkingLanguage.Id); model.CategoryBreadcrumb = _cacheManager.Get(breadcrumbCacheKey, () => category .GetCategoryBreadCrumb(_categoryService, _aclService, _storeMappingService) .Select(catBr => new CategoryModel { Id = catBr.Id, Name = catBr.GetLocalized(x => x.Name), SeName = catBr.GetSeName() }) .ToList() ); } var pictureSize = _mediaSettings.CategoryThumbPictureSize; //subcategories string subCategoriesCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_SUBCATEGORIES_KEY, category.Id, pictureSize, string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()), _storeContext.CurrentStore.Id, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured()); model.SubCategories = _cacheManager.Get(subCategoriesCacheKey, () => _categoryService.GetAllCategoriesByParentCategoryId(category.Id) .Select(x => { var subCatModel = new CategoryModel.SubCategoryModel { Id = x.Id, Name = x.GetLocalized(y => y.Name), SeName = x.GetSeName(), Description = x.GetLocalized(y => y.Description) }; //prepare picture model var categoryPictureCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_PICTURE_MODEL_KEY, x.Id, pictureSize, true, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured(), _storeContext.CurrentStore.Id); subCatModel.PictureModel = _cacheManager.Get(categoryPictureCacheKey, () => { var picture = _pictureService.GetPictureById(x.PictureId); var pictureModel = new PictureModel { FullSizeImageUrl = _pictureService.GetPictureUrl(picture), ImageUrl = _pictureService.GetPictureUrl(picture, pictureSize), Title = string.Format(_localizationService.GetResource("Media.Category.ImageLinkTitleFormat"), subCatModel.Name), AlternateText = string.Format(_localizationService.GetResource("Media.Category.ImageAlternateTextFormat"), subCatModel.Name) }; return(pictureModel); }); return(subCatModel); }) .ToList() ); //featured products if (!_catalogSettings.IgnoreFeaturedProducts) { //We cache a value indicating whether we have featured products IPagedList <Product> featuredProducts = null; string cacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_HAS_FEATURED_PRODUCTS_KEY, category.Id, string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()), _storeContext.CurrentStore.Id); var hasFeaturedProductsCache = _cacheManager.Get <bool?>(cacheKey); if (!hasFeaturedProductsCache.HasValue) { //no value in the cache yet //let's load products and cache the result (true/false) featuredProducts = _productService.SearchProducts( categoryIds: new List <int> { category.Id }, storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true, featuredProducts: true); hasFeaturedProductsCache = featuredProducts.TotalCount > 0; _cacheManager.Set(cacheKey, hasFeaturedProductsCache, 60); } if (hasFeaturedProductsCache.Value && featuredProducts == null) { //cache indicates that the category has featured products //let's load them featuredProducts = _productService.SearchProducts( categoryIds: new List <int> { category.Id }, storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true, featuredProducts: true); } if (featuredProducts != null) { model.FeaturedProducts = _productModelFactory.PrepareProductOverviewModels(featuredProducts).ToList(); } } var categoryIds = new List <int>(); categoryIds.Add(category.Id); if (_catalogSettings.ShowProductsFromSubcategories) { //include subcategories categoryIds.AddRange(GetChildCategoryIds(category.Id)); } //products var products = _productService.SearchProducts( categoryIds: categoryIds, storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true, featuredProducts: _catalogSettings.IncludeFeaturedProductsInNormalLists ? null : (bool?)false, orderBy: (ProductSortingEnum)command.OrderBy, pageIndex: command.PageNumber - 1, pageSize: command.PageSize); model.Products = _productModelFactory.PrepareProductOverviewModels(products).ToList(); model.PagingFilteringContext.LoadPagedList(products); return(model); }
public IEnumerable <ProductOverviewModel> prepareProductOverViewModel(List <Product> productList) { var productOverviewModel = _productModelFactory.PrepareProductOverviewModels(productList); return(productOverviewModel); }