Skip to content

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.

Allow leaving only one vendor review per customer #161

KrzysztofPajak32b215697c7e
diff --git a/src/Business/Grand.Business.System/Services/Migrations/1.1/MigrationUpdateResourceString.cs b/src/Business/Grand.Business.System/Services/Migrations/1.1/MigrationUpdateResourceString.cs
index 807190bab..b4c9108c4 100644
--- a/src/Business/Grand.Business.System/Services/Migrations/1.1/MigrationUpdateResourceString.cs
+++ b/src/Business/Grand.Business.System/Services/Migrations/1.1/MigrationUpdateResourceString.cs
@@ -15,7 +15,7 @@ namespace Grand.Business.System.Services.Migrations._1._1
{
public int Priority => 0;
public DbVersion Version => new(1, 1);
- public Guid Identity => new("E15FFD84-D489-4F6D-BB49-3EEFC7EEE2AC");
+ public Guid Identity => new("5FE5E3D4-2783-4925-8727-A8D8F202E4B8");
public string Name => "Update resource string for english language";
/// <summary>
diff --git a/src/Core/Grand.Domain/Vendors/VendorSettings.cs b/src/Core/Grand.Domain/Vendors/VendorSettings.cs
index 61cd7df1d..437fa816e 100644
--- a/src/Core/Grand.Domain/Vendors/VendorSettings.cs
+++ b/src/Core/Grand.Domain/Vendors/VendorSettings.cs
@@ -81,6 +81,11 @@ namespace Grand.Domain.Vendors
/// </summary>
public bool DefaultAllowCustomerReview { get; set; }
+ /// <summary>
+ /// Gets or sets a value indicating whether vendor can be reviewed only once by customer
+ /// </summary>
+ public bool VendorReviewPossibleOnlyOnce { get; set; }
+
/// <summary>
/// Gets or sets a number of review on vendor page
/// </summary>
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Setting/Vendor.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Setting/Vendor.cshtml
index cf3e9cb57..1ce3000cc 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Setting/Vendor.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Setting/Vendor.cshtml
@@ -288,6 +288,18 @@
<span asp-validation-for="DefaultVendorRatingValue"></span>
</div>
</div>
+ <div class="form-group">
+ <div class="col-8 col-md-4 col-sm-4 text-right">
+ <admin-label asp-for="VendorReviewPossibleOnlyOnce" class="control-label" />
+ </div>
+ <div class="col-4 col-md-8 col-sm-8">
+ <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
+ <admin-input asp-for="VendorReviewPossibleOnlyOnce" />
+ <div class="control__indicator"></div>
+ </label>
+ <span asp-validation-for="VendorReviewPossibleOnlyOnce"></span>
+ </div>
+ </div>
<div class="form-group">
<div class="col-8 col-md-4 col-sm-4 text-right">
<admin-label asp-for="NumberOfReview" class="control-label" />
diff --git a/src/Web/Grand.Web.Admin/Models/Settings/VendorSettingsModel.cs b/src/Web/Grand.Web.Admin/Models/Settings/VendorSettingsModel.cs
index 6ae65855c..2160f5e74 100644
--- a/src/Web/Grand.Web.Admin/Models/Settings/VendorSettingsModel.cs
+++ b/src/Web/Grand.Web.Admin/Models/Settings/VendorSettingsModel.cs
@@ -62,6 +62,9 @@ namespace Grand.Web.Admin.Models.Settings
[GrandResourceDisplayName("Admin.Settings.Vendor.DefaultVendorRatingValue")]
public int DefaultVendorRatingValue { get; set; }
+ [GrandResourceDisplayName("Admin.Settings.Vendor.VendorReviewPossibleOnlyOnce")]
+ public bool VendorReviewPossibleOnlyOnce { get; set; }
+
[GrandResourceDisplayName("Admin.Settings.Vendor.DefaultVendorPageSizeOptions")]
public string DefaultVendorPageSizeOptions { get; set; }
diff --git a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
index 3b915f753..33e9e0079 100644
--- a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
+++ b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
@@ -12063,6 +12063,9 @@
<Resource Name="Admin.Settings.Vendor.VendorReviewPossibleOnlyAfterPurchasing">
<Value>Vendor review possible only after purchasing product from vendor</Value>
</Resource>
+ <Resource Name="Admin.Settings.Vendor.VendorReviewPossibleOnlyOnce">
+ <Value>Vendor review possible only once by customer</Value>
+ </Resource>
<Resource Name="Admin.Settings.Vendor.VendorReviews">
<Value>Vendor reviews</Value>
</Resource>
@@ -16602,6 +16605,9 @@
<Resource Name="VendorReviews.VendorReviewPossibleOnlyAfterPurchasing">
<Value>Vendor can be reviewed only after purchasing a product from this vendor.</Value>
</Resource>
+ <Resource Name="VendorReviews.VendorReviewPossibleOnlyOnce">
+ <Value>Vendor can be reviewed only once by customer</Value>
+ </Resource>
<Resource Name="Vendors">
<Value>Vendors</Value>
</Resource>
diff --git a/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_110.xml b/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_110.xml
index cb8b18e20..6c1a48f70 100644
--- a/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_110.xml
+++ b/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_110.xml
@@ -300,4 +300,10 @@
<Resource Name="Admin.Settings.Customer.AddressFormFields.DisallowUsersToChangeEmail">
<Value>Disallow user change email on the address fields</Value>
</Resource>
+ <Resource Name="Admin.Settings.Vendor.VendorReviewPossibleOnlyOnce">
+ <Value>Vendor review possible only once by customer</Value>
+ </Resource>
+ <Resource Name="VendorReviews.VendorReviewPossibleOnlyOnce">
+ <Value>Vendor can be reviewed only once by customer</Value>
+ </Resource>
</Language>
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Controllers/CatalogController.cs b/src/Web/Grand.Web/Controllers/CatalogController.cs
index d93a92af8..dba415fd0 100644
--- a/src/Web/Grand.Web/Controllers/CatalogController.cs
+++ b/src/Web/Grand.Web/Controllers/CatalogController.cs
@@ -383,6 +383,16 @@ namespace Grand.Web.Controllers
})).Any())
ModelState.AddModelError(string.Empty, _translationService.GetResource("VendorReviews.VendorReviewPossibleOnlyAfterPurchasing"));
+ if(ModelState.IsValid && _vendorSettings.VendorReviewPossibleOnlyOnce)
+ {
+ if((await _vendorService.GetAllVendorReviews(
+ customerId: _workContext.CurrentCustomer.Id,
+ approved: null,
+ vendorId: vendor.Id,
+ pageSize: 1)).Any())
+ ModelState.AddModelError(string.Empty, _translationService.GetResource("VendorReviews.VendorReviewPossibleOnlyOnce"));
+ }
+
if (ModelState.IsValid)
{
var vendorReview = await _mediator.Send(new InsertVendorReviewCommand() { Vendor = vendor, Store = _workContext.CurrentStore, Model = model });
diff --git a/src/Web/Grand.Web/Controllers/VendorController.cs b/src/Web/Grand.Web/Controllers/VendorController.cs
index d1cc39ce2..d4e19ff50 100644
--- a/src/Web/Grand.Web/Controllers/VendorController.cs
+++ b/src/Web/Grand.Web/Controllers/VendorController.cs
@@ -7,14 +7,12 @@ using Grand.Business.Messages.Interfaces;
using Grand.Business.Storage.Extensions;
using Grand.Business.Storage.Interfaces;
using Grand.Domain.Common;
-using Grand.Domain.Customers;
using Grand.Domain.Localization;
using Grand.Domain.Seo;
using Grand.Domain.Vendors;
using Grand.Infrastructure;
using Grand.SharedKernel.Extensions;
using Grand.Web.Commands.Models.Vendors;
-using Grand.Web.Common.Controllers;
using Grand.Web.Common.Filters;
using Grand.Web.Common.Security.Captcha;
using Grand.Web.Extensions;
@@ -123,8 +121,7 @@ namespace Grand.Web.Controllers
model.TermsOfServiceEnabled = _vendorSettings.TermsOfServiceEnabled;
model.TermsOfServicePopup = _commonSettings.PopupForTermsOfServiceLinks;
var countries = await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id, _workContext.CurrentStore.Id);
- model.Address = await _mediator.Send(new GetVendorAddress()
- {
+ model.Address = await _mediator.Send(new GetVendorAddress() {
Language = _workContext.WorkingLanguage,
Address = null,
ExcludeProperties = false,
@@ -182,8 +179,7 @@ namespace Grand.Web.Controllers
var description = FormatText.ConvertText(model.Description);
var address = new Address();
//disabled by default
- var vendor = new Vendor
- {
+ var vendor = new Vendor {
Name = model.Name,
Email = model.Email,
Description = description,
@@ -231,8 +227,7 @@ namespace Grand.Web.Controllers
model.TermsOfServicePopup = _commonSettings.PopupForTermsOfServiceLinks;
var countries = await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id, _workContext.CurrentStore.Id);
- model.Address = await _mediator.Send(new GetVendorAddress()
- {
+ model.Address = await _mediator.Send(new GetVendorAddress() {
Language = _workContext.WorkingLanguage,
Address = null,
Model = model.Address,
@@ -260,8 +255,7 @@ namespace Grand.Web.Controllers
model.UserFields = vendor.UserFields;
model.PictureUrl = await _pictureService.GetPictureUrl(vendor.PictureId);
var countries = await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id, _workContext.CurrentStore.Id);
- model.Address = await _mediator.Send(new GetVendorAddress()
- {
+ model.Address = await _mediator.Send(new GetVendorAddress() {
Language = _workContext.WorkingLanguage,
Address = vendor.Address,
ExcludeProperties = false,
@@ -339,8 +333,7 @@ namespace Grand.Web.Controllers
return RedirectToAction("Info");
}
var countries = await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id, _workContext.CurrentStore.Id);
- model.Address = await _mediator.Send(new GetVendorAddress()
- {
+ model.Address = await _mediator.Send(new GetVendorAddress() {
Language = _workContext.WorkingLanguage,
Model = model.Address,
Address = vendor.Address,