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 possibility to add a custom name for addresses #214

KrzysztofPajakc973de0ecd32
diff --git a/src/Business/Grand.Business.Messages/DotLiquidDrops/LiquidOrder.cs b/src/Business/Grand.Business.Messages/DotLiquidDrops/LiquidOrder.cs
index 0383fb30f..dad1a8f11 100644
--- a/src/Business/Grand.Business.Messages/DotLiquidDrops/LiquidOrder.cs
+++ b/src/Business/Grand.Business.Messages/DotLiquidDrops/LiquidOrder.cs
@@ -66,6 +66,10 @@ namespace Grand.Business.Messages.DotLiquidDrops
get { return _order.BillingAddress.Email; }
}
+ public string BillingAddressName {
+ get { return _order.BillingAddress.Name; }
+ }
+
public string BillingFirstName
{
get { return _order.BillingAddress.FirstName; }
@@ -137,6 +141,10 @@ namespace Grand.Business.Messages.DotLiquidDrops
get { return _order.ShippingOptionAttributeDescription; }
}
+ public string ShippingAddressName {
+ get { return _order.ShippingAddress != null ? _order.ShippingAddress.Name : ""; }
+ }
+
public string ShippingFirstName
{
get { return _order.ShippingAddress != null ? _order.ShippingAddress.FirstName : ""; }
diff --git a/src/Business/Grand.Business.System/Services/Installation/InstallDataSettings.cs b/src/Business/Grand.Business.System/Services/Installation/InstallDataSettings.cs
index 2e7d8bc9f..511d48815 100644
--- a/src/Business/Grand.Business.System/Services/Installation/InstallDataSettings.cs
+++ b/src/Business/Grand.Business.System/Services/Installation/InstallDataSettings.cs
@@ -313,6 +313,7 @@ namespace Grand.Business.System.Services.Installation
});
await _settingService.SaveSetting(new AddressSettings {
+ NameEnabled = false,
CompanyEnabled = true,
StreetAddressEnabled = true,
StreetAddressRequired = true,
diff --git a/src/Core/Grand.Domain/Common/Address.cs b/src/Core/Grand.Domain/Common/Address.cs
index a44f7494f..cd4452745 100644
--- a/src/Core/Grand.Domain/Common/Address.cs
+++ b/src/Core/Grand.Domain/Common/Address.cs
@@ -10,6 +10,11 @@ namespace Grand.Domain.Common
Attributes = new List<CustomAttribute>();
}
+ /// <summary>
+ /// Gets or sets the name of address
+ /// </summary>
+ public string Name { get; set; }
+
/// <summary>
/// Gets or sets the first name
/// </summary>
diff --git a/src/Core/Grand.Domain/Common/AddressSettings.cs b/src/Core/Grand.Domain/Common/AddressSettings.cs
index d6a6a22b2..93580d960 100644
--- a/src/Core/Grand.Domain/Common/AddressSettings.cs
+++ b/src/Core/Grand.Domain/Common/AddressSettings.cs
@@ -4,6 +4,11 @@ namespace Grand.Domain.Common
{
public class AddressSettings : ISettings
{
+ /// <summary>
+ /// Gets or sets a value indicating whether 'Name' is enabled
+ /// </summary>
+ public bool NameEnabled { get; set; }
+
/// <summary>
/// Gets or sets a value indicating whether 'Company' is enabled
/// </summary>
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Setting/Customer.TabAddressFormFields.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Setting/Customer.TabAddressFormFields.cshtml
index 694a0acdc..22c38e8ee 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Setting/Customer.TabAddressFormFields.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Setting/Customer.TabAddressFormFields.cshtml
@@ -88,6 +88,18 @@
@Loc["Admin.Settings.Customer.AddressFormFields.Description"]
</div>
</div>
+ <div class="form-group">
+ <div class="col-8 col-md-4 col-sm-4 text-right">
+ <admin-label asp-for="AddressSettings.NameEnabled" 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="AddressSettings.NameEnabled" />
+ <div class="control__indicator"></div>
+ </label>
+ <span asp-validation-for="AddressSettings.NameEnabled"></span>
+ </div>
+ </div>
<div class="form-group">
<div class="col-8 col-md-4 col-sm-4 text-right">
<admin-label asp-for="AddressSettings.AddressTypeEnabled" class="control-label" />
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/Address.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/Address.cshtml
index 19b615ca1..3229e64d3 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/Address.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/EditorTemplates/Address.cshtml
@@ -54,6 +54,16 @@
<div class="form-horizontal">
<div class="form-body">
+ @if (Model.NameEnabled)
+ {
+ <div class="form-group">
+ <admin-label asp-for="Name" />
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="Name" />
+ <span asp-validation-for="Name"></span>
+ </div>
+ </div>
+ }
@if (Model.FirstNameEnabled)
{
<div class="form-group">
diff --git a/src/Web/Grand.Web.Admin/Mapper/AddressProfile.cs b/src/Web/Grand.Web.Admin/Mapper/AddressProfile.cs
index 521b61220..f1725610f 100644
--- a/src/Web/Grand.Web.Admin/Mapper/AddressProfile.cs
+++ b/src/Web/Grand.Web.Admin/Mapper/AddressProfile.cs
@@ -15,6 +15,7 @@ namespace Grand.Web.Admin.Mapper
.ForMember(dest => dest.FormattedCustomAddressAttributes, mo => mo.Ignore())
.ForMember(dest => dest.AvailableCountries, mo => mo.Ignore())
.ForMember(dest => dest.AvailableStates, mo => mo.Ignore())
+ .ForMember(dest => dest.NameEnabled, mo => mo.Ignore())
.ForMember(dest => dest.FirstNameEnabled, mo => mo.Ignore())
.ForMember(dest => dest.FirstNameRequired, mo => mo.Ignore())
.ForMember(dest => dest.LastNameEnabled, mo => mo.Ignore())
diff --git a/src/Web/Grand.Web.Admin/Models/Common/AddressModel.cs b/src/Web/Grand.Web.Admin/Models/Common/AddressModel.cs
index c59d5fc21..0f21e0164 100644
--- a/src/Web/Grand.Web.Admin/Models/Common/AddressModel.cs
+++ b/src/Web/Grand.Web.Admin/Models/Common/AddressModel.cs
@@ -16,16 +16,16 @@ namespace Grand.Web.Admin.Models.Common
CustomAddressAttributes = new List<AddressAttributeModel>();
}
- [GrandResourceDisplayName("Admin.Address.Fields.FirstName")]
+ [GrandResourceDisplayName("Admin.Address.Fields.AddressName")]
+ public string Name { get; set; }
+ [GrandResourceDisplayName("Admin.Address.Fields.FirstName")]
public string FirstName { get; set; }
[GrandResourceDisplayName("Admin.Address.Fields.LastName")]
-
public string LastName { get; set; }
[GrandResourceDisplayName("Admin.Address.Fields.Email")]
-
public string Email { get; set; }
[GrandResourceDisplayName("Admin.Address.Fields.Company")]
@@ -39,34 +39,27 @@ namespace Grand.Web.Admin.Models.Common
public string CountryId { get; set; }
[GrandResourceDisplayName("Admin.Address.Fields.Country")]
-
public string CountryName { get; set; }
[GrandResourceDisplayName("Admin.Address.Fields.StateProvince")]
public string StateProvinceId { get; set; }
[GrandResourceDisplayName("Admin.Address.Fields.StateProvince")]
-
public string StateProvinceName { get; set; }
[GrandResourceDisplayName("Admin.Address.Fields.City")]
-
public string City { get; set; }
[GrandResourceDisplayName("Admin.Address.Fields.Address1")]
-
public string Address1 { get; set; }
[GrandResourceDisplayName("Admin.Address.Fields.Address2")]
-
public string Address2 { get; set; }
[GrandResourceDisplayName("Admin.Address.Fields.ZipPostalCode")]
-
public string ZipPostalCode { get; set; }
[GrandResourceDisplayName("Admin.Address.Fields.PhoneNumber")]
-
public string PhoneNumber { get; set; }
[GrandResourceDisplayName("Admin.Address.Fields.FaxNumber")]
@@ -88,7 +81,7 @@ namespace Grand.Web.Admin.Models.Common
public IList<SelectListItem> AvailableStates { get; set; }
-
+ public bool NameEnabled { get; set; }
public bool FirstNameEnabled { get; set; }
public bool FirstNameRequired { get; set; }
public bool LastNameEnabled { get; set; }
diff --git a/src/Web/Grand.Web.Admin/Models/Settings/CustomerSettingsModel.cs b/src/Web/Grand.Web.Admin/Models/Settings/CustomerSettingsModel.cs
index 62664735f..c7a168375 100644
--- a/src/Web/Grand.Web.Admin/Models/Settings/CustomerSettingsModel.cs
+++ b/src/Web/Grand.Web.Admin/Models/Settings/CustomerSettingsModel.cs
@@ -194,6 +194,8 @@ namespace Grand.Web.Admin.Models.Settings
public partial class AddressSettingsModel : BaseModel
{
+ [GrandResourceDisplayName("Admin.Settings.Customer.AddressFormFields.NameEnabled")]
+ public bool NameEnabled { get; set; }
[GrandResourceDisplayName("Admin.Settings.Customer.AddressFormFields.AddressTypeEnabled")]
public bool AddressTypeEnabled { get; set; }
diff --git a/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs b/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
index a36ff8d22..8f253d023 100644
--- a/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/CustomerViewModelService.cs
@@ -1177,6 +1177,7 @@ namespace Grand.Web.Admin.Services
if (model.Address == null)
model.Address = new AddressModel();
+ model.Address.NameEnabled = true;
model.Address.FirstNameEnabled = true;
model.Address.FirstNameRequired = true;
model.Address.LastNameEnabled = true;
diff --git a/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs b/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs
index cdbab6b48..5e52629f9 100644
--- a/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/OrderViewModelService.cs
@@ -603,6 +603,7 @@ namespace Grand.Web.Admin.Services
model.BillingAddress = await order.BillingAddress.ToModel(_countryService);
model.BillingAddress.FormattedCustomAddressAttributes = await _addressAttributeParser.FormatAttributes(_workContext.WorkingLanguage, order.BillingAddress.Attributes);
+ model.BillingAddress.NameEnabled = true;
model.BillingAddress.FirstNameEnabled = true;
model.BillingAddress.FirstNameRequired = true;
model.BillingAddress.LastNameEnabled = true;
@@ -641,6 +642,7 @@ namespace Grand.Web.Admin.Services
{
model.ShippingAddress = await order.ShippingAddress.ToModel(_countryService);
model.ShippingAddress.FormattedCustomAddressAttributes = await _addressAttributeParser.FormatAttributes(_workContext.WorkingLanguage, order.ShippingAddress.Attributes);
+ model.ShippingAddress.NameEnabled = true;
model.ShippingAddress.FirstNameEnabled = true;
model.ShippingAddress.FirstNameRequired = true;
model.ShippingAddress.LastNameEnabled = true;
@@ -900,6 +902,7 @@ namespace Grand.Web.Admin.Services
Address = await address.ToModel(_countryService)
};
model.Address.Id = address.Id;
+ model.Address.NameEnabled = true;
model.Address.FirstNameEnabled = true;
model.Address.FirstNameRequired = true;
model.Address.LastNameEnabled = true;
diff --git a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
index e2e7e02b9..1fc80dc89 100644
--- a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
+++ b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
@@ -1275,6 +1275,9 @@
<Resource Name="Address.Fields.Address2.Required">
<Value>Address 2 is required.</Value>
</Resource>
+ <Resource Name="Address.Fields.AddressName">
+ <Value>Address name</Value>
+ </Resource>
<Resource Name="Address.Fields.Addresstype">
<Value>Address type</Value>
</Resource>
@@ -1503,6 +1506,9 @@
<Resource Name="Admin.Address.Fields.Address2.Required">
<Value>Address 2 is required.</Value>
</Resource>
+ <Resource Name="Admin.Address.Fields.AddressName">
+ <Value>Address name</Value>
+ </Resource>
<Resource Name="Admin.Address.Fields.City">
<Value>City</Value>
</Resource>
@@ -10924,6 +10930,9 @@
<Resource Name="Admin.Settings.Customer.AddressFormFields.FaxRequired">
<Value>'Fax number' required</Value>
</Resource>
+ <Resource Name="Admin.Settings.Customer.AddressFormFields.NameEnabled">
+ <Value>'Address name' enabled</Value>
+ </Resource>
<Resource Name="Admin.Settings.Customer.AddressFormFields.NoteEnabled">
<Value>'Note' enabled</Value>
</Resource>
diff --git a/src/Web/Grand.Web/Extensions/MappingExtensions.cs b/src/Web/Grand.Web/Extensions/MappingExtensions.cs
index fe79cad1a..548109ccf 100644
--- a/src/Web/Grand.Web/Extensions/MappingExtensions.cs
+++ b/src/Web/Grand.Web/Extensions/MappingExtensions.cs
@@ -168,6 +168,9 @@ namespace Grand.Web.Extensions
if (trimFields)
{
+
+ if (model.Name != null)
+ model.Name = model.Name.Trim();
if (model.FirstName != null)
model.FirstName = model.FirstName.Trim();
if (model.LastName != null)
@@ -191,6 +194,7 @@ namespace Grand.Web.Extensions
if (model.FaxNumber != null)
model.FaxNumber = model.FaxNumber.Trim();
}
+ destination.Name = model.Name;
destination.FirstName = model.FirstName;
destination.LastName = model.LastName;
destination.Email = model.Email;
diff --git a/src/Web/Grand.Web/Features/Handlers/Common/GetAddressModelHandler.cs b/src/Web/Grand.Web/Features/Handlers/Common/GetAddressModelHandler.cs
index 98a37a297..c9260b5fc 100644
--- a/src/Web/Grand.Web/Features/Handlers/Common/GetAddressModelHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Common/GetAddressModelHandler.cs
@@ -75,6 +75,7 @@ namespace Grand.Web.Features.Handlers.Common
if (!excludeProperties && address != null)
{
model.Id = address.Id;
+ model.Name = address.Name;
model.FirstName = address.FirstName;
model.LastName = address.LastName;
model.Email = address.Email;
@@ -154,6 +155,7 @@ namespace Grand.Web.Features.Handlers.Common
}
//form fields
+ model.NameEnabled = _addressSettings.NameEnabled;
model.CompanyEnabled = _addressSettings.CompanyEnabled;
model.CompanyRequired = _addressSettings.CompanyRequired;
model.VatNumberEnabled = _addressSettings.VatNumberEnabled;
diff --git a/src/Web/Grand.Web/Models/Common/AddressModel.cs b/src/Web/Grand.Web/Models/Common/AddressModel.cs
index f233a2088..5ad447498 100644
--- a/src/Web/Grand.Web/Models/Common/AddressModel.cs
+++ b/src/Web/Grand.Web/Models/Common/AddressModel.cs
@@ -15,8 +15,14 @@ namespace Grand.Web.Models.Common
CustomAddressAttributes = new List<AddressAttributeModel>();
}
+ public bool NameEnabled { get; set; }
+
+ [GrandResourceDisplayName("Address.Fields.AddressName")]
+ public string Name { get; set; }
+
[GrandResourceDisplayName("Address.Fields.FirstName")]
public string FirstName { get; set; }
+
[GrandResourceDisplayName("Address.Fields.LastName")]
public string LastName { get; set; }
[DataType(DataType.EmailAddress)]
diff --git a/src/Web/Grand.Web/Views/Shared/_CreateOrUpdateAddress.cshtml b/src/Web/Grand.Web/Views/Shared/_CreateOrUpdateAddress.cshtml
index 56a78ba8d..2abd04c60 100644
--- a/src/Web/Grand.Web/Views/Shared/_CreateOrUpdateAddress.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/_CreateOrUpdateAddress.cshtml
@@ -42,6 +42,13 @@
}
<input asp-for="Id" type="hidden" />
<div class="edit-address row">
+ @if (Model.NameEnabled)
+ {
+ <div class="form-group col-sm-12 col-md-12">
+ <label asp-for="Name" class="col-form-label">@Loc["Address.Fields.Name"]:</label>
+ <input asp-for="Name" v-model="createorupdateaddress@{@prefix}.Name" v-bind:class="['form-control']" />
+ </div>
+ }
<div class="form-group col-sm-12 col-md-6">
<validation-provider tag="div" rules="required" :name="'@prefix' + '.FirstName'" v-slot="{ errors, classes }">
<label asp-for="FirstName" class="col-form-label">@Loc["Address.Fields.FirstName"]:</label>
@@ -290,6 +297,7 @@
data: () => ({
@{
<text>
+ Name: '@Html.Raw(Model.Name)',
FirstName: '@Html.Raw(Model.FirstName)',
LastName: '@Html.Raw(Model.LastName)',
Company: '@Html.Raw(Model.Company)',