public ActionResult CompareProducts() { if (!_catalogSettings.CompareProductsEnabled) { return(HttpNotFound()); } var products = _compareProductsService.GetComparedProducts(); var settings = _helper.GetBestFitProductSummaryMappingSettings(ProductSummaryViewMode.Compare); var model = _helper.MapProductSummaryModel(products, settings); return(View(model)); }
public virtual async Task <IActionResult> CompareProducts() { if (!_catalogSettings.CompareProductsEnabled) { return(RedirectToRoute("HomePage")); } var model = new CompareProductsModel { IncludeShortDescriptionInCompareProducts = _catalogSettings.IncludeShortDescriptionInCompareProducts, IncludeFullDescriptionInCompareProducts = _catalogSettings.IncludeFullDescriptionInCompareProducts, }; var products = await _compareProductsService.GetComparedProducts(); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList(); //availability dates products = products.Where(p => p.IsAvailable()).ToList(); (await _mediator.Send(new GetProductOverview() { PrepareSpecificationAttributes = true, Products = products, })).ToList().ForEach(model.Products.Add); return(View(model)); }
public virtual ActionResult CompareProducts() { if (!_catalogSettings.CompareProductsEnabled) { return(RedirectToRoute("HomePage")); } var model = new CompareProductsModel { IncludeShortDescriptionInCompareProducts = _catalogSettings.IncludeShortDescriptionInCompareProducts, IncludeFullDescriptionInCompareProducts = _catalogSettings.IncludeFullDescriptionInCompareProducts, }; var products = _compareProductsService.GetComparedProducts(); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList(); //availability dates products = products.Where(p => p.IsAvailable()).ToList(); //prepare model _productModelFactory.PrepareProductOverviewModels(products, prepareSpecificationAttributes: true) .ToList() .ForEach(model.Products.Add); return(View(model)); }
public virtual IActionResult AddProductToCompareList(int productId) { var product = _productService.GetProductById(productId); if (product == null || product.Deleted || !product.Published) { return(Json(new { success = false, message = "No product found with the specified ID" })); } if (!_catalogSettings.CompareProductsEnabled) { return(Json(new { success = false, message = "Product comparison is disabled" })); } if (_compareProductsService.GetComparedProducts().Contains(product)) { _compareProductsService.RemoveProductFromCompareList(productId); } else { _compareProductsService.AddProductToCompareList(productId); } //activity log _customerActivityService.InsertActivity("PublicStore.AddToCompareList", string.Format(_localizationService.GetResource("ActivityLog.PublicStore.AddToCompareList"), product.Name), product); return(Json(new { success = true, message = string.Format(_localizationService.GetResource("Products.ProductHasBeenAddedToCompareList.Link"), Url.RouteUrl("CompareProducts")) //use the code below (commented) if you want a customer to be automatically redirected to the compare products page //redirect = Url.RouteUrl("CompareProducts"), })); }
/// <summary> /// Prepare the header links model /// </summary> /// <returns>Header links model</returns> public virtual HeaderLinksModel PrepareHeaderLinksModel() { var customer = _workContext.CurrentCustomer; var unreadMessageCount = GetUnreadPrivateMessages(); var unreadMessage = string.Empty; var alertMessage = string.Empty; if (unreadMessageCount > 0) { unreadMessage = string.Format(_localizationService.GetResource("PrivateMessages.TotalUnread"), unreadMessageCount); //notifications here if (_forumSettings.ShowAlertForPM && !_genericAttributeService.GetAttribute <bool>(customer, NopCustomerDefaults.NotifiedAboutNewPrivateMessagesAttribute, _storeContext.CurrentStore.Id)) { _genericAttributeService.SaveAttribute(customer, NopCustomerDefaults.NotifiedAboutNewPrivateMessagesAttribute, true, _storeContext.CurrentStore.Id); alertMessage = string.Format(_localizationService.GetResource("PrivateMessages.YouHaveUnreadPM"), unreadMessageCount); } } var model = new HeaderLinksModel { IsAuthenticated = customer.IsRegistered(), CustomerName = customer.IsRegistered() ? _customerService.FormatUserName(customer) : "", ShoppingCartEnabled = _permissionService.Authorize(StandardPermissionProvider.EnableShoppingCart), WishlistEnabled = _permissionService.Authorize(StandardPermissionProvider.EnableWishlist), AllowPrivateMessages = customer.IsRegistered() && _forumSettings.AllowPrivateMessages, UnreadPrivateMessages = unreadMessage, AlertMessage = alertMessage, }; //performance optimization (use "HasShoppingCartItems" property) if (customer.HasShoppingCartItems) { model.ShoppingCartItems = customer.ShoppingCartItems .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart) .LimitPerStore(_storeContext.CurrentStore.Id) .Sum(item => item.Quantity); model.WishlistItems = customer.ShoppingCartItems .Where(sci => sci.ShoppingCartType == ShoppingCartType.Wishlist) .LimitPerStore(_storeContext.CurrentStore.Id).Count(); } model.CompareProductItems = _compareProductsService.GetComparedProducts().Count(); return(model); }
public ActionResult HeaderLinks() { var customer = _workContext.CurrentCustomer; var unreadMessageCount = GetUnreadPrivateMessages(); var unreadMessage = string.Empty; var alertMessage = string.Empty; if (unreadMessageCount > 0) { unreadMessage = string.Format(_localizationService.GetResource("PrivateMessages.TotalUnread"), unreadMessageCount); //notifications here if (_forumSettings.ShowAlertForPM && !customer.GetAttribute <bool>(SystemCustomerAttributeNames.NotifiedAboutNewPrivateMessages, _storeContext.CurrentStore.Id)) { _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.NotifiedAboutNewPrivateMessages, true, _storeContext.CurrentStore.Id); alertMessage = string.Format(_localizationService.GetResource("PrivateMessages.YouHaveUnreadPM"), unreadMessageCount); } } var model = new HeaderLinksModel() { IsAuthenticated = customer.IsRegistered(), CustomerEmailUsername = customer.IsRegistered() ? (_customerSettings.UsernamesEnabled ? customer.Username : customer.Email) : "", ShoppingCartEnabled = _permissionService.Authorize(StandardPermissionProvider.EnableShoppingCart), ShoppingCartItems = customer.ShoppingCartItems .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart) .Where(sci => sci.StoreId == _storeContext.CurrentStore.Id) .ToList() .GetTotalProducts(), WishlistEnabled = _permissionService.Authorize(StandardPermissionProvider.EnableWishlist), WishlistItems = customer.ShoppingCartItems .Where(sci => sci.ShoppingCartType == ShoppingCartType.Wishlist) .Where(sci => sci.StoreId == _storeContext.CurrentStore.Id) .ToList() .GetTotalProducts(), CompareListItems = _compareProductsService.GetComparedProducts().Count, AllowPrivateMessages = customer.IsRegistered() && _forumSettings.AllowPrivateMessages, UnreadPrivateMessages = unreadMessage, AlertMessage = alertMessage, }; return(PartialView(model)); }