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
ContactController - move validator logic from Controller to Validator / Move ContactUsVendor to Vendors folder
support77d6293058be
diff --git a/src/Business/Grand.Business.Core/Interfaces/Marketing/Contacts/IContactAttributeParser.cs b/src/Business/Grand.Business.Core/Interfaces/Marketing/Contacts/IContactAttributeParser.csindex 554e4b8e5..3643b3a8e 100644--- a/src/Business/Grand.Business.Core/Interfaces/Marketing/Contacts/IContactAttributeParser.cs+++ b/src/Business/Grand.Business.Core/Interfaces/Marketing/Contacts/IContactAttributeParser.cs@@ -66,5 +66,12 @@ namespace Grand.Business.Core.Interfaces.Marketing.Contactsstring separator = "<br />",bool htmlEncode = true,bool allowHyperlinks = true);++ /// <summary>+ /// Get parse contact attributes+ /// </summary>+ /// <param name="model"></param>+ /// <returns></returns>+ Task<IList<CustomAttribute>> GetParseContactAttributes(IList<CustomAttribute> model);}}diff --git a/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeParser.cs b/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeParser.csindex cc4c9c391..95859e7b8 100644--- a/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeParser.cs+++ b/src/Business/Grand.Business.Marketing/Services/Contacts/ContactAttributeParser.cs@@ -22,7 +22,7 @@ namespace Grand.Business.Marketing.Services.Contactspublic ContactAttributeParser(IContactAttributeService contactAttributeService,IWorkContext workContext- )+ ){_contactAttributeService = contactAttributeService;_workContext = workContext;@@ -33,7 +33,8 @@ namespace Grand.Business.Marketing.Services.Contacts/// </summary>/// <param name="customAttributes">Attributes</param>/// <returns>Selected contact attributes</returns>- public virtual async Task<IList<ContactAttribute>> ParseContactAttributes(IList<CustomAttribute> customAttributes)+ public virtual async Task<IList<ContactAttribute>> ParseContactAttributes(+ IList<CustomAttribute> customAttributes){var result = new List<ContactAttribute>();if (customAttributes == null || !customAttributes.Any())@@ -47,6 +48,7 @@ namespace Grand.Business.Marketing.Services.Contactsresult.Add(attribute);}}+return result;}@@ -55,7 +57,8 @@ namespace Grand.Business.Marketing.Services.Contacts/// </summary>/// <param name="customAttributes">Attributes</param>/// <returns>Contact attribute values</returns>- public virtual async Task<IList<ContactAttributeValue>> ParseContactAttributeValues(IList<CustomAttribute> customAttributes)+ public virtual async Task<IList<ContactAttributeValue>> ParseContactAttributeValues(+ IList<CustomAttribute> customAttributes){var values = new List<ContactAttributeValue>();if (customAttributes == null || !customAttributes.Any())@@ -68,10 +71,17 @@ namespace Grand.Business.Marketing.Services.Contactscontinue;var valuesStr = customAttributes.Where(x => x.Key == attribute.Id).Select(x => x.Value);- values.AddRange(from valueStr in valuesStr where !string.IsNullOrEmpty(valueStr) select attribute.ContactAttributeValues.FirstOrDefault(x => x.Id == valueStr) into value where value != null select value);+ values.AddRange(from valueStr in valuesStr+ where !string.IsNullOrEmpty(valueStr)+ select attribute.ContactAttributeValues.FirstOrDefault(x => x.Id == valueStr)+ into value+ where value != null+ select value);}+return values;}+/// <summary>/// Adds an attribute/// </summary>@@ -79,12 +89,12 @@ namespace Grand.Business.Marketing.Services.Contacts/// <param name="ca">Contact attribute</param>/// <param name="value">Value</param>/// <returns>Attributes</returns>- public virtual IList<CustomAttribute> AddContactAttribute(IList<CustomAttribute> customAttributes, ContactAttribute ca, string value)+ public virtual IList<CustomAttribute> AddContactAttribute(IList<CustomAttribute> customAttributes,+ ContactAttribute ca, string value){customAttributes ??= new List<CustomAttribute>();customAttributes.Add(new CustomAttribute() { Key = ca.Id, Value = value });return customAttributes;-}/// <summary>@@ -93,7 +103,8 @@ namespace Grand.Business.Marketing.Services.Contacts/// <param name="attribute">Contact attribute</param>/// <param name="customAttributes">Selected attributes</param>/// <returns>Result</returns>- public virtual async Task<bool?> IsConditionMet(ContactAttribute attribute, IList<CustomAttribute> customAttributes)+ public virtual async Task<bool?> IsConditionMet(ContactAttribute attribute,+ IList<CustomAttribute> customAttributes){if (attribute == null)throw new ArgumentNullException(nameof(attribute));@@ -110,7 +121,8 @@ namespace Grand.Business.Marketing.Services.Contactsif (dependOnAttribute == null)return true;- var valuesThatShouldBeSelected = conditionAttribute.Where(x => x.Key == dependOnAttribute.Id).Select(x => x.Value)+ var valuesThatShouldBeSelected = conditionAttribute.Where(x => x.Key == dependOnAttribute.Id)+ .Select(x => x.Value)//a workaround here://ConditionAttribute can contain "empty" values (nothing is selected)//but in other cases (like below) we do not store empty values@@ -118,7 +130,8 @@ namespace Grand.Business.Marketing.Services.Contacts.Where(x => !string.IsNullOrEmpty(x)).ToList();- var selectedValues = customAttributes.Where(x => x.Key == dependOnAttribute.Id).Select(x => x.Value).ToList();+ var selectedValues = customAttributes.Where(x => x.Key == dependOnAttribute.Id).Select(x => x.Value)+ .ToList();if (valuesThatShouldBeSelected.Count != selectedValues.Count)return false;@@ -142,7 +155,8 @@ namespace Grand.Business.Marketing.Services.Contacts/// <param name="customAttributes">Attributes</param>/// <param name="attribute">Contact attribute</param>/// <returns>Updated result</returns>- public virtual IList<CustomAttribute> RemoveContactAttribute(IList<CustomAttribute> customAttributes, ContactAttribute attribute)+ public virtual IList<CustomAttribute> RemoveContactAttribute(IList<CustomAttribute> customAttributes,+ ContactAttribute attribute){return customAttributes.Where(x => x.Key != attribute.Id).ToList();}@@ -205,6 +219,7 @@ namespace Grand.Business.Marketing.Services.ContactsattributeText =$"<a href=\"{downloadLink}\" class=\"fileuploadattribute\">{attribute.GetTranslation(a => a.TextPrompt, language.Id)}</a>";}+formattedAttribute = $"{attributeName}: {attributeText}";}}@@ -225,6 +240,7 @@ namespace Grand.Business.Marketing.Services.ContactsformattedAttribute =$"{attribute.GetTranslation(a => a.Name, language.Id)}: {attributeValue.GetTranslation(a => a.Name, language.Id)}";}+//encode (if required)if (htmlEncode)formattedAttribute = WebUtility.HtmlEncode(formattedAttribute);@@ -236,7 +252,109 @@ namespace Grand.Business.Marketing.Services.Contactsresult.Append(formattedAttribute);}}+return result.ToString();}++ public async Task<IList<CustomAttribute>> GetParseContactAttributes(IList<CustomAttribute> model)+ {+ var customAttributes = new List<CustomAttribute>();+ var contactAttributes = await _contactAttributeService.GetAllContactAttributes();+ foreach (var attribute in contactAttributes)+ {+ switch (attribute.AttributeControlType)+ {+ case AttributeControlType.DropdownList:+ case AttributeControlType.RadioList:+ case AttributeControlType.ColorSquares:+ case AttributeControlType.ImageSquares:+ {+ var ctrlAttributes = model.FirstOrDefault(x => x.Key == attribute.Id)?.Value;+ if (!string.IsNullOrEmpty(ctrlAttributes))+ {+ customAttributes = AddContactAttribute(customAttributes,+ attribute, ctrlAttributes).ToList();+ }+ }+ break;+ case AttributeControlType.Checkboxes:+ {+ var cblAttributes = model.FirstOrDefault(x => x.Key == attribute.Id)?.Value;++ if (!string.IsNullOrEmpty(cblAttributes))+ {+ foreach (var item in cblAttributes.Split(','))+ {+ customAttributes = AddContactAttribute(customAttributes, attribute, item).ToList();+ }+ }+ }+ break;+ case AttributeControlType.ReadonlyCheckboxes:+ {+ //load read-only (already server-side selected) values+ var attributeValues = attribute.ContactAttributeValues;+ foreach (var selectedAttributeId in attributeValues+ .Where(v => v.IsPreSelected)+ .Select(v => v.Id)+ .ToList())+ {+ customAttributes = AddContactAttribute(customAttributes,+ attribute, selectedAttributeId).ToList();+ }+ }+ break;+ case AttributeControlType.TextBox:+ case AttributeControlType.MultilineTextbox:+ {+ var ctrlAttributes = model.FirstOrDefault(x => x.Key == attribute.Id)?.Value;+ if (!string.IsNullOrEmpty(ctrlAttributes))+ {+ var enteredText = ctrlAttributes.Trim();+ customAttributes = AddContactAttribute(customAttributes,+ attribute, enteredText).ToList();+ }+ }+ break;+ case AttributeControlType.Datepicker:+ {+ var date = model.FirstOrDefault(x => x.Key == attribute.Id + "_day")?.Value;+ var month = model.FirstOrDefault(x => x.Key == attribute.Id + "_month")?.Value;+ var year = model.FirstOrDefault(x => x.Key == attribute.Id + "_year")?.Value;+ DateTime? selectedDate = null;+ try+ {+ selectedDate = new DateTime(int.Parse(year), int.Parse(month), int.Parse(date));+ }+ catch { }++ if (selectedDate.HasValue)+ {+ customAttributes = AddContactAttribute(customAttributes,+ attribute, selectedDate.Value.ToString("D")).ToList();+ }+ }+ break;+ case AttributeControlType.FileUpload:+ {+ var guid = model.FirstOrDefault(x => x.Key == attribute.Id)?.Value;+ if (Guid.TryParse(guid, out Guid downloadGuid))+ customAttributes = AddContactAttribute(customAttributes,+ attribute, downloadGuid.ToString()).ToList();+ }+ break;+ }+ }++ //validate conditional attributes (if specified)+ foreach (var attribute in contactAttributes)+ {+ var conditionMet = await IsConditionMet(attribute, customAttributes);+ if (conditionMet.HasValue && !conditionMet.Value)+ customAttributes = RemoveContactAttribute(customAttributes, attribute).ToList();+ }++ return customAttributes;+ }}-}+}\ No newline at end of filediff --git a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xmlindex 118337e4f..3cdade67a 100644--- a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml+++ b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml@@ -12953,6 +12953,9 @@<Resource Name="ContactUs.Enquiry.Required" Area="Front"><Value>Enter enquiry</Value></Resource>+ <Resource Name="ContactUs.FileUploaded" Area="Front">+ <Value>Your file successfully uploaded!</Value>+ </Resource><Resource Name="ContactUs.FullName" Area="Front"><Value>Your name</Value></Resource>@@ -12962,6 +12965,9 @@<Resource Name="ContactUs.FullName.Required" Area="Front"><Value>Enter your name</Value></Resource>+ <Resource Name="ContactUs.MaximumUploadedFileSize" Area="Front">+ <Value>Maximum file size is {0} KB</Value>+ </Resource><Resource Name="ContactUs.SelectAttribute" Area="Front"><Value>Please select: {0}</Value></Resource>@@ -12977,6 +12983,9 @@<Resource Name="ContactUs.TextboxMinimumLength" Area="Front"><Value>{0} : minimum length is {1} chars</Value></Resource>+ <Resource Name="ContactUs.ValidationFileAllowed" Area="Front">+ <Value>This file extension does not allow to upload</Value>+ </Resource><Resource Name="ContactUs.YourEnquiryHasBeenSent" Area="Front"><Value>Your enquiry has been successfully sent to the store owner.</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.xmlindex 5e570560c..8cd698b5b 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@@ -42,4 +42,13 @@<Resource Name="Account.ChangePassword.Errors.NotRegistered" Area="Front"><Value>Account is not registered</Value></Resource>+ <Resource Name="ContactUs.FileUploaded" Area="Front">+ <Value>Your file successfully uploaded!</Value>+ </Resource>+ <Resource Name="ContactUs.MaximumUploadedFileSize" Area="Front">+ <Value>Maximum file size is {0} KB</Value>+ </Resource>+ <Resource Name="ContactUs.ValidationFileAllowed" Area="Front">+ <Value>This file extension does not allow to upload</Value>+ </Resource></Language>\ No newline at end of filediff --git a/src/Web/Grand.Web/Commands/Handler/Common/ContactUsSendCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/Common/ContactUsSendCommandHandler.csdeleted file mode 100644index 991dfbc85..000000000--- a/src/Web/Grand.Web/Commands/Handler/Common/ContactUsSendCommandHandler.cs+++ /dev/null@@ -1,410 +0,0 @@-using Grand.Business.Core.Extensions;-using Grand.Business.Core.Interfaces.Common.Localization;-using Grand.Business.Core.Interfaces.Common.Logging;-using Grand.Business.Core.Interfaces.Marketing.Contacts;-using Grand.Business.Core.Interfaces.Messages;-using Grand.Business.Core.Interfaces.Storage;-using Grand.Domain.Catalog;-using Grand.Domain.Common;-using Grand.Domain.Messages;-using Grand.Domain.Stores;-using Grand.Infrastructure;-using Grand.SharedKernel.Extensions;-using Grand.Web.Commands.Models.Common;-using Grand.Web.Models.Common;-using MediatR;-using System.Globalization;--namespace Grand.Web.Commands.Handler.Common-{- public class ContactUsSendCommandHandler : IRequestHandler<ContactUsSendCommand, (ContactUsModel model, IList<string> errors)>- {- private readonly IWorkContext _workContext;- private readonly IContactAttributeService _contactAttributeService;- private readonly IContactAttributeParser _contactAttributeParser;- private readonly IDownloadService _downloadService;- private readonly ITranslationService _translationService;- private readonly IMessageProviderService _messageProviderService;- private readonly ICustomerActivityService _customerActivityService;-- private readonly CommonSettings _commonSettings;-- public ContactUsSendCommandHandler(IWorkContext workContext,- IContactAttributeService contactAttributeService,- IContactAttributeParser contactAttributeParser,- IDownloadService downloadService,- ITranslationService translationService,- IMessageProviderService messageProviderService,- ICustomerActivityService customerActivityService,- CommonSettings commonSettings)- {- _workContext = workContext;- _contactAttributeService = contactAttributeService;- _contactAttributeParser = contactAttributeParser;- _downloadService = downloadService;- _translationService = translationService;- _messageProviderService = messageProviderService;- _customerActivityService = customerActivityService;- _commonSettings = commonSettings;- }-- public async Task<(ContactUsModel model, IList<string> errors)> Handle(ContactUsSendCommand request, CancellationToken cancellationToken)- {- var errors = new List<string>();- //parse contact attributes- var attributes = await ParseContactAttributes(request);- var contactAttributeWarnings = await GetContactAttributesWarnings(attributes, request.Store.Id);- if (contactAttributeWarnings.Any())- {- foreach (var item in contactAttributeWarnings)- {- errors.Add(item);- }- }- if (!errors.Any())- {- request.Model.ContactAttribute = attributes;- request.Model.ContactAttributeInfo = await _contactAttributeParser.FormatAttributes(_workContext.WorkingLanguage, attributes, _workContext.CurrentCustomer);- request.Model = await SendContactUs(request, request.Store);-- //activity log- _ = _customerActivityService.InsertActivity("PublicStore.ContactUs", "",- _workContext.CurrentCustomer, request.IpAddress,- _translationService.GetResource("ActivityLog.PublicStore.ContactUs"));-- }- else- {- request.Model.ContactAttributes = await PrepareContactAttributeModel(attributes, request.Store.Id);- }-- return (request.Model, errors);-- }-- private async Task<IList<CustomAttribute>> ParseContactAttributes(ContactUsSendCommand request)- {- var customAttributes = new List<CustomAttribute>();- var contactAttributes = await _contactAttributeService.GetAllContactAttributes(request.Store.Id);- foreach (var attribute in contactAttributes)- {- switch (attribute.AttributeControlType)- {- case AttributeControlType.DropdownList:- case AttributeControlType.RadioList:- case AttributeControlType.ColorSquares:- case AttributeControlType.ImageSquares:- {- var ctrlAttributes = request.Model.Attributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;- if (!string.IsNullOrEmpty(ctrlAttributes))- {- customAttributes = _contactAttributeParser.AddContactAttribute(customAttributes,- attribute, ctrlAttributes).ToList();-- }- }- break;- case AttributeControlType.Checkboxes:- {- var cblAttributes = request.Model.Attributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;-- if (!string.IsNullOrEmpty(cblAttributes))- {- foreach (var item in cblAttributes.Split(','))- {- customAttributes = _contactAttributeParser.AddContactAttribute(customAttributes, attribute, item).ToList();- }- }- }- break;- case AttributeControlType.ReadonlyCheckboxes:- {- //load read-only (already server-side selected) values- var attributeValues = attribute.ContactAttributeValues;- foreach (var selectedAttributeId in attributeValues- .Where(v => v.IsPreSelected)- .Select(v => v.Id)- .ToList())- {- customAttributes = _contactAttributeParser.AddContactAttribute(customAttributes,- attribute, selectedAttributeId).ToList();- }- }- break;- case AttributeControlType.TextBox:- case AttributeControlType.MultilineTextbox:- {- var ctrlAttributes = request.Model.Attributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;- if (!string.IsNullOrEmpty(ctrlAttributes))- {- var enteredText = ctrlAttributes.Trim();- customAttributes = _contactAttributeParser.AddContactAttribute(customAttributes,- attribute, enteredText).ToList();- }- }- break;- case AttributeControlType.Datepicker:- {- var date = request.Model.Attributes.FirstOrDefault(x => x.Key == attribute.Id+ "_day")?.Value;- var month = request.Model.Attributes.FirstOrDefault(x => x.Key == attribute.Id+ "_month")?.Value;- var year = request.Model.Attributes.FirstOrDefault(x => x.Key == attribute.Id+ "_year")?.Value;- DateTime? selectedDate = null;- try- {- selectedDate = new DateTime(int.Parse(year), int.Parse(month), int.Parse(date));- }- catch { }- if (selectedDate.HasValue)- {- customAttributes = _contactAttributeParser.AddContactAttribute(customAttributes,- attribute, selectedDate.Value.ToString("D")).ToList();- }- }- break;- case AttributeControlType.FileUpload:- {- var guid = request.Model.Attributes.FirstOrDefault(x => x.Key == attribute.Id)?.Value;- Guid.TryParse(guid, out Guid downloadGuid);- var download = await _downloadService.GetDownloadByGuid(downloadGuid);- if (download != null)- {- customAttributes = _contactAttributeParser.AddContactAttribute(customAttributes,- attribute, download.DownloadGuid.ToString()).ToList();- }- }- break;- }- }- //validate conditional attributes (if specified)- foreach (var attribute in contactAttributes)- {- var conditionMet = await _contactAttributeParser.IsConditionMet(attribute, customAttributes);- if (conditionMet.HasValue && !conditionMet.Value)- customAttributes = _contactAttributeParser.RemoveContactAttribute(customAttributes, attribute).ToList();- }-- return customAttributes;- }-- private async Task<IList<string>> GetContactAttributesWarnings(IList<CustomAttribute> customAttributes, string storeId)- {- var warnings = new List<string>();-- //selected attributes- var attributes1 = await _contactAttributeParser.ParseContactAttributes(customAttributes);-- //existing contact attributes- var attributes2 = await _contactAttributeService.GetAllContactAttributes(storeId);- foreach (var a2 in attributes2)- {- var conditionMet = await _contactAttributeParser.IsConditionMet(a2, customAttributes);- if (!a2.IsRequired ||- ((!conditionMet.HasValue || !conditionMet.Value) && conditionMet.HasValue)) continue;- var found = false;- //selected checkout attributes- foreach (var a1 in attributes1)- {- if (a1.Id != a2.Id) continue;- var attributeValuesStr = customAttributes.Where(x => x.Key == a1.Id).Select(x => x.Value).ToList();- foreach (var str1 in attributeValuesStr)- if (!string.IsNullOrEmpty(str1.Trim()))- {- found = true;- break;- }- }-- //if not found- if (!found)- {- warnings.Add(- !string.IsNullOrEmpty(a2.GetTranslation(a => a.TextPrompt, _workContext.WorkingLanguage.Id))- ? a2.GetTranslation(a => a.TextPrompt, _workContext.WorkingLanguage.Id)- : string.Format(_translationService.GetResource("ContactUs.SelectAttribute"),- a2.GetTranslation(a => a.Name, _workContext.WorkingLanguage.Id)));- }- }-- //now validation rules-- //minimum length- foreach (var ca in attributes2)- {- if (ca.ValidationMinLength.HasValue)- {-- if (ca.AttributeControlType is AttributeControlType.TextBox or AttributeControlType.MultilineTextbox)- {- var conditionMet = await _contactAttributeParser.IsConditionMet(ca, customAttributes);- if (ca.IsRequired && ((conditionMet.HasValue && conditionMet.Value) || !conditionMet.HasValue))- {- var valuesStr = customAttributes.Where(x => x.Key == ca.Id).Select(x => x.Value).ToList();- var enteredText = valuesStr.FirstOrDefault();- var enteredTextLength = string.IsNullOrEmpty(enteredText) ? 0 : enteredText.Length;-- if (ca.ValidationMinLength.Value > enteredTextLength)- {- warnings.Add(string.Format(_translationService.GetResource("ContactUs.TextboxMinimumLength"), ca.GetTranslation(a => a.Name, _workContext.WorkingLanguage.Id), ca.ValidationMinLength.Value));- }- }- }- }-- //maximum length- if (!ca.ValidationMaxLength.HasValue) continue;- {- if (ca.AttributeControlType != AttributeControlType.TextBox &&- ca.AttributeControlType != AttributeControlType.MultilineTextbox) continue;- var conditionMet = await _contactAttributeParser.IsConditionMet(ca, customAttributes);- if (!ca.IsRequired || ((!conditionMet.HasValue || !conditionMet.Value) && conditionMet.HasValue))- continue;- var valuesStr = customAttributes.Where(x => x.Key == ca.Id).Select(x => x.Value).ToList();- var enteredText = valuesStr.FirstOrDefault();- var enteredTextLength = string.IsNullOrEmpty(enteredText) ? 0 : enteredText.Length;-- if (ca.ValidationMaxLength.Value < enteredTextLength)- {- warnings.Add(string.Format(_translationService.GetResource("ContactUs.TextboxMaximumLength"), ca.GetTranslation(a => a.Name, _workContext.WorkingLanguage.Id), ca.ValidationMaxLength.Value));- }- }- }-- return warnings;- }-- private async Task<IList<ContactUsModel.ContactAttributeModel>> PrepareContactAttributeModel(IList<CustomAttribute> selectedContactAttributes, string storeId)- {- var model = new List<ContactUsModel.ContactAttributeModel>();-- var contactAttributes = await _contactAttributeService.GetAllContactAttributes(storeId);- foreach (var attribute in contactAttributes)- {- var attributeModel = new ContactUsModel.ContactAttributeModel {- Id = attribute.Id,- Name = attribute.GetTranslation(x => x.Name, _workContext.WorkingLanguage.Id),- TextPrompt = attribute.GetTranslation(x => x.TextPrompt, _workContext.WorkingLanguage.Id),- IsRequired = attribute.IsRequired,- AttributeControlType = attribute.AttributeControlType,- DefaultValue = attribute.DefaultValue- };- if (!string.IsNullOrEmpty(attribute.ValidationFileAllowedExtensions))- {- attributeModel.AllowedFileExtensions = attribute.ValidationFileAllowedExtensions- .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)- .ToList();- }-- if (attribute.ShouldHaveValues())- {- //values- var attributeValues = attribute.ContactAttributeValues;- foreach (var attributeValue in attributeValues)- {- var attributeValueModel = new ContactUsModel.ContactAttributeValueModel {- Id = attributeValue.Id,- Name = attributeValue.GetTranslation(x => x.Name, _workContext.WorkingLanguage.Id),- ColorSquaresRgb = attributeValue.ColorSquaresRgb,- IsPreSelected = attributeValue.IsPreSelected,- DisplayOrder = attributeValue.DisplayOrder- };- attributeModel.Values.Add(attributeValueModel);- }- }-- switch (attribute.AttributeControlType)- {- case AttributeControlType.DropdownList:- case AttributeControlType.RadioList:- case AttributeControlType.Checkboxes:- case AttributeControlType.ColorSquares:- case AttributeControlType.ImageSquares:- {- if (selectedContactAttributes != null && selectedContactAttributes.Any())- {- //clear default selection- foreach (var item in attributeModel.Values)- item.IsPreSelected = false;-- //select new values- var selectedValues = await _contactAttributeParser.ParseContactAttributeValues(selectedContactAttributes);- foreach (var attributeValue in selectedValues)- if (attributeModel.Id == attributeValue.ContactAttributeId)- foreach (var item in attributeModel.Values)- if (attributeValue.Id == item.Id)- item.IsPreSelected = true;- }- }- break;- case AttributeControlType.ReadonlyCheckboxes:- {- //do nothing- //values are already pre-set- }- break;- case AttributeControlType.TextBox:- case AttributeControlType.MultilineTextbox:- {- if (selectedContactAttributes != null && selectedContactAttributes.Any())- {- var enteredText = selectedContactAttributes.Where(x => x.Key == attribute.Id).Select(x => x.Value).ToList();- if (enteredText.Any())- attributeModel.DefaultValue = enteredText[0];- }- }- break;- case AttributeControlType.Datepicker:- {- if (selectedContactAttributes != null && selectedContactAttributes.Any())- {- //keep in mind my that the code below works only in the current culture- var selectedDateStr = selectedContactAttributes.Where(x => x.Key == attribute.Id).Select(x => x.Value).ToList();- if (selectedDateStr.Any())- {- if (DateTime.TryParseExact(selectedDateStr[0], "D", CultureInfo.CurrentCulture,- DateTimeStyles.None, out var selectedDate))- {- //successfully parsed- attributeModel.SelectedDay = selectedDate.Day;- attributeModel.SelectedMonth = selectedDate.Month;- attributeModel.SelectedYear = selectedDate.Year;- }- }- }- }- break;- case AttributeControlType.FileUpload:- {- if (selectedContactAttributes != null && selectedContactAttributes.Any())- {- var downloadGuidStr = selectedContactAttributes.Where(x => x.Key == attribute.Id).Select(x => x.Value).FirstOrDefault();- Guid.TryParse(downloadGuidStr, out Guid downloadGuid);- var download = await _downloadService.GetDownloadByGuid(downloadGuid);- if (download != null)- attributeModel.DefaultValue = download.DownloadGuid.ToString();- }- }- break;- }-- model.Add(attributeModel);- }-- return model;- }-- private async Task<ContactUsModel> SendContactUs(ContactUsSendCommand request, Store store)- {- var subject = _commonSettings.SubjectFieldOnContactUsForm ? request.Model.Subject : null;- var body = FormatText.ConvertText(request.Model.Enquiry);-- await _messageProviderService.SendContactUsMessage- (_workContext.CurrentCustomer, store, _workContext.WorkingLanguage.Id, request.Model.Email.Trim(), request.Model.FullName, subject,- body, request.Model.ContactAttributeInfo, request.Model.ContactAttribute, request.IpAddress);-- request.Model.SuccessfullySent = true;- request.Model.Result = _translationService.GetResource("ContactUs.YourEnquiryHasBeenSent");-- return request.Model;- }- }-}diff --git a/src/Web/Grand.Web/Commands/Handler/Common/ContactAttributeChangeCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/Contact/ContactAttributeChangeCommandHandler.cssimilarity index 98%rename from src/Web/Grand.Web/Commands/Handler/Common/ContactAttributeChangeCommandHandler.csrename to src/Web/Grand.Web/Commands/Handler/Contact/ContactAttributeChangeCommandHandler.csindex 662e869b0..e28503ae0 100644--- a/src/Web/Grand.Web/Commands/Handler/Common/ContactAttributeChangeCommandHandler.cs+++ b/src/Web/Grand.Web/Commands/Handler/Contact/ContactAttributeChangeCommandHandler.cs@@ -2,10 +2,10 @@using Grand.Business.Core.Interfaces.Storage;using Grand.Domain.Catalog;using Grand.Domain.Common;-using Grand.Web.Commands.Models.Common;+using Grand.Web.Commands.Models.Contact;using MediatR;-namespace Grand.Web.Commands.Handler.Common+namespace Grand.Web.Commands.Handler.Contact{public class ContactAttributeChangeCommandHandler : IRequestHandler<ContactAttributeChangeCommand, (IList<string>enabledAttributeIds, IList<string> disabledAttributeIds)>diff --git a/src/Web/Grand.Web/Commands/Handler/Common/ContactUsCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/Contact/ContactUsCommandHandler.cssimilarity index 97%rename from src/Web/Grand.Web/Commands/Handler/Common/ContactUsCommandHandler.csrename to src/Web/Grand.Web/Commands/Handler/Contact/ContactUsCommandHandler.csindex 01e13256f..461422069 100644--- a/src/Web/Grand.Web/Commands/Handler/Common/ContactUsCommandHandler.cs+++ b/src/Web/Grand.Web/Commands/Handler/Contact/ContactUsCommandHandler.cs@@ -4,12 +4,12 @@ using Grand.Domain.Catalog;using Grand.Domain.Common;using Grand.Domain.Customers;using Grand.Domain.Messages;-using Grand.Web.Commands.Models.Common;+using Grand.Web.Commands.Models.Contact;using Grand.Web.Common.Security.Captcha;-using Grand.Web.Models.Common;+using Grand.Web.Models.Contact;using MediatR;-namespace Grand.Web.Commands.Handler.Common+namespace Grand.Web.Commands.Handler.Contact{public class ContactUsCommandHandler : IRequestHandler<ContactUsCommand, ContactUsModel>{diff --git a/src/Web/Grand.Web/Commands/Handler/Contact/ContactUsSendCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/Contact/ContactUsSendCommandHandler.csnew file mode 100644index 000000000..282268662--- /dev/null+++ b/src/Web/Grand.Web/Commands/Handler/Contact/ContactUsSendCommandHandler.cs@@ -0,0 +1,75 @@+using Grand.Business.Core.Interfaces.Common.Localization;+using Grand.Business.Core.Interfaces.Common.Logging;+using Grand.Business.Core.Interfaces.Marketing.Contacts;+using Grand.Business.Core.Interfaces.Messages;+using Grand.Domain.Common;+using Grand.Domain.Stores;+using Grand.Infrastructure;+using Grand.SharedKernel.Extensions;+using Grand.Web.Commands.Models.Contact;+using Grand.Web.Models.Contact;+using MediatR;++namespace Grand.Web.Commands.Handler.Contact+{+ public class ContactUsSendCommandHandler : IRequestHandler<ContactUsSendCommand, ContactUsModel>+ {+ private readonly IWorkContext _workContext;+ private readonly IContactAttributeParser _contactAttributeParser;+ private readonly ITranslationService _translationService;+ private readonly IMessageProviderService _messageProviderService;+ private readonly ICustomerActivityService _customerActivityService;++ private readonly CommonSettings _commonSettings;++ public ContactUsSendCommandHandler(IWorkContext workContext,+ IContactAttributeParser contactAttributeParser,+ ITranslationService translationService,+ IMessageProviderService messageProviderService,+ ICustomerActivityService customerActivityService,+ CommonSettings commonSettings)+ {+ _workContext = workContext;+ _contactAttributeParser = contactAttributeParser;+ _translationService = translationService;+ _messageProviderService = messageProviderService;+ _customerActivityService = customerActivityService;+ _commonSettings = commonSettings;+ }++ public async Task<ContactUsModel> Handle(ContactUsSendCommand request, CancellationToken cancellationToken)+ {+ var attributes = await _contactAttributeParser.GetParseContactAttributes(request.Model.Attributes+ .Select(x => new CustomAttribute { Key = x.Key, Value = x.Value }).ToList());++ request.Model.ContactAttribute = attributes;+ request.Model.ContactAttributeInfo =+ await _contactAttributeParser.FormatAttributes(_workContext.WorkingLanguage, attributes,+ _workContext.CurrentCustomer);+ request.Model = await SendContactUs(request, _workContext.CurrentStore);++ //activity log+ _ = _customerActivityService.InsertActivity("PublicStore.ContactUs", "",+ _workContext.CurrentCustomer, request.IpAddress,+ _translationService.GetResource("ActivityLog.PublicStore.ContactUs"));++ return request.Model;+ }++ private async Task<ContactUsModel> SendContactUs(ContactUsSendCommand request, Store store)+ {+ var subject = _commonSettings.SubjectFieldOnContactUsForm ? request.Model.Subject : null;+ var body = FormatText.ConvertText(request.Model.Enquiry);++ await _messageProviderService.SendContactUsMessage+ (_workContext.CurrentCustomer, store, _workContext.WorkingLanguage.Id, request.Model.Email.Trim(),+ request.Model.FullName, subject,+ body, request.Model.ContactAttributeInfo, request.Model.ContactAttribute, request.IpAddress);++ request.Model.SuccessfullySent = true;+ request.Model.Result = _translationService.GetResource("ContactUs.YourEnquiryHasBeenSent");++ return request.Model;+ }+ }+}\ No newline at end of filediff --git a/src/Web/Grand.Web/Commands/Handler/Vendors/ContactVendorCommandHandler.cs b/src/Web/Grand.Web/Commands/Handler/Vendors/ContactVendorCommandHandler.csindex 5c1b20958..3feb5c063 100644--- a/src/Web/Grand.Web/Commands/Handler/Vendors/ContactVendorCommandHandler.cs+++ b/src/Web/Grand.Web/Commands/Handler/Vendors/ContactVendorCommandHandler.cs@@ -4,7 +4,7 @@ using Grand.Domain.Common;using Grand.Infrastructure;using Grand.SharedKernel.Extensions;using Grand.Web.Commands.Models.Vendors;-using Grand.Web.Models.Common;+using Grand.Web.Models.Vendors;using MediatR;namespace Grand.Web.Commands.Handler.Vendorsdiff --git a/src/Web/Grand.Web/Commands/Models/Common/ContactUsSendCommand.cs b/src/Web/Grand.Web/Commands/Models/Common/ContactUsSendCommand.csdeleted file mode 100644index bf59070a2..000000000--- a/src/Web/Grand.Web/Commands/Models/Common/ContactUsSendCommand.cs+++ /dev/null@@ -1,14 +0,0 @@-using Grand.Domain.Stores;-using Grand.Web.Models.Common;-using MediatR;--namespace Grand.Web.Commands.Models.Common-{- public class ContactUsSendCommand : IRequest<(ContactUsModel model, IList<string> errors)>- {- public ContactUsModel Model { get; set; }- public bool CaptchaValid { get; set; }- public string IpAddress { get; set; }- public Store Store { get; set; }- }-}diff --git a/src/Web/Grand.Web/Commands/Models/Common/ContactAttributeChangeCommand.cs b/src/Web/Grand.Web/Commands/Models/Contact/ContactAttributeChangeCommand.cssimilarity index 90%rename from src/Web/Grand.Web/Commands/Models/Common/ContactAttributeChangeCommand.csrename to src/Web/Grand.Web/Commands/Models/Contact/ContactAttributeChangeCommand.csindex aa77d985b..8544d9041 100644--- a/src/Web/Grand.Web/Commands/Models/Common/ContactAttributeChangeCommand.cs+++ b/src/Web/Grand.Web/Commands/Models/Contact/ContactAttributeChangeCommand.cs@@ -3,7 +3,7 @@ using Grand.Domain.Stores;using Grand.Web.Common.Models;using MediatR;-namespace Grand.Web.Commands.Models.Common+namespace Grand.Web.Commands.Models.Contact{public class ContactAttributeChangeCommand : IRequest<(IList<string> enabledAttributeIds, IList<string> disabledAttributeIds)>{diff --git a/src/Web/Grand.Web/Commands/Models/Common/ContactUsCommand.cs b/src/Web/Grand.Web/Commands/Models/Contact/ContactUsCommand.cssimilarity index 82%rename from src/Web/Grand.Web/Commands/Models/Common/ContactUsCommand.csrename to src/Web/Grand.Web/Commands/Models/Contact/ContactUsCommand.csindex deb504d81..c1ad157eb 100644--- a/src/Web/Grand.Web/Commands/Models/Common/ContactUsCommand.cs+++ b/src/Web/Grand.Web/Commands/Models/Contact/ContactUsCommand.cs@@ -1,10 +1,10 @@using Grand.Domain.Customers;using Grand.Domain.Localization;using Grand.Domain.Stores;-using Grand.Web.Models.Common;+using Grand.Web.Models.Contact;using MediatR;-namespace Grand.Web.Commands.Models.Common+namespace Grand.Web.Commands.Models.Contact{public class ContactUsCommand : IRequest<ContactUsModel>{diff --git a/src/Web/Grand.Web/Commands/Models/Contact/ContactUsSendCommand.cs b/src/Web/Grand.Web/Commands/Models/Contact/ContactUsSendCommand.csnew file mode 100644index 000000000..2be8497dc--- /dev/null+++ b/src/Web/Grand.Web/Commands/Models/Contact/ContactUsSendCommand.cs@@ -0,0 +1,11 @@+using Grand.Web.Models.Contact;+using MediatR;++namespace Grand.Web.Commands.Models.Contact+{+ public class ContactUsSendCommand : IRequest<ContactUsModel>+ {+ public ContactUsModel Model { get; set; }+ public string IpAddress { get; set; }+ }+}diff --git a/src/Web/Grand.Web/Commands/Models/Vendors/ContactVendorSendCommand.cs b/src/Web/Grand.Web/Commands/Models/Vendors/ContactVendorSendCommand.csindex a0571b695..7cd21cde0 100644--- a/src/Web/Grand.Web/Commands/Models/Vendors/ContactVendorSendCommand.cs+++ b/src/Web/Grand.Web/Commands/Models/Vendors/ContactVendorSendCommand.cs@@ -1,6 +1,6 @@using Grand.Domain.Stores;using Grand.Domain.Vendors;-using Grand.Web.Models.Common;+using Grand.Web.Models.Vendors;using MediatR;namespace Grand.Web.Commands.Models.Vendorsdiff --git a/src/Web/Grand.Web/Components/VendorContact.cs b/src/Web/Grand.Web/Components/VendorContact.csindex d07f8a7aa..7a5c2c0e0 100644--- a/src/Web/Grand.Web/Components/VendorContact.cs+++ b/src/Web/Grand.Web/Components/VendorContact.cs@@ -6,7 +6,7 @@ using Grand.Domain.Vendors;using Grand.Infrastructure;using Grand.Web.Common.Components;using Grand.Web.Common.Security.Captcha;-using Grand.Web.Models.Common;+using Grand.Web.Models.Vendors;using Microsoft.AspNetCore.Mvc;namespace Grand.Web.Componentsdiff --git a/src/Web/Grand.Web/Controllers/ContactController.cs b/src/Web/Grand.Web/Controllers/ContactController.csindex 69cb4d02a..3596812b3 100644--- a/src/Web/Grand.Web/Controllers/ContactController.cs+++ b/src/Web/Grand.Web/Controllers/ContactController.cs@@ -6,24 +6,22 @@ using Grand.Domain.Catalog;using Grand.Domain.Media;using Grand.Domain.Stores;using Grand.Infrastructure;-using Grand.Web.Commands.Models.Common;+using Grand.Web.Commands.Models.Contact;using Grand.Web.Common.Extensions;using Grand.Web.Common.Filters;-using Grand.Web.Common.Security.Captcha;using Grand.Web.Controllers;using Grand.Web.Events;-using Grand.Web.Models.Common;+using Grand.Web.Models.Contact;using MediatR;using Microsoft.AspNetCore.Mvc;-public class ContactController: BasePublicController+public class ContactController : BasePublicController{#region Fieldsprivate readonly ITranslationService _translationService;private readonly IWorkContext _workContext;private readonly IMediator _mediator;- private readonly CaptchaSettings _captchaSettings;#endregion@@ -32,13 +30,11 @@ public class ContactController: BasePublicControllerpublic ContactController(ITranslationService translationService,IWorkContext workContext,- IMediator mediator,- CaptchaSettings captchaSettings)+ IMediator mediator){_translationService = translationService;_workContext = workContext;_mediator = mediator;- _captchaSettings = captchaSettings;}#endregion@@ -64,63 +60,43 @@ public class ContactController: BasePublicControllerreturn View(model);}- [HttpPost, ActionName("ContactUs")]+ [HttpPost][AutoValidateAntiforgeryToken]- [ValidateCaptcha][ClosedStore(true)][DenySystemAccount]- public virtual async Task<IActionResult> ContactUsSend(+ public virtual async Task<IActionResult> ContactUs([FromServices] StoreInformationSettings storeInformationSettings,[FromServices] IPageService pageService,- ContactUsModel model, bool captchaValid)+ ContactUsModel model){if (storeInformationSettings.StoreClosed){- var closestorepage = await pageService.GetPageBySystemName("ContactUs");- if (closestorepage is not { AccessibleWhenStoreClosed: true })+ var closeStorePage = await pageService.GetPageBySystemName("ContactUs");+ if (closeStorePage is not { AccessibleWhenStoreClosed: true })return RedirectToRoute("StoreClosed");}- //validate CAPTCHA- if (_captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage && !captchaValid)- {- ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_translationService));- }-if (ModelState.IsValid){var result = await _mediator.Send(new ContactUsSendCommand {- CaptchaValid = captchaValid,Model = model,- Store = _workContext.CurrentStore,IpAddress = HttpContext?.Connection?.RemoteIpAddress?.ToString()});++ //notification+ await _mediator.Publish(new ContactUsEvent(_workContext.CurrentCustomer, result));- if (result.errors.Any())- {- foreach (var item in result.errors)- {- ModelState.AddModelError("", item);- }- }- else- {- //notification- await _mediator.Publish(new ContactUsEvent(_workContext.CurrentCustomer, result.model));-- model = result.model;- return View(model);- }+ return View(result);}- var model1 = await _mediator.Send(new ContactUsCommand {+ var modelReturn = await _mediator.Send(new ContactUsCommand {Customer = _workContext.CurrentCustomer,Language = _workContext.WorkingLanguage,Store = _workContext.CurrentStore,Model = model});- return View(model1);+ return View(modelReturn);}[HttpPost]@@ -188,7 +164,7 @@ public class ContactController: BasePublicController{return Json(new {success = false,- message = _translationService.GetResource("ShoppingCart.ValidationFileAllowed"),+ message = _translationService.GetResource("ContactUs.ValidationFileAllowed"),downloadGuid = Guid.Empty});}@@ -204,7 +180,7 @@ public class ContactController: BasePublicController//otherwise some browsers will pop-up a "Save As" dialog.return Json(new {success = false,- message = string.Format(_translationService.GetResource("ShoppingCart.MaximumUploadedFileSize"),+ message = string.Format(_translationService.GetResource("ContactUs.MaximumUploadedFileSize"),attribute.ValidationFileMaximumSize.Value),downloadGuid = Guid.Empty});diff --git a/src/Web/Grand.Web/Controllers/VendorController.cs b/src/Web/Grand.Web/Controllers/VendorController.csindex d2a370d99..df32120cd 100644--- a/src/Web/Grand.Web/Controllers/VendorController.cs+++ b/src/Web/Grand.Web/Controllers/VendorController.cs@@ -17,7 +17,6 @@ using Grand.Web.Common.Filters;using Grand.Web.Common.Security.Captcha;using Grand.Web.Extensions;using Grand.Web.Features.Models.Common;-using Grand.Web.Models.Common;using Grand.Web.Models.Vendors;using MediatR;using Microsoft.AspNetCore.Http;@@ -387,7 +386,7 @@ namespace Grand.Web.Controllersif (ModelState.IsValid){- model = await _mediator.Send(new ContactVendorSendCommand { Model = model, Vendor = vendor, Store = _workContext.CurrentStore, IpAddress = HttpContext.Connection?.RemoteIpAddress?.ToString() });+ model = await _mediator.Send(new ContactVendorSendCommand { Model = model, Vendor = vendor, Store = _workContext.CurrentStore, IpAddress = HttpContext.Connection.RemoteIpAddress?.ToString() });return Json(model);}diff --git a/src/Web/Grand.Web/Events/ContactUsEvent.cs b/src/Web/Grand.Web/Events/ContactUsEvent.csindex c93127ea5..04d0353c2 100644--- a/src/Web/Grand.Web/Events/ContactUsEvent.cs+++ b/src/Web/Grand.Web/Events/ContactUsEvent.cs@@ -1,5 +1,5 @@using Grand.Domain.Customers;-using Grand.Web.Models.Common;+using Grand.Web.Models.Contact;using MediatR;namespace Grand.Web.Eventsdiff --git a/src/Web/Grand.Web/Models/Common/ContactAttributeChangeModel.cs b/src/Web/Grand.Web/Models/Contact/ContactAttributeChangeModel.cssimilarity index 91%rename from src/Web/Grand.Web/Models/Common/ContactAttributeChangeModel.csrename to src/Web/Grand.Web/Models/Contact/ContactAttributeChangeModel.csindex 535421e7f..b4914a0ec 100644--- a/src/Web/Grand.Web/Models/Common/ContactAttributeChangeModel.cs+++ b/src/Web/Grand.Web/Models/Contact/ContactAttributeChangeModel.cs@@ -2,7 +2,7 @@using Grand.Web.Common.Models;using Microsoft.AspNetCore.Mvc;-namespace Grand.Web.Models.Common;+namespace Grand.Web.Models.Contact;public class ContactAttributeChangeModel{public ContactAttributeChangeModel()diff --git a/src/Web/Grand.Web/Models/Common/ContactUsModel.cs b/src/Web/Grand.Web/Models/Contact/ContactUsModel.cssimilarity index 95%rename from src/Web/Grand.Web/Models/Common/ContactUsModel.csrename to src/Web/Grand.Web/Models/Contact/ContactUsModel.csindex bcc94d00c..3ba0a7a7a 100644--- a/src/Web/Grand.Web/Models/Common/ContactUsModel.cs+++ b/src/Web/Grand.Web/Models/Contact/ContactUsModel.cs@@ -4,9 +4,10 @@ using Grand.Infrastructure.ModelBinding;using Grand.Infrastructure.Models;using Grand.Web.Common.Binders;using Grand.Web.Common.Models;+using Grand.Web.Models.Common;using Microsoft.AspNetCore.Mvc;-namespace Grand.Web.Models.Common+namespace Grand.Web.Models.Contact{public class ContactUsModel : BaseModel{@@ -34,6 +35,7 @@ namespace Grand.Web.Models.Commonpublic string Result { get; set; }public bool DisplayCaptcha { get; set; }+ public ICaptchaValidModel Captcha { get; set; } = new CaptchaModel();[ModelBinder(BinderType = typeof(CustomAttributesBinder))]public IList<CustomAttributeModel> Attributes { get; set; }diff --git a/src/Web/Grand.Web/Models/Common/ContactVendorModel.cs b/src/Web/Grand.Web/Models/Vendors/ContactVendorModel.cssimilarity index 96%rename from src/Web/Grand.Web/Models/Common/ContactVendorModel.csrename to src/Web/Grand.Web/Models/Vendors/ContactVendorModel.csindex ba56fdbb5..5628575d3 100644--- a/src/Web/Grand.Web/Models/Common/ContactVendorModel.cs+++ b/src/Web/Grand.Web/Models/Vendors/ContactVendorModel.cs@@ -2,7 +2,7 @@using Grand.Infrastructure.Models;using System.ComponentModel.DataAnnotations;-namespace Grand.Web.Models.Common+namespace Grand.Web.Models.Vendors{public class ContactVendorModel : BaseModel{diff --git a/src/Web/Grand.Web/Validators/Common/ContactUsValidator.cs b/src/Web/Grand.Web/Validators/Common/ContactUsValidator.csdeleted file mode 100644index be2e9c54b..000000000--- a/src/Web/Grand.Web/Validators/Common/ContactUsValidator.cs+++ /dev/null@@ -1,25 +0,0 @@-using FluentValidation;-using Grand.Business.Core.Interfaces.Common.Localization;-using Grand.Domain.Common;-using Grand.Infrastructure.Validators;-using Grand.Web.Models.Common;--namespace Grand.Web.Validators.Common-{- public class ContactUsValidator : BaseGrandValidator<ContactUsModel>- {- public ContactUsValidator(- IEnumerable<IValidatorConsumer<ContactUsModel>> validators,- ITranslationService translationService, CommonSettings commonSettings)- : base(validators)- {- RuleFor(x => x.Email).NotEmpty().WithMessage(translationService.GetResource("ContactUs.Email.Required"));- RuleFor(x => x.Email).EmailAddress().WithMessage(translationService.GetResource("Common.WrongEmail"));- RuleFor(x => x.FullName).NotEmpty().WithMessage(translationService.GetResource("ContactUs.FullName.Required"));- if (commonSettings.SubjectFieldOnContactUsForm)- {- RuleFor(x => x.Subject).NotEmpty().WithMessage(translationService.GetResource("ContactUs.Subject.Required"));- }- RuleFor(x => x.Enquiry).NotEmpty().WithMessage(translationService.GetResource("ContactUs.Enquiry.Required"));- }}-}\ No newline at end of filediff --git a/src/Web/Grand.Web/Validators/Contact/ContactUsValidator.cs b/src/Web/Grand.Web/Validators/Contact/ContactUsValidator.csnew file mode 100644index 000000000..a35a164cc--- /dev/null+++ b/src/Web/Grand.Web/Validators/Contact/ContactUsValidator.cs@@ -0,0 +1,167 @@+using FluentValidation;+using Grand.Business.Core.Extensions;+using Grand.Business.Core.Interfaces.Common.Localization;+using Grand.Business.Core.Interfaces.Marketing.Contacts;+using Grand.Domain.Catalog;+using Grand.Domain.Common;+using Grand.Infrastructure;+using Grand.Infrastructure.Models;+using Grand.Infrastructure.Validators;+using Grand.Web.Common.Security.Captcha;+using Grand.Web.Common.Validators;+using Grand.Web.Models.Contact;+using Microsoft.AspNetCore.Http;++namespace Grand.Web.Validators.Contact+{+ public class ContactUsValidator : BaseGrandValidator<ContactUsModel>+ {+ private readonly IContactAttributeParser _contactAttributeParser;+ private readonly ITranslationService _translationService;+ private readonly IContactAttributeService _contactAttributeService;+ private readonly IWorkContext _workContext;++ public ContactUsValidator(+ IEnumerable<IValidatorConsumer<ContactUsModel>> validators,+ IEnumerable<IValidatorConsumer<ICaptchaValidModel>> validatorsCaptcha,+ IContactAttributeParser contactAttributeParser,+ IContactAttributeService contactAttributeService,+ IWorkContext workContext,+ ITranslationService translationService, CommonSettings commonSettings,+ CaptchaSettings captchaSettings,+ IHttpContextAccessor contextAccessor, GoogleReCaptchaValidator googleReCaptchaValidator)+ : base(validators)+ {+ _contactAttributeParser = contactAttributeParser;+ _contactAttributeService = contactAttributeService;+ _translationService = translationService;+ _workContext = workContext;++ RuleFor(x => x.Email).NotEmpty().WithMessage(translationService.GetResource("ContactUs.Email.Required"));+ RuleFor(x => x.Email).EmailAddress().WithMessage(translationService.GetResource("Common.WrongEmail"));+ RuleFor(x => x.FullName).NotEmpty()+ .WithMessage(translationService.GetResource("ContactUs.FullName.Required"));+ if (commonSettings.SubjectFieldOnContactUsForm)+ {+ RuleFor(x => x.Subject).NotEmpty()+ .WithMessage(translationService.GetResource("ContactUs.Subject.Required"));+ }++ RuleFor(x => x.Enquiry).NotEmpty()+ .WithMessage(translationService.GetResource("ContactUs.Enquiry.Required"));++ if (captchaSettings.Enabled && captchaSettings.ShowOnContactUsPage)+ {+ RuleFor(x => x.Captcha).NotNull()+ .WithMessage(translationService.GetResource("Account.Captcha.Required"));+ ;+ RuleFor(x => x.Captcha)+ .SetValidator(new CaptchaValidator(validatorsCaptcha, contextAccessor, googleReCaptchaValidator));+ }++ RuleFor(x => x).CustomAsync(async (x, context, _) =>+ {+ var contactAttributeWarnings = await GetContactAttributesWarnings(x.Attributes.Select(z => new CustomAttribute { Key = z.Key, Value = z.Value }).ToList(), workContext.CurrentStore.Id);+ if (contactAttributeWarnings.Any())+ {+ foreach (var item in contactAttributeWarnings)+ {+ context.AddFailure(item);+ }+ }+ });+ }++ private async Task<IList<string>> GetContactAttributesWarnings(IList<CustomAttribute> customAttributes,+ string storeId)+ {+ var warnings = new List<string>();++ //selected attributes+ var attributes1 = await _contactAttributeParser.ParseContactAttributes(customAttributes);++ //existing contact attributes+ var attributes2 = await _contactAttributeService.GetAllContactAttributes(storeId);+ foreach (var a2 in attributes2)+ {+ var conditionMet = await _contactAttributeParser.IsConditionMet(a2, customAttributes);+ if (!a2.IsRequired ||+ ((!conditionMet.HasValue || !conditionMet.Value) && conditionMet.HasValue)) continue;+ var found = false;+ //selected checkout attributes+ foreach (var a1 in attributes1)+ {+ if (a1.Id != a2.Id) continue;+ var attributeValuesStr = customAttributes.Where(x => x.Key == a1.Id).Select(x => x.Value).ToList();+ foreach (var str1 in attributeValuesStr)+ if (!string.IsNullOrEmpty(str1.Trim()))+ {+ found = true;+ break;+ }+ }++ //if not found+ if (!found)+ {+ warnings.Add(+ !string.IsNullOrEmpty(a2.GetTranslation(a => a.TextPrompt, _workContext.WorkingLanguage.Id))+ ? a2.GetTranslation(a => a.TextPrompt, _workContext.WorkingLanguage.Id)+ : string.Format(_translationService.GetResource("ContactUs.SelectAttribute"),+ a2.GetTranslation(a => a.Name, _workContext.WorkingLanguage.Id)));+ }+ }++ //now validation rules++ //minimum length+ foreach (var ca in attributes2)+ {+ if (ca.ValidationMinLength.HasValue)+ {+ if (ca.AttributeControlType is AttributeControlType.TextBox+ or AttributeControlType.MultilineTextbox)+ {+ var conditionMet = await _contactAttributeParser.IsConditionMet(ca, customAttributes);+ if (ca.IsRequired && ((conditionMet.HasValue && conditionMet.Value) || !conditionMet.HasValue))+ {+ var valuesStr = customAttributes.Where(x => x.Key == ca.Id).Select(x => x.Value).ToList();+ var enteredText = valuesStr.FirstOrDefault();+ var enteredTextLength = string.IsNullOrEmpty(enteredText) ? 0 : enteredText.Length;++ if (ca.ValidationMinLength.Value > enteredTextLength)+ {+ warnings.Add(string.Format(+ _translationService.GetResource("ContactUs.TextboxMinimumLength"),+ ca.GetTranslation(a => a.Name, _workContext.WorkingLanguage.Id),+ ca.ValidationMinLength.Value));+ }+ }+ }+ }++ //maximum length+ if (!ca.ValidationMaxLength.HasValue) continue;+ {+ if (ca.AttributeControlType != AttributeControlType.TextBox &&+ ca.AttributeControlType != AttributeControlType.MultilineTextbox) continue;+ var conditionMet = await _contactAttributeParser.IsConditionMet(ca, customAttributes);+ if (!ca.IsRequired || ((!conditionMet.HasValue || !conditionMet.Value) && conditionMet.HasValue))+ continue;+ var valuesStr = customAttributes.Where(x => x.Key == ca.Id).Select(x => x.Value).ToList();+ var enteredText = valuesStr.FirstOrDefault();+ var enteredTextLength = string.IsNullOrEmpty(enteredText) ? 0 : enteredText.Length;++ if (ca.ValidationMaxLength.Value < enteredTextLength)+ {+ warnings.Add(string.Format(_translationService.GetResource("ContactUs.TextboxMaximumLength"),+ ca.GetTranslation(a => a.Name, _workContext.WorkingLanguage.Id),+ ca.ValidationMaxLength.Value));+ }+ }+ }++ return warnings;+ }+ }+}\ No newline at end of filediff --git a/src/Web/Grand.Web/Validators/Common/ContactVendorValidator.cs b/src/Web/Grand.Web/Validators/Contact/ContactVendorValidator.cssimilarity index 94%rename from src/Web/Grand.Web/Validators/Common/ContactVendorValidator.csrename to src/Web/Grand.Web/Validators/Contact/ContactVendorValidator.csindex 81bc1e22d..f21fdb61f 100644--- a/src/Web/Grand.Web/Validators/Common/ContactVendorValidator.cs+++ b/src/Web/Grand.Web/Validators/Contact/ContactVendorValidator.cs@@ -2,9 +2,9 @@using Grand.Business.Core.Interfaces.Common.Localization;using Grand.Domain.Common;using Grand.Infrastructure.Validators;-using Grand.Web.Models.Common;+using Grand.Web.Models.Vendors;-namespace Grand.Web.Validators.Common+namespace Grand.Web.Validators.Contact{public class ContactVendorValidator : BaseGrandValidator<ContactVendorModel>{diff --git a/src/Web/Grand.Web/Views/Contact/ContactUs.cshtml b/src/Web/Grand.Web/Views/Contact/ContactUs.cshtmlnew file mode 100644index 000000000..318b4007c--- /dev/null+++ b/src/Web/Grand.Web/Views/Contact/ContactUs.cshtml@@ -0,0 +1,95 @@+@model ContactUsModel+@inject IPageHeadBuilder pagebuilder+@{+ Layout = "_SingleColumn";++ //title+ pagebuilder.AddTitleParts(Loc["Title.ContactUs"]);+}+<div class="page contact-page">+ <h1 class="generalTitle h2">@Loc["Title.ContactUs"]</h1>+ <div class="generalMarginSupporter text-left">+ @await Component.InvokeAsync("PageBlock", new { systemName = "ContactUs" })+ @await Component.InvokeAsync("Widget", new { widgetZone = "contactus_top" })+ @if (Model.SuccessfullySent)+ {+ <div class="alert alert-info">+ @Model.Result+ </div>+ }+ else+ {+ <validation-observer v-slot="{ handleSubmit }">+ <form asp-route="ContactUs" method="post" id="contactus-form" ref="form" v-on:submit.prevent="handleSubmit(formSubmit)">+ <div asp-validation-summary="ModelOnly" class="message-error"></div>+ <div class="form-fields">+ <div class="form-group">+ <validation-provider tag="div" rules="required" name="FullName" v-slot="{ errors, classes }">+ <label asp-for="FullName" class="col-form-label">@Loc["ContactUs.FullName"]:</label>+ <span class="required">*</span>+ <input asp-for="FullName" v-model="contactus.FullName" placeholder="@Loc["ContactUs.FullName.Hint"]" v-bind:class="[classes , 'form-control']" />+ <span class="field-validation-error">{{ errors[0] }}</span>+ <span asp-validation-for="FullName"></span>+ </validation-provider>+ </div>+ <div class="form-group">+ <validation-provider tag="div" rules="required|email" name="Email" v-slot="{ errors, classes }">+ <label asp-for="Email" class="col-form-label">@Loc["ContactUs.Email"]:</label>+ <span class="required">*</span>+ <input asp-for="Email" v-model="contactus.Email" placeholder="@Loc["ContactUs.Email.Hint"]" v-bind:class="[classes , 'form-control']" />+ <span class="field-validation-error">{{ errors[0] }}</span>+ <span asp-validation-for="Email"></span>+ </validation-provider>+ </div>+ @if (Model.SubjectEnabled)+ {+ <div class="form-group">+ <validation-provider tag="div" rules="required" name="Subject" v-slot="{ errors, classes }">+ <label asp-for="Subject" class="col-form-label">@Loc["ContactUs.Subject"]:</label>+ <span class="required">*</span>+ <input asp-for="Subject" v-model="contactus.Subject" placeholder="@Loc["ContactUs.Subject.Hint"]" v-bind:class="[classes , 'form-control']" />+ <span class="field-validation-error">{{ errors[0] }}</span>+ <span asp-validation-for="Subject"></span>+ </validation-provider>+ </div>+ }+ <div class="form-group">+ <validation-provider tag="div" rules="required" name="Enquiry" v-slot="{ errors, classes }">+ <label asp-for="Enquiry" class="col-form-label">@Loc["ContactUs.Enquiry"]:</label>+ <span class="required">*</span>+ <textarea asp-for="Enquiry" v-model="contactus.Enquiry" placeholder="@Loc["ContactUs.Enquiry.Hint"]" v-bind:class="[classes , 'form-control']" rows="4"></textarea>+ <span class="field-validation-error">{{ errors[0] }}</span>+ <span asp-validation-for="Enquiry"></span>+ </validation-provider>+ </div>+ </div>+ <partial name="Partials/ContactAttributes" model="Model.ContactAttributes" />+ @if (Model.DisplayCaptcha)+ {+ <div class="captcha-box">+ <captcha />+ </div>+ }+ <div class="buttons mt-1 mb-1">+ <input type="submit" name="send-email" class="btn btn-info contact-us-button" value="@Loc["ContactUs.Button"]" />+ </div>+ </form>+ </validation-observer>+ <script asp-location="Footer" asp-order="300">+ var contactus = new Vue({+ data: () => ({+ @{+ <text>+ FullName: '@Html.Raw(Model.FullName)',+ Email: '@Html.Raw(Model.Email)',+ Subject: '@Html.Raw(Model.Subject)',+ Enquiry: '@Html.Raw(Model.Enquiry)',+ </text>+ }+ })+ });+ </script>+ }+ @await Component.InvokeAsync("Widget", new { widgetZone = "contactus_bottom" })+ </div>+</div>\ No newline at end of filediff --git a/src/Web/Grand.Web/Views/Contact/Partials/ContactAttributes.cshtml b/src/Web/Grand.Web/Views/Contact/Partials/ContactAttributes.cshtmlnew file mode 100644index 000000000..918fb1ed8--- /dev/null+++ b/src/Web/Grand.Web/Views/Contact/Partials/ContactAttributes.cshtml@@ -0,0 +1,259 @@+@using Grand.Business.Core.Interfaces.Storage+@using Grand.Domain.Media+@model IList<ContactUsModel.ContactAttributeModel>+@inject IDownloadService downloadService++@if (Model.Any())+{+ var attributeChangeScriptsBuilder = new StringBuilder();+ <div class="form-group contact-attributes">+ @foreach (var attribute in Model)+ {+ var controlId = $"contact_attribute_{attribute.Id}";+ var controlName = $"attributes[{attribute.Id}]";+ var textPrompt = !string.IsNullOrEmpty(attribute.TextPrompt) ? attribute.TextPrompt : attribute.Name;+ <div id="@($"contact_attribute_label_{attribute.Id}")" class="col-12 px-0">+ <span class="col-form-label text-prompt">+ @textPrompt+ </span>+ @if (attribute.IsRequired)+ {+ <span class="required">*</span>+ }++ @switch (attribute.AttributeControlType)+ {+ case AttributeControlType.TextBox:+ {+ <label for="@(controlId)" class="sr-only">"@(controlId)</label>+ <input name="@(controlName)" type="text" class="form-control textbox" id="@(controlId)" value="@(attribute.DefaultValue)" />+ }+ break;+ case AttributeControlType.DropdownList:+ {+ <label for="@(controlId)" class="sr-only">"@(controlId)</label>+ <select id="@(controlId)" class="form-control custom-select" name="@(controlName)">+ @if (!attribute.IsRequired)+ {+ <option value="">---</option>+ }+ @foreach (var attributeValue in attribute.Values)+ {+ var attributeName = attributeValue.Name;+ <option selected="@attributeValue.IsPreSelected" value="@(attributeValue.Id)">@attributeName</option>+ }+ </select>+ attributeChangeScriptsBuilder.Append($"document.querySelector('#{controlId}').addEventListener('change',function(){{contactAttributeChange();}});\n");+ }+ break;+ case AttributeControlType.RadioList:+ {+ <ul class="option-list pl-0">+ @foreach (var attributeValue in attribute.Values)+ {+ var attributeName = attributeValue.Name;+ <li>+ <fieldset>+ <legend class="sr-only">+ @(controlId)+ </legend>+ <label class="custom-control custom-radio">+ <input class="custom-control-input" id="@(controlId)_@(attributeValue.Id)" type="radio" name="@(controlName)" value="@attributeValue.Id" checked="@attributeValue.IsPreSelected" />+ <span class="custom-control-label"></span>+ <span class="custom-control-description" for="@(controlId)_@(attributeValue.Id)">@attributeName</span>+ </label>++ </fieldset>+ </li>+ attributeChangeScriptsBuilder.Append($"document.querySelector('#{controlId}_{attributeValue.Id}').addEventListener('click',function(){{contactAttributeChange();}});\n");+ }+ </ul>+ }+ break;+ case AttributeControlType.Checkboxes:+ case AttributeControlType.ReadonlyCheckboxes:+ {+ <fieldset>+ <ul class="option-list pl-0">+ @foreach (var attributeValue in attribute.Values.OrderBy(x => x.DisplayOrder))+ {+ var attributeName = attributeValue.Name;+ <li>+ <label class="custom-control custom-checkbox">+ <input class="custom-control-input" id="@(controlId)_@(attributeValue.Id)" type="checkbox" name="@(controlName)" value="@(attributeValue.Id)" checked="@(attributeValue.IsPreSelected)" @(attribute.AttributeControlType == AttributeControlType.ReadonlyCheckboxes ? Html.Raw(" disabled=\"disabled\"") : null) />+ <span class="custom-control-label"></span>+ <span class="custom-control-description" for="@(controlId)_@(attributeValue.Id)">@attributeName</span>+ </label>+ </li>+ attributeChangeScriptsBuilder.Append($"document.querySelector('#{controlId}_{attributeValue.Id}').addEventListener('click',function(){{contactAttributeChange();}});\n");+ }+ </ul>+ </fieldset>+ }+ break;++ case AttributeControlType.MultilineTextbox:+ {+ <textarea id="@(controlId)" name="@(controlId)">@(attribute.DefaultValue)</textarea>+ }+ break;+ case AttributeControlType.Datepicker:+ {+ <date-picker-dropdown control-day="@($"attributes[{attribute.Id}_day]")"+ control-month="@($"attributes[{attribute.Id}_month]")"+ control-year="@($"attributes[{attribute.Id}_year]")"+ begin-year="@(DateTime.Now.Year)"+ end-year="@(DateTime.Now.Year+1)"+ selected-day="attribute.SelectedDay ?? 0"+ selected-month="attribute.SelectedMonth ?? 0"+ selected-year="attribute.SelectedYear ?? 0"+ PartialViewName="Partials/DatePickerDropDowns"+ class="input-group" />+ }+ break;+ case AttributeControlType.FileUpload:+ {+ Download download = null;+ if (!string.IsNullOrEmpty(attribute.DefaultValue))+ {+ download = await downloadService.GetDownloadByGuid(new Guid(attribute.DefaultValue));+ }++ //ex. ['jpg', 'jpeg', 'png', 'gif'] or []+ var allowedFileExtensions = string.Join(", ", attribute.AllowedFileExtensions.Select(x => "" + x.Trim() + "").ToList());++ if (download != null)+ {+ <input id="@(controlId)" name="@(controlName)" type="hidden" value="@download.DownloadGuid" />+ }+ else+ {+ <input id="@(controlId)" name="@(controlName)" type="hidden" />+ }+ <template>+ <b-form-file accept="@Html.Raw(allowedFileExtensions)" type="file" id="qqfile" name="qqfile" onchange="uploadFile(this)" />+ </template>+ <input class="hidden-upload-input" type="hidden" onchange="contactAttributeChange()" id="@(controlId)" name="@(controlName)" />+ <div id="download-message" class="alert my-2" style="display:none;"></div>+ <a id="@(controlId)downloadurl'" class="download-file btn btn-outline-info" style="display:none;">+ Download+ </a>+ <script asp-location="Footer">+ function uploadFile(e) {+ var formData = new FormData();+ formData.append("image", qqfile.files[0]);+ axios.post('@(Url.RouteUrl("UploadFileContactAttribute", new {attributeId = attribute.Id}))', formData, {+ headers: {+ 'Content-Type': 'multipart/form-data'+ }+ }).then(function (response) {+ if (response.data.success) {+ var message = response.data.message;+ var downloadGuid = response.data.downloadGuid;+ var downloadUrl = response.data.downloadUrl;+ var downloadBtn = document.querySelector('.download-file');+ var messageContainer = document.getElementById('download-message');++ document.querySelector('.hidden-upload-input').setAttribute('value', downloadGuid);+ contactAttributeChange();++ messageContainer.style.display = "block";+ messageContainer.classList.remove('alert-danger');+ messageContainer.classList.add('alert-info');+ messageContainer.innerText = message;++ downloadBtn.style.display = "inline-block";+ downloadBtn.setAttribute('href', downloadUrl);++ } else {+ var message = response.data.message;+ var messageContainer = document.getElementById('download-message');+ messageContainer.style.display = "block";+ messageContainer.classList.remove('alert-info');+ messageContainer.classList.add('alert-danger');+ messageContainer.innerText = message;+ contactAttributeChange();+ }+ })+ }+ </script>+ }+ break;+ case AttributeControlType.ColorSquares:+ {+ <ul class="option-list color-squares w-100 d-inline-flex flex-wrap px-0 mb-0" id="color-squares-@(attribute.Id)">+ @foreach (var attributeValue in attribute.Values)+ {+ var attributeName = attributeValue.Name;+ <li class="mr-1 p-0" @(attributeValue.IsPreSelected ? Html.Raw(" class=\"selected-value border border-primary\"") : null)>+ <label for="@(controlId)_@(attributeValue.Id)" class="mb-0">+ <input id="@(controlId)_@(attributeValue.Id)" type="radio" name="@(controlName)" value="@attributeValue.Id" checked="@attributeValue.IsPreSelected" />+ <span class="color-container" title="@attributeName">+ <span class="color" style="background-color:@(attributeValue.ColorSquaresRgb);"> </span>+ </span>+ </label>+ </li>+ attributeChangeScriptsBuilder.Append($"document.querySelector('#{controlId}_{attributeValue.Id}').addEventListener('click',function(){{contactAttributeChange();}});\n");+ }+ </ul>+ <script asp-location="Footer">+ document.addEventListener("DOMContentLoaded", function () {+ var btnContainer = document.querySelector(".contact-attributes #color-squares-@(attribute.Id)");+ var btns = btnContainer.getElementsByTagName("li");+ for (var i = 0; i < btns.length; i++) {+ btns[i].addEventListener("click", function () {+ (document.querySelector('.selected-value')) ? document.querySelector('.selected-value').classList.remove('selected-value') : '';+ this.classList.add('selected-value');+ });+ }+ });+ </script>+ }+ break;+ case AttributeControlType.ImageSquares:+ {+ //not support attribute type+ }+ break;+ }+ </div>+ }+ </div>++ <script asp-location="Footer">+ document.addEventListener("DOMContentLoaded", function () {+ contactAttributeChange();+ @Html.Raw(attributeChangeScriptsBuilder.ToString())+ });+ function contactAttributeChange() {+ var form = document.querySelector('#contactus-form');+ var data = new FormData(form);+ axios({+ method: 'post',+ data: data,+ url: '@Html.Raw(Url.Action("contactattributechange", "contact"))',+ }).then(function (response) {+ if (response.data.enabledattributeids) {+ for (var i = 0; i < response.data.enabledattributeids.length; i++) {+ if (document.querySelector('#contact_attribute_label_' + response.data.enabledattributeids[i])) {+ document.querySelector('#contact_attribute_label_' + response.data.enabledattributeids[i]).style.display = 'block';+ }+ if (document.querySelector('#contact_attribute_input_' + response.data.enabledattributeids[i])) {+ document.querySelector('#contact_attribute_input_' + response.data.enabledattributeids[i]).style.display = 'block';+ }+ }+ }+ if (response.data.disabledattributeids) {+ for (var i = 0; i < response.data.disabledattributeids.length; i++) {+ if (document.querySelector('#contact_attribute_label_' + response.data.disabledattributeids[i])) {+ document.querySelector('#contact_attribute_label_' + response.data.disabledattributeids[i]).style.display = 'none';+ }+ if (document.querySelector('#contact_attribute_input_' + response.data.disabledattributeids[i])) {+ document.querySelector('#contact_attribute_input_' + response.data.disabledattributeids[i]).style.display = 'none';+ }+ }+ }+ })+ }+ </script>+}\ No newline at end of filediff --git a/src/Web/Grand.Web/Views/_ViewImports.cshtml b/src/Web/Grand.Web/Views/_ViewImports.cshtmlindex 155c0214c..ec961dabf 100644--- a/src/Web/Grand.Web/Views/_ViewImports.cshtml+++ b/src/Web/Grand.Web/Views/_ViewImports.cshtml@@ -19,6 +19,7 @@@using Grand.Web.Extensions@using Grand.Web.Models.Blogs@using Grand.Web.Models.Catalog+@using Grand.Web.Models.Contact@using Grand.Web.Models.Checkout@using Grand.Web.Models.Cms@using Grand.Web.Models.Common