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
Product review - further changes
KrzysztofPajak7a90dc136e23
diff --git a/src/Web/Grand.Web/Controllers/ProductController.cs b/src/Web/Grand.Web/Controllers/ProductController.csindex 0f48f4eb3..c96031869 100644--- a/src/Web/Grand.Web/Controllers/ProductController.cs+++ b/src/Web/Grand.Web/Controllers/ProductController.cs@@ -485,28 +485,6 @@ namespace Grand.Web.Controllers#endregion#region Product reviews- public virtual async Task<IActionResult> ProductReviews(string productId,- [FromServices] IGroupService groupService)- {- var product = await _productService.GetProductById(productId);- if (product == null || !product.Published || !product.AllowCustomerReviews)- return RedirectToRoute("HomePage");-- var model = await _mediator.Send(new GetProductReviews() {- Customer = _workContext.CurrentCustomer,- Language = _workContext.WorkingLanguage,- Product = product,- Store = _workContext.CurrentStore,- Size = _catalogSettings.NumberOfReview- });-- //only registered users can leave reviews- if (await groupService.IsGuest(_workContext.CurrentCustomer) && !_catalogSettings.AllowAnonymousUsersToReviewProduct)- ModelState.AddModelError("", _translationService.GetResource("Reviews.OnlyRegisteredUsersCanWriteReviews"));- //default value- model.AddProductReview.Rating = _catalogSettings.DefaultProductRatingValue;- return View(model);- }[HttpPost][AutoValidateAntiforgeryToken]diff --git a/src/Web/Grand.Web/Views/Catalog/Components/VendorReviews/Default.cshtml b/src/Web/Grand.Web/Views/Catalog/Components/VendorReviews/Default.cshtmlindex 9a80bbf78..85f133892 100644--- a/src/Web/Grand.Web/Views/Catalog/Components/VendorReviews/Default.cshtml+++ b/src/Web/Grand.Web/Views/Catalog/Components/VendorReviews/Default.cshtml@@ -111,7 +111,7 @@vm.$refs['ModalVendorReview'].show();},modalReviewShown: function () {- if (vendorreviews.Model.AddVendorReview.DisplayCaptcha && document.querySelector("#ModalVendorReview .captcha-box") == null) {+ if (vendorreviews.Model.AddVendorReview.DisplayCaptcha && document.querySelector("#ModalVendorReview .captcha-box") == null) {var html = document.getElementById("captcha-box");document.getElementById("captcha-popup").prepend(html);}diff --git a/src/Web/Grand.Web/Views/Catalog/_VendorReview.Modal.cshtml b/src/Web/Grand.Web/Views/Catalog/_VendorReview.Modal.cshtmlindex 45a37f760..2e31168ec 100644--- a/src/Web/Grand.Web/Views/Catalog/_VendorReview.Modal.cshtml+++ b/src/Web/Grand.Web/Views/Catalog/_VendorReview.Modal.cshtml@@ -12,8 +12,7 @@<validation-observer v-slot="{ handleSubmit }"><form id="addReviewForm" asp-route="VendorReviews" asp-route-VendorId="@Model.VendorId"method="post" ref="modalForm" v-on:submit.prevent="handleSubmit(vendorreviews.submitVendorReview)" :data-title="'@Loc["Reviews.VendorReviewsFor"] ' + vendorreviews.Model.VendorName">- <input type="hidden" name="VendorId" :value="vendorreviews.Model.VendorId" />- <div asp-validation-summary="ModelOnly" class="message-error alert alert-danger my-3"></div>+ <input type="hidden" asp-for="@Model.VendorId" /><fieldset><div class="form-fields"><div class="form-group">diff --git a/src/Web/Grand.Web/Views/Product/Components/ProductReviews/Default.cshtml b/src/Web/Grand.Web/Views/Product/Components/ProductReviews/Default.cshtmlindex bff01eb64..bc0fe001f 100644--- a/src/Web/Grand.Web/Views/Product/Components/ProductReviews/Default.cshtml+++ b/src/Web/Grand.Web/Views/Product/Components/ProductReviews/Default.cshtml@@ -1,7 +1,7 @@@model ProductReviewsModel<div class="mb-3">- <a class="btn btn-info" @@click="addProductReview('@Url.RouteUrl("ProductReviews", new { productId = Model.ProductId })')">@Loc["Reviews.Overview.AddNew"]</a>+ <a class="btn btn-info" @@click="productreviews.addProductReview()">@Loc["Reviews.Overview.AddNew"]</a></div>@if (Model.AddProductReview.DisplayCaptcha){@@ -11,11 +11,12 @@</div></div>}-<partial name="_ProductReview.Modal" />+<partial name="_ProductReview.Modal.cshtml" model="Model" />+<template id="product-review-list" v-if="productreviews.Model !== null"><div class="product-review-list"><h5 class="mb-3"><strong>@Loc["Reviews.ExistingReviews"]</strong></h5>- <template v-for="review in productreviews.Model">+ <template v-for="review in productreviews.Model.Items"><div class="card product-review-item mb-3"><div class="card-header"><div class="review-info d-inline-flex w-100">@@ -82,7 +83,7 @@}},created() {- this.Model = @Json.Serialize(Model.Items);+ this.Model = @Json.Serialize(Model);},methods: {setProductReviewHelpfulness(url, wasHelpful, reviewId, productId, toastTitle) {@@ -115,6 +116,72 @@}).catch(function (error) {alert(error);})+ },+ addProductReview: function () {+ vm.$refs['ModalProductReview'].show();+ },+ modalReviewShown: function () {+ if (productreviews.Model.AddProductReview.DisplayCaptcha && document.querySelector("#ModalProductReview .captcha-box") == null) {+ var html = document.getElementById("captcha-box");+ document.getElementById("captcha-popup").prepend(html);+ }+ productreviews.Model = Object.assign({}, productreviews.Model, { ReviewTitle: '', ReviewText: '' })+ },+ modalReviewClose: function () {+ if (productreviews.Model.AddProductReview.DisplayCaptcha && document.querySelector("#ModalProductReview .captcha-box") !== null) {+ var html = document.getElementById("captcha-box");+ document.getElementById("captcha-container").prepend(html);+ }+ },+ submitProductReview: function () {+ var form = document.getElementById("addReviewForm");+ var url = form.getAttribute("action");+ var resultTitle = form.getAttribute("data-title");+ var bodyFormData = new FormData(form);+ axios({+ method: "post",+ url: url,+ data: bodyFormData,+ headers: {+ "Content-Type": "multipart/form-data",+ 'X-Response-View': 'Json'+ },+ }).then(function (response) {+ productreviews.Model = response.data;+ var result = response.data.AddProductReview.Result;+ var variant = "";++ if (response.data.AddProductReview.SuccessfullyAdded) {++ variant = "info";+ vm.$refs['ModalProductReview'].hide();++ } else {+ variant = "danger";+ }++ new Vue({+ el: ".modal-place",+ methods: {+ toast() {+ this.$bvToast.toast(result, {+ title: resultTitle,+ variant: variant,+ autoHideDelay: 3000,+ solid: true+ })+ }+ },+ mounted: function () {+ this.toast();+ }+ });++ if (response.data.ProductReviewOverviewModel !== null) {+ productreviewsoverview.Model = response.data.ProductReviewOverviewModel;+ }+ });+ return}}});diff --git a/src/Web/Grand.Web/Views/Product/_ProductReview.Modal.cshtml b/src/Web/Grand.Web/Views/Product/Components/ProductReviews/_ProductReview.Modal.cshtmlsimilarity index 63%rename from src/Web/Grand.Web/Views/Product/_ProductReview.Modal.cshtmlrename to src/Web/Grand.Web/Views/Product/Components/ProductReviews/_ProductReview.Modal.cshtmlindex 1bb730c2d..aac5cee85 100644--- a/src/Web/Grand.Web/Views/Product/_ProductReview.Modal.cshtml+++ b/src/Web/Grand.Web/Views/Product/Components/ProductReviews/_ProductReview.Modal.cshtml@@ -1,31 +1,34 @@-@{- var productlink = @Url.RouteUrl("Product");+@model ProductReviewsModel++@{+ var productlink = @Url.RouteUrl("Product", new { SeName = Model.ProductSeName });}-<b-modal id="ModalProductReview" ref="ModalProductReview" :dark-theme="darkMode" size="xl" @@shown="modalReviewShown()" @@hide="modalReviewClose()" centered hide-footer hide-header>- <template v-if="PopupProductReviewVueModal !== null">- <h2 class="generalTitle h3">@Loc["Reviews.ProductReviewsFor"] <a :href="'@productlink' + PopupProductReviewVueModal.ProductSeName">{{PopupProductReviewVueModal.ProductName}}</a></h2>+<b-modal id="ModalProductReview" ref="ModalProductReview" :dark-theme="darkMode" size="xl" @@shown="productreviews.modalReviewShown()" @@hide="productreviews.modalReviewClose()" centered hide-footer hide-header>+ <template v-if="productreviews.Model !== null">+ <h2 class="generalTitle h3">@Loc["Reviews.ProductReviewsFor"] <a :href="'@productlink'">{{productreviews.Model.ProductName}}</a></h2><a class="modal-close" @@click="$bvModal.hide('ModalProductReview')"><b-icon icon="x"></b-icon></a>- <template v-if="!PopupProductReviewVueModal.AddProductReview.SuccessfullyAdded">+ <template v-if="!productreviews.Model.AddProductReview.SuccessfullyAdded"><div class="write-review" id="review-form"><h5 class="generalTitle"><strong>@Loc["Reviews.Write"]</strong></h5><validation-observer v-slot="{ handleSubmit }">- <form id="addReviewForm" :action="'/productreviews/' + PopupProductReviewVueModal.ProductId" method="post" ref="modalForm" v-on:submit.prevent="handleSubmit(submitProductReview)" :data-title="'@Loc["Reviews.ProductReviewsFor"] ' + PopupProductReviewVueModal.ProductName">- <input type="hidden" name="productId" :value="PopupProductReviewVueModal.ProductId" />+ <form id="addReviewForm" asp-route="ProductReviews" asp-route-ProductId="@Model.ProductId" method="post" ref="modalForm"+ v-on:submit.prevent="handleSubmit(productreviews.submitProductReview)" :data-title="'@Loc["Reviews.ProductReviewsFor"] ' + productreviews.Model.ProductName">+ <input type="hidden" asp-for="@Model.ProductId" /><div asp-validation-summary="ModelOnly" class="message-error alert alert-danger my-3"></div><fieldset><div class="form-fields"><div class="form-group"><validation-provider tag="div" rules="required" name="AddProductReview.Title" v-slot="{ errors, classes }"><label for="AddProductReview_Title" class="col-form-label">@Loc["Reviews.Fields.Title"]:</label>- <input data-val-required="@Loc["reviews.fields.title.required"]" v-model="PopupProductReviewVueModal.ReviewTitle" id="AddProductReview_Title" name="AddProductReview.Title" v-bind:class="[classes , 'form-control review-title']" :disabled="!PopupProductReviewVueModal.AddProductReview.CanCurrentCustomerLeaveReview"/>+ <input data-val-required="@Loc["reviews.fields.title.required"]" v-model="productreviews.Model.ReviewTitle" id="AddProductReview_Title" name="AddProductReview.Title" v-bind:class="[classes , 'form-control review-title']" :disabled="!productreviews.Model.AddProductReview.CanCurrentCustomerLeaveReview" /><span class="field-validation-error">{{ errors[0] }}</span></validation-provider></div><div class="form-group"><validation-provider tag="div" rules="required" name="AddProductReview.ReviewText" v-slot="{ errors, classes }"><label for="AddProductReview_ReviewText" class="col-form-label">@Loc["Reviews.Fields.ReviewText"]:</label>- <textarea data-val-required="@Loc["reviews.fields.reviewtext.required"]" v-model="PopupProductReviewVueModal.ReviewText" id="AddProductReview_ReviewText" name="AddProductReview.ReviewText" v-bind:class="[classes , 'form-control review-text']" :disabled="!PopupProductReviewVueModal.AddProductReview.CanCurrentCustomerLeaveReview"></textarea>+ <textarea data-val-required="@Loc["reviews.fields.reviewtext.required"]" v-model="productreviews.Model.ReviewText" id="AddProductReview_ReviewText" name="AddProductReview.ReviewText" v-bind:class="[classes , 'form-control review-text']" :disabled="!productreviews.Model.AddProductReview.CanCurrentCustomerLeaveReview"></textarea><span class="field-validation-error">{{ errors[0] }}</span></validation-provider></div>@@ -34,13 +37,13 @@<b-form-rating v-model="value" variant="warning" show-value value="5" inline></b-form-rating><input class="sr-only" id="AddProductReview_Rating" name="AddProductReview.Rating" v-model="value" /></div>- <template v-if="PopupProductReviewVueModal.AddProductReview.DisplayCaptcha">+ <template v-if="productreviews.Model.AddProductReview.DisplayCaptcha"><div id="captcha-popup"></div></template></div></fieldset><div class="buttons my-3">- <input type="submit" class="btn btn-info write-product-review-button" value="@Loc[" Reviews.SubmitButton"]" :disabled="!PopupProductReviewVueModal.AddProductReview.CanCurrentCustomerLeaveReview" />+ <input type="submit" class="btn btn-info write-product-review-button" value="@Loc[" Reviews.SubmitButton"]" :disabled="!productreviews.Model.AddProductReview.CanCurrentCustomerLeaveReview" /></div></form></validation-observer>diff --git a/src/Web/Grand.Web/wwwroot/theme/script/app.js b/src/Web/Grand.Web/wwwroot/theme/script/app.jsindex 6978f161f..b7b25290b 100644--- a/src/Web/Grand.Web/wwwroot/theme/script/app.js+++ b/src/Web/Grand.Web/wwwroot/theme/script/app.js@@ -11,7 +11,6 @@flycartfirstload: true,PopupAddToCartVueModal: null,PopupQuickViewVueModal: null,- PopupProductReviewVueModal: null,index: null,RelatedProducts: null,compareproducts: null,@@ -344,84 +343,6 @@}}},- addProductReview: function (url) {- axios({- url: url,- method: 'get',- headers: {- 'Accept': 'application/json',- 'Content-Type': 'application/json',- 'X-Response-View': 'Json'- }- }).then(function (response) {- vm.PopupProductReviewVueModal = response.data;- vm.$refs['ModalProductReview'].show();- });- },- modalReviewShown: function () {- if (vm.PopupProductReviewVueModal.AddProductReview.DisplayCaptcha && document.querySelector("#ModalProductReview .captcha-box") == null) {- var html = document.getElementById("captcha-box");- document.getElementById("captcha-popup").prepend(html);- }- vm.PopupProductReviewVueModal = Object.assign({}, vm.PopupProductReviewVueModal, { ReviewTitle: '', ReviewText: '' })- },- modalReviewClose: function () {- if (vm.PopupProductReviewVueModal.AddProductReview.DisplayCaptcha && document.querySelector("#ModalProductReview .captcha-box") !== null) {- var html = document.getElementById("captcha-box");- document.getElementById("captcha-container").prepend(html);- }- },- submitProductReview: function () {- var form = document.getElementById("addReviewForm");- var url = form.getAttribute("action");- var resultTitle = form.getAttribute("data-title");- var bodyFormData = new FormData(form);- axios({- method: "post",- url: url,- data: bodyFormData,- headers: {- "Content-Type": "multipart/form-data",- 'X-Response-View': 'Json'- },- }).then(function (response) {- vm.PopupProductReviewVueModal = response.data;- productreviews.Model = response.data.Items;-- var result = response.data.AddProductReview.Result;- var variant = "";-- if (response.data.AddProductReview.SuccessfullyAdded) {-- variant = "info";- vm.$refs['ModalProductReview'].hide();-- } else {- variant = "danger";- }-- new Vue({- el: ".modal-place",- methods: {- toast() {- this.$bvToast.toast(result, {- title: resultTitle,- variant: variant,- autoHideDelay: 3000,- solid: true- })- }- },- mounted: function () {- this.toast();- }- });-- if (response.data.ProductReviewOverviewModel !== null) {- productreviewsoverview.Model = response.data.ProductReviewOverviewModel;- }- });- return- }+},});