diff --git a/src/Core/Grand.Infrastructure/Caching/Constants/ProductCacheKey.cs b/src/Core/Grand.Infrastructure/Caching/Constants/ProductCacheKey.cs index a388154dd..69bf390d0 100644 --- a/src/Core/Grand.Infrastructure/Caching/Constants/ProductCacheKey.cs +++ b/src/Core/Grand.Infrastructure/Caching/Constants/ProductCacheKey.cs @@ -82,7 +82,7 @@ public static partial class CacheKey /// /// Compare products cookie name /// - public static string PRODUCTS_COMPARE_COOKIE_NAME => "Grand.CompareProducts"; + public static string PRODUCTS_COMPARE_COOKIE_NAME => "Grand.CompareProduct"; /// /// Key for caching diff --git a/src/Web/Grand.Web/Components/Footer.cs b/src/Web/Grand.Web/Components/Footer.cs index 07bd495aa..98b167e85 100644 --- a/src/Web/Grand.Web/Components/Footer.cs +++ b/src/Web/Grand.Web/Components/Footer.cs @@ -103,7 +103,6 @@ private async Task PrepareFooter() PinterestLink = _storeInformationSettings.PinterestLink, BlogEnabled = _blogSettings.Enabled, KnowledgebaseEnabled = _knowledgebaseSettings.Enabled, - CompareProductsEnabled = _catalogSettings.CompareProductsEnabled, NewsEnabled = _newsSettings.Enabled, RecentlyViewedProductsEnabled = _catalogSettings.RecentlyViewedProductsEnabled, RecommendedProductsEnabled = _catalogSettings.RecommendedProductsEnabled, diff --git a/src/Web/Grand.Web/Controllers/ProductController.cs b/src/Web/Grand.Web/Controllers/ProductController.cs index 935fa8e64..dbd9e75b4 100644 --- a/src/Web/Grand.Web/Controllers/ProductController.cs +++ b/src/Web/Grand.Web/Controllers/ProductController.cs @@ -874,106 +874,14 @@ await _mediator.Send(new SendProductAskQuestionMessageCommand() { protected virtual List GetComparedProductIds() { //try to get cookie - if (!HttpContext.Request.Cookies.TryGetValue(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME, out string productIdsCookie) || string.IsNullOrEmpty(productIdsCookie)) + if (!HttpContext.Request.Cookies.TryGetValue(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME, out var productIdsCookie) || string.IsNullOrEmpty(productIdsCookie)) return new List(); //get array of string product identifiers from cookie - var productIds = productIdsCookie.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + var productIds = productIdsCookie.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); //return list of int product identifiers - return productIds.Select(productId => productId).Distinct().ToList(); - } - - protected virtual void AddCompareProductsCookie(IEnumerable comparedProductIds) - { - //delete current cookie if exists - HttpContext.Response.Cookies.Delete(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME); - - //create cookie value - var comparedProductIdsCookie = string.Join(",", comparedProductIds); - - //create cookie options - var cookieOptions = new CookieOptions { - Expires = DateTime.UtcNow.AddHours(CommonHelper.CookieAuthExpires), - HttpOnly = true - }; - //add cookie - HttpContext.Response.Cookies.Append(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME, comparedProductIdsCookie, cookieOptions); - } - - [HttpPost] - public virtual async Task AddProductToCompareList(string productId) - { - var product = await _productService.GetProductById(productId); - if (product == null || !product.Published) - return Json(new - { - success = false, - comparemessage = "No product found with the specified ID" - }); - - if (product.ProductTypeId == ProductType.Auction || product.ProductTypeId == ProductType.Reservation) - return Json(new - { - success = false, - comparemessage = _translationService.GetResource("Products.ProductCantAddToCompareList") - }); - - if (!_catalogSettings.CompareProductsEnabled) - return Json(new - { - success = false, - comparemessage = "Product comparison is disabled" - }); - - //get list of compared product identifiers - var comparedProductIds = GetComparedProductIds(); - - //whether product identifier to add already exist - if (!comparedProductIds.Contains(productId)) - comparedProductIds.Insert(0, productId); - - //limit list based on the allowed number of products to be compared - comparedProductIds = comparedProductIds.Take(_catalogSettings.CompareProductsNumber).ToList(); - - //set cookie - AddCompareProductsCookie(comparedProductIds); - - //activity log - _ = _customerActivityService.InsertActivity("PublicStore.AddToCompareList", productId, - _workContext.CurrentCustomer, HttpContext.Connection?.RemoteIpAddress?.ToString(), - _translationService.GetResource("ActivityLog.PublicStore.AddToCompareList"), product.Name); - - return Json(new - { - success = true, - comparemessage = string.Format(_translationService.GetResource("Products.ProductHasBeenAddedToCompareList.Link"), Url.RouteUrl("CompareProducts")) - }); - } - - public virtual IActionResult RemoveProductFromCompareList(string productId) - { - var product = _productService.GetProductById(productId); - if (product == null) - return RedirectToRoute("HomePage"); - - if (!_catalogSettings.CompareProductsEnabled) - return RedirectToRoute("HomePage"); - - //get list of compared product identifiers - var comparedProductIds = GetComparedProductIds(); - - //whether product identifier to remove exists - if (!comparedProductIds.Contains(productId)) - return RedirectToRoute("CompareProducts"); - - //it exists, so remove it from list - comparedProductIds.Remove(productId); - - //set cookie - AddCompareProductsCookie(comparedProductIds); ; - - return RedirectToRoute("CompareProducts"); + return productIds.Select(productId => productId).Distinct().Take(10).ToList(); } public virtual async Task CompareProducts() @@ -1008,16 +916,6 @@ public virtual async Task CompareProducts() return View(model); } - - public virtual IActionResult ClearCompareList() - { - if (!_catalogSettings.CompareProductsEnabled) - return RedirectToRoute("HomePage"); - - HttpContext.Response.Cookies.Delete(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME); - - return RedirectToRoute("CompareProducts"); - } #endregion #region Calendar diff --git a/src/Web/Grand.Web/Endpoints/EndpointProvider.cs b/src/Web/Grand.Web/Endpoints/EndpointProvider.cs index e2255ea7c..317a1d976 100644 --- a/src/Web/Grand.Web/Endpoints/EndpointProvider.cs +++ b/src/Web/Grand.Web/Endpoints/EndpointProvider.cs @@ -304,26 +304,11 @@ private void RegisterProductRoute(IEndpointRouteBuilder endpointRouteBuilder, st pattern + "productreviews/{productId}", new { controller = "Product", action = "ProductReviews" }); - //comparing products - endpointRouteBuilder.MapControllerRoute("AddProductToCompare", - pattern + "compareproducts/add/{productId?}", - new { controller = "Product", action = "AddProductToCompareList" }); - //set review helpfulness (AJAX link) endpointRouteBuilder.MapControllerRoute("SetProductReviewHelpfulness", pattern + "setproductreviewhelpfulness", new { controller = "Product", action = "SetProductReviewHelpfulness" }); - //comparing products - endpointRouteBuilder.MapControllerRoute("RemoveProductFromCompareList", - pattern + "compareproducts/remove/{productId}", - new { controller = "Product", action = "RemoveProductFromCompareList" }); - - endpointRouteBuilder.MapControllerRoute("ClearCompareList", - pattern + "clearcomparelist/", - new { controller = "Product", action = "ClearCompareList" }); - - //product attributes with "upload file" type endpointRouteBuilder.MapControllerRoute("UploadFileProductAttribute", pattern + "uploadfileproductattribute/{attributeId?}", diff --git a/src/Web/Grand.Web/Features/Handlers/Common/GetRobotsTextFileHandler.cs b/src/Web/Grand.Web/Features/Handlers/Common/GetRobotsTextFileHandler.cs index ad1a107ea..5fb65808b 100644 --- a/src/Web/Grand.Web/Features/Handlers/Common/GetRobotsTextFileHandler.cs +++ b/src/Web/Grand.Web/Features/Handlers/Common/GetRobotsTextFileHandler.cs @@ -76,9 +76,7 @@ private async Task PrepareRobotsTextFile() "/checkout/shippingmethod", "/checkout/paymentinfo", "/checkout/paymentmethod", - "/clearcomparelist", "/compareproducts", - "/compareproducts/add/*", "/account/activation", "/account/addresses", "/account/changepassword", diff --git a/src/Web/Grand.Web/Models/Common/FooterModel.cs b/src/Web/Grand.Web/Models/Common/FooterModel.cs index 426ddf55d..95d288a8b 100644 --- a/src/Web/Grand.Web/Models/Common/FooterModel.cs +++ b/src/Web/Grand.Web/Models/Common/FooterModel.cs @@ -29,7 +29,6 @@ public FooterModel() public bool SitemapEnabled { get; set; } public bool BlogEnabled { get; set; } public bool NewsEnabled { get; set; } - public bool CompareProductsEnabled { get; set; } public bool RecentlyViewedProductsEnabled { get; set; } public bool RecommendedProductsEnabled { get; set; } public bool NewProductsEnabled { get; set; } diff --git a/src/Web/Grand.Web/Views/Catalog/_CatalogProductListView.cshtml b/src/Web/Grand.Web/Views/Catalog/_CatalogProductListView.cshtml index c863a7309..22af80f43 100644 --- a/src/Web/Grand.Web/Views/Catalog/_CatalogProductListView.cshtml +++ b/src/Web/Grand.Web/Views/Catalog/_CatalogProductListView.cshtml @@ -288,7 +288,7 @@ } @if (!Model.ProductPrice.DisableAddToCompareListButton && Model.ProductType == ProductType.SimpleProduct) { - diff --git a/src/Web/Grand.Web/Views/Catalog/_CatalogProductListViewVue.cshtml b/src/Web/Grand.Web/Views/Catalog/_CatalogProductListViewVue.cshtml index 251134eb0..8b52de5b1 100644 --- a/src/Web/Grand.Web/Views/Catalog/_CatalogProductListViewVue.cshtml +++ b/src/Web/Grand.Web/Views/Catalog/_CatalogProductListViewVue.cshtml @@ -226,7 +226,7 @@