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.

Add new vendor settings - Allow vendor to upload picture file

support539b92c7843b
diff --git a/src/Core/Grand.Domain/Vendors/VendorSettings.cs b/src/Core/Grand.Domain/Vendors/VendorSettings.cs
index 437fa816e..6393017de 100644
--- a/src/Core/Grand.Domain/Vendors/VendorSettings.cs
+++ b/src/Core/Grand.Domain/Vendors/VendorSettings.cs
@@ -45,6 +45,10 @@ namespace Grand.Domain.Vendors
/// Get or sets a value indicating whether vendor can edit information about itself (public store)
/// </summary>
public bool AllowVendorsToEditInfo { get; set; }
+ /// <summary>
+ /// Get or sets a value indicating whether vendor can upload picture file
+ /// </summary>
+ public bool AllowToUploadFile { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the store owner is notified that the vendor information has been changed
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 1ce3000cc..71d5a9886 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
@@ -209,7 +209,18 @@
<span asp-validation-for="TermsOfServiceEnabled"></span>
</div>
</div>
-
+ <div class="form-group">
+ <div class="col-8 col-md-4 col-sm-4 text-right">
+ <admin-label asp-for="AllowToUploadFile" 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="AllowToUploadFile" />
+ <div class="control__indicator"></div>
+ </label>
+ <span asp-validation-for="AllowToUploadFile"></span>
+ </div>
+ </div>
<div class="form-group">
<div class="col-8 col-md-4 col-sm-4 text-right">
<admin-label asp-for="VendorReviewsMustBeApproved" 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 2160f5e74..a664d4323 100644
--- a/src/Web/Grand.Web.Admin/Models/Settings/VendorSettingsModel.cs
+++ b/src/Web/Grand.Web.Admin/Models/Settings/VendorSettingsModel.cs
@@ -36,7 +36,8 @@ namespace Grand.Web.Admin.Models.Settings
[GrandResourceDisplayName("Admin.Settings.Vendor.TermsOfServiceEnabled")]
public bool TermsOfServiceEnabled { get; set; }
-
+ [GrandResourceDisplayName("Admin.Settings.Vendor.AllowToUploadFile")]
+ public bool AllowToUploadFile { get; set; }
//review vendor
[GrandResourceDisplayName("Admin.Settings.Vendor.VendorReviewsMustBeApproved")]
public bool VendorReviewsMustBeApproved { 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 3cdade67a..3cb5228b8 100644
--- a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
+++ b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
@@ -11399,6 +11399,9 @@
<Resource Name="Admin.Settings.Vendor.AllowCustomersToContactVendors" Area="Admin">
<Value>Allow customers to contact vendors</Value>
</Resource>
+ <Resource Name="Admin.Settings.Vendor.AllowToUploadFile" Area="Admin">
+ <Value>Allow vendor to upload picture file</Value>
+ </Resource>
<Resource Name="Admin.Settings.Vendor.AllowSearchByVendor" Area="Admin">
<Value>Allow search by vendor in store advanced search</Value>
</Resource>
diff --git a/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_210.xml b/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_210.xml
index 8cd698b5b..9d300141f 100644
--- a/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_210.xml
+++ b/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_210.xml
@@ -51,4 +51,7 @@
<Resource Name="ContactUs.ValidationFileAllowed" Area="Front">
<Value>This file extension does not allow to upload</Value>
</Resource>
+ <Resource Name="Admin.Settings.Vendor.AllowToUploadFile" Area="Admin">
+ <Value>Allow vendor to upload picture file</Value>
+ </Resource>
</Language>
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Controllers/VendorController.cs b/src/Web/Grand.Web/Controllers/VendorController.cs
index a469d7934..2bd7ecafd 100644
--- a/src/Web/Grand.Web/Controllers/VendorController.cs
+++ b/src/Web/Grand.Web/Controllers/VendorController.cs
@@ -116,6 +116,7 @@ namespace Grand.Web.Controllers
model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage;
model.Email = _workContext.CurrentCustomer.Email;
model.TermsOfServiceEnabled = _vendorSettings.TermsOfServiceEnabled;
+ model.AllowToUploadFile = _vendorSettings.AllowToUploadFile;
model.TermsOfServicePopup = _commonSettings.PopupForTermsOfServiceLinks;
var countries = await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id, _workContext.CurrentStore.Id);
model.Address = await _mediator.Send(new GetVendorAddress {
@@ -144,7 +145,7 @@ namespace Grand.Web.Controllers
var contentType = string.Empty;
byte[] vendorPictureBinary = null;
- if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName))
+ if (_vendorSettings.AllowToUploadFile && uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName))
{
try
{
@@ -213,7 +214,7 @@ namespace Grand.Web.Controllers
model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage;
model.TermsOfServiceEnabled = _vendorSettings.TermsOfServiceEnabled;
model.TermsOfServicePopup = _commonSettings.PopupForTermsOfServiceLinks;
-
+ model.AllowToUploadFile = _vendorSettings.AllowToUploadFile;
var countries = await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id, _workContext.CurrentStore.Id);
model.Address = await _mediator.Send(new GetVendorAddress {
Language = _workContext.WorkingLanguage,
@@ -241,6 +242,7 @@ namespace Grand.Web.Controllers
model.Email = vendor.Email;
model.Name = vendor.Name;
model.UserFields = vendor.UserFields;
+ model.AllowToUploadFile = _vendorSettings.AllowToUploadFile;
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 {
@@ -266,7 +268,7 @@ namespace Grand.Web.Controllers
var contentType = string.Empty;
byte[] vendorPictureBinary = null;
- if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName))
+ if (_vendorSettings.AllowToUploadFile && uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName))
{
try
{
@@ -303,10 +305,10 @@ namespace Grand.Web.Controllers
var picture = await _pictureService.InsertPicture(vendorPictureBinary, contentType, null, reference: Reference.Vendor, objectId: vendor.Id);
if (picture != null)
vendor.PictureId = picture.Id;
+
+ if (prevPicture != null)
+ await _pictureService.DeletePicture(prevPicture);
}
- if (prevPicture != null)
- await _pictureService.DeletePicture(prevPicture);
-
//update picture seo file name
await UpdatePictureSeoNames(vendor);
model.Address.ToEntity(vendor.Address);
diff --git a/src/Web/Grand.Web/Models/Vendors/ApplyVendorModel.cs b/src/Web/Grand.Web/Models/Vendors/ApplyVendorModel.cs
index 5d0bb707c..b54316963 100644
--- a/src/Web/Grand.Web/Models/Vendors/ApplyVendorModel.cs
+++ b/src/Web/Grand.Web/Models/Vendors/ApplyVendorModel.cs
@@ -27,6 +27,7 @@ namespace Grand.Web.Models.Vendors
public bool TermsOfServiceEnabled { get; set; }
public bool TermsOfServicePopup { get; set; }
public bool DisableFormInput { get; set; }
+ public bool AllowToUploadFile { get; set; }
public string Result { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Models/Vendors/VendorInfoModel.cs b/src/Web/Grand.Web/Models/Vendors/VendorInfoModel.cs
index 4e123a67e..726096e66 100644
--- a/src/Web/Grand.Web/Models/Vendors/VendorInfoModel.cs
+++ b/src/Web/Grand.Web/Models/Vendors/VendorInfoModel.cs
@@ -21,7 +21,7 @@ namespace Grand.Web.Models.Vendors
[GrandResourceDisplayName("Account.VendorInfo.Picture")]
public string PictureUrl { get; set; }
-
+ public bool AllowToUploadFile { get; set; }
public VendorAddressModel Address { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Views/Vendor/ApplyVendor.cshtml b/src/Web/Grand.Web/Views/Vendor/ApplyVendor.cshtml
index 833bebf79..05b51f1d9 100644
--- a/src/Web/Grand.Web/Views/Vendor/ApplyVendor.cshtml
+++ b/src/Web/Grand.Web/Views/Vendor/ApplyVendor.cshtml
@@ -45,13 +45,15 @@
<label asp-for="Description" class="col-form-label">@Loc["Vendors.ApplyAccount.Description"]:</label>
<textarea asp-for="Description" class="form-control description"></textarea>
</div>
-
- <div class="form-group">
- <label class="col-form-label">@Loc["Vendors.ApplyAccount.Picture"]:</label>
- <div class="custom-file">
- <b-form-file id="uploadedFile" name="uploadedFile" accept="image/*"></b-form-file>
+ @if (Model.AllowToUploadFile)
+ {
+ <div class="form-group">
+ <label class="col-form-label">@Loc["Vendors.ApplyAccount.Picture"]:</label>
+ <div class="custom-file">
+ <b-form-file id="uploadedFile" name="uploadedFile" accept="image/*"></b-form-file>
+ </div>
</div>
- </div>
+ }
@if (Model.DisplayCaptcha)
{
<div class="captcha-box">
diff --git a/src/Web/Grand.Web/Views/Vendor/Info.cshtml b/src/Web/Grand.Web/Views/Vendor/Info.cshtml
index b91a5c399..b5c8d4ef2 100644
--- a/src/Web/Grand.Web/Views/Vendor/Info.cshtml
+++ b/src/Web/Grand.Web/Views/Vendor/Info.cshtml
@@ -38,17 +38,20 @@
<label asp-for="Description" class="col-form-label">@Loc["Account.VendorInfo.Description"]:</label>
<textarea asp-for="Description" class="form-control description"></textarea>
</div>
- <div class="form-group">
- <label asp-for="PictureUrl" class="col-form-label">@Loc["Account.VendorInfo.Picture"]:</label>
- <b-form-file id="uploadedFile" name="uploadedFile" accept="image/*"></b-form-file>
- @if (!string.IsNullOrEmpty(Model.PictureUrl))
- {
- <div class="vendor-picture mt-3">
- <img src="@(Model.PictureUrl)" alt="picture" style="width:100px; display:block" />
- <a asp-route="CustomerVendorRemovePicture" name="remove-picture" class="btn btn-danger remove-picture-button mt-3">@Loc["Account.VendorInfo.Picture.Remove"]</a>
- </div>
- }
- </div>
+ @if (Model.AllowToUploadFile)
+ {
+ <div class="form-group">
+ <label asp-for="PictureUrl" class="col-form-label">@Loc["Account.VendorInfo.Picture"]:</label>
+ <b-form-file id="uploadedFile" name="uploadedFile" accept="image/*"></b-form-file>
+ @if (!string.IsNullOrEmpty(Model.PictureUrl))
+ {
+ <div class="vendor-picture mt-3">
+ <img src="@(Model.PictureUrl)" alt="picture" style="width:100px; display:block"/>
+ <a asp-route="CustomerVendorRemovePicture" name="remove-picture" class="btn btn-danger remove-picture-button mt-3">@Loc["Account.VendorInfo.Picture.Remove"]</a>
+ </div>
+ }
+ </div>
+ }
@{
var dataDictAddress = new ViewDataDictionary(ViewData)
{