Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Minor improvements - Product Review return Json model
supportfebd79f7582f
diff --git a/src/Web/Grand.Web/Controllers/ProductController.cs b/src/Web/Grand.Web/Controllers/ProductController.csindex 66365ac9f..52cdde7ea 100644--- a/src/Web/Grand.Web/Controllers/ProductController.cs+++ b/src/Web/Grand.Web/Controllers/ProductController.cs@@ -499,19 +499,17 @@ namespace Grand.Web.Controllers[ValidateCaptcha][DenySystemAccount]public virtual async Task<IActionResult> ProductReviews(- string productId,ProductReviewsModel model,- bool captchaValid,[FromServices] IGroupService groupService,[FromServices] IOrderService orderService,[FromServices] IProductReviewService productReviewService){- var product = await _productService.GetProductById(productId);+ var product = await _productService.GetProductById(model.ProductId);if (product is not { Published: true } || !product.AllowCustomerReviews)- return RedirectToRoute("HomePage");+ return Content("");//validate CAPTCHA- if (_captchaSettings.Enabled && _captchaSettings.ShowOnProductReviewPage && !captchaValid)+ if (_captchaSettings.Enabled && _captchaSettings.ShowOnProductReviewPage && !model.CaptchaValid){ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_translationService));}@@ -522,13 +520,13 @@ namespace Grand.Web.Controllers}if (_catalogSettings.ProductReviewPossibleOnlyAfterPurchasing &&- !(await orderService.SearchOrders(customerId: _workContext.CurrentCustomer.Id, productId: productId, os: (int)OrderStatusSystem.Complete)).Any())+ !(await orderService.SearchOrders(customerId: _workContext.CurrentCustomer.Id, productId: model.ProductId, os: (int)OrderStatusSystem.Complete)).Any())ModelState.AddModelError(string.Empty, _translationService.GetResource("Reviews.ProductReviewPossibleOnlyAfterPurchasing"));if (_catalogSettings.ProductReviewPossibleOnlyOnce){var reviews = await productReviewService.GetAllProductReviews(customerId: _workContext.CurrentCustomer.Id,- productId: productId,+ productId: model.ProductId,pageSize: 1);if (reviews.Any())ModelState.AddModelError(string.Empty, _translationService.GetResource("Reviews.ProductReviewPossibleOnlyOnce"));@@ -577,7 +575,7 @@ namespace Grand.Web.ControllersStore = _workContext.CurrentStore});}- return View(model);+ return Json(model);}//If we got this far, something failed, redisplay form@@ -594,7 +592,7 @@ namespace Grand.Web.Controllersnewmodel.AddProductReview.Title = model.AddProductReview.Title;newmodel.AddProductReview.Result = string.Join(",", ModelState.Values.SelectMany(m => m.Errors).Select(e => e.ErrorMessage).ToList());- return View(newmodel);+ return Json(newmodel);}[HttpPost]diff --git a/src/Web/Grand.Web/Models/Catalog/ProductReviewModel.cs b/src/Web/Grand.Web/Models/Catalog/ProductReviewModel.csindex 3ce852714..ef107e274 100644--- a/src/Web/Grand.Web/Models/Catalog/ProductReviewModel.cs+++ b/src/Web/Grand.Web/Models/Catalog/ProductReviewModel.cs@@ -23,6 +23,7 @@ namespace Grand.Web.Models.Catalog}public string ProductId { get; set; }+ public bool CaptchaValid { get; set; }public string ProductName { get; set; }public string ProductSeName { get; set; }diff --git a/src/Web/Grand.Web/Views/Product/Components/ProductReviews/Default.cshtml b/src/Web/Grand.Web/Views/Product/Components/ProductReviews/Default.cshtmlindex c021ee865..bbf59b890 100644--- a/src/Web/Grand.Web/Views/Product/Components/ProductReviews/Default.cshtml+++ b/src/Web/Grand.Web/Views/Product/Components/ProductReviews/Default.cshtml@@ -90,10 +90,7 @@axios({url: url,method: 'post',- params: { "productReviewId": reviewId, "productId": productId, "washelpful": wasHelpful },- headers: {- 'X-Response-View': 'Json'- },+ params: { "productReviewId": reviewId, "productId": productId, "washelpful": wasHelpful },}).then(function (response) {document.getElementById("helpfulness-vote-yes-" + reviewId + "").innerHTML = response.data.TotalYesdocument.getElementById("helpfulness-vote-no-" + reviewId + "").innerHTML = response.data.TotalNo;@@ -143,8 +140,7 @@url: url,data: bodyFormData,headers: {- "Content-Type": "multipart/form-data",- 'X-Response-View': 'Json'+ "Content-Type": "multipart/form-data"},}).then(function (response) {productreviews.Model = response.data;