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 Message Templates management to Grand.Web.Store (#694)

Copilotd0af8c34b20f
diff --git a/Directory.Packages.props b/Directory.Packages.props
index 510f84898..1e7e528b7 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -3,69 +3,69 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
- <PackageVersion Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.4.0" />
+ <PackageVersion Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.5.0" />
<PackageVersion Include="ExcelMapper" Version="6.0.641" />
- <PackageVersion Include="Microsoft.AspNetCore.Http" Version="2.3.9" />
- <PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="10.0.7" />
+ <PackageVersion Include="Microsoft.AspNetCore.Http" Version="2.3.10" />
+ <PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="10.0.8" />
<PackageVersion Include="Microsoft.FeatureManagement.AspNetCore" Version="4.5.0" />
- <PackageVersion Include="Scalar.AspNetCore" Version="2.14.5" />
+ <PackageVersion Include="Scalar.AspNetCore" Version="2.14.14" />
<PackageVersion Include="Scryber.Core" Version="9.5.0" />
<PackageVersion Include="Scryber.Core.OpenType" Version="9.2.0" />
<PackageVersion Include="MailKit" Version="4.16.0" />
- <PackageVersion Include="AWSSDK.Core" Version="4.0.4" />
- <PackageVersion Include="AWSSDK.S3" Version="4.0.22.1" />
- <PackageVersion Include="Azure.Storage.Blobs" Version="12.27.0" />
+ <PackageVersion Include="AWSSDK.Core" Version="4.0.7.1" />
+ <PackageVersion Include="AWSSDK.S3" Version="4.0.23.3" />
+ <PackageVersion Include="Azure.Storage.Blobs" Version="12.28.0" />
<PackageVersion Include="SixLabors.ImageSharp" Version="3.1.12" />
<PackageVersion Include="SkiaSharp" Version="3.119.2" />
<PackageVersion Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="3.119.2" />
<PackageVersion Include="LiteDB" Version="5.0.21" />
- <PackageVersion Include="MongoDB.Bson" Version="3.8.0" />
- <PackageVersion Include="MongoDB.Driver" Version="3.8.0" />
+ <PackageVersion Include="MongoDB.Bson" Version="3.8.1" />
+ <PackageVersion Include="MongoDB.Driver" Version="3.8.1" />
<PackageVersion Include="DotLiquid" Version="2.3.197" />
<PackageVersion Include="FluentValidation.DependencyInjectionExtensions" Version="12.1.1" />
<PackageVersion Include="GoogleAuthenticator" Version="3.2.0" />
<PackageVersion Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="8.5.0" />
- <PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.7" />
- <PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="10.0.7" />
- <PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.7" />
- <PackageVersion Include="Microsoft.Extensions.DependencyModel" Version="10.0.7" />
+ <PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.8" />
+ <PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="10.0.8" />
+ <PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.8" />
+ <PackageVersion Include="Microsoft.Extensions.DependencyModel" Version="10.0.8" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.3.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="5.3.0" />
<PackageVersion Include="MediatR" Version="12.5.0" />
<PackageVersion Include="Scrutor" Version="7.0.0" />
- <PackageVersion Include="StackExchange.Redis" Version="2.12.14" />
+ <PackageVersion Include="StackExchange.Redis" Version="2.13.1" />
<PackageVersion Include="FluentValidation" Version="12.1.1" />
- <PackageVersion Include="Microsoft.AspNetCore.JsonPatch.SystemTextJson" Version="10.0.7" />
- <PackageVersion Include="Microsoft.AspNetCore.Authentication.Facebook" Version="10.0.7" />
- <PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="10.0.7" />
+ <PackageVersion Include="Microsoft.AspNetCore.JsonPatch.SystemTextJson" Version="10.0.8" />
+ <PackageVersion Include="Microsoft.AspNetCore.Authentication.Facebook" Version="10.0.8" />
+ <PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="10.0.8" />
<PackageVersion Include="Braintree" Version="5.39.0" />
- <PackageVersion Include="System.Configuration.ConfigurationManager" Version="10.0.7" />
+ <PackageVersion Include="System.Configuration.ConfigurationManager" Version="10.0.8" />
<PackageVersion Include="System.Linq.Dynamic.Core" Version="1.7.2" />
- <PackageVersion Include="System.Security.Cryptography.Xml" Version="10.0.7" />
+ <PackageVersion Include="System.Security.Cryptography.Xml" Version="10.0.8" />
<PackageVersion Include="System.Xml.XPath.XmlDocument" Version="4.7.0" />
<PackageVersion Include="Stripe.net" Version="51.1.0" />
<PackageVersion Include="elFinder.Net.AspNetCore" Version="1.5.0" />
<PackageVersion Include="elFinder.Net.Core" Version="1.5.0" />
<PackageVersion Include="elFinder.Net.Drivers.FileSystem" Version="1.5.0" />
- <PackageVersion Include="Azure.Extensions.AspNetCore.DataProtection.Blobs" Version="1.5.1" />
- <PackageVersion Include="Azure.Extensions.AspNetCore.DataProtection.Keys" Version="1.6.1" />
+ <PackageVersion Include="Azure.Extensions.AspNetCore.DataProtection.Blobs" Version="1.5.3" />
+ <PackageVersion Include="Azure.Extensions.AspNetCore.DataProtection.Keys" Version="1.6.3" />
<PackageVersion Include="Azure.Identity" Version="1.21.0" />
<PackageVersion Include="Flurl.Http" Version="4.0.2" />
- <PackageVersion Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="10.0.7" />
+ <PackageVersion Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="10.0.8" />
<PackageVersion Include="NetEscapades.AspNetCore.SecurityHeaders" Version="1.3.1" />
<PackageVersion Include="Wangkanai.Detection" Version="8.20.0" />
- <PackageVersion Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="10.0.7" />
- <PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
+ <PackageVersion Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="10.0.8" />
+ <PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.5.1" />
<PackageVersion Include="Moq" Version="4.20.72" />
- <PackageVersion Include="MSTest.TestAdapter" Version="4.2.1" />
- <PackageVersion Include="MSTest.TestFramework" Version="4.2.1" />
+ <PackageVersion Include="MSTest.TestAdapter" Version="4.2.3" />
+ <PackageVersion Include="MSTest.TestFramework" Version="4.2.3" />
<PackageVersion Include="coverlet.collector" Version="10.0.0" />
- <PackageVersion Include="NUnit" Version="4.5.1" />
- <PackageVersion Include="Verify.MSTest" Version="31.16.2" />
- <PackageVersion Include="Aspire.Hosting.AppHost" Version="13.2.4" />
- <PackageVersion Include="Aspire.Hosting.MongoDB" Version="13.2.4" />
- <PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="10.5.0" />
- <PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="10.5.0" />
+ <PackageVersion Include="NUnit" Version="4.6.0" />
+ <PackageVersion Include="Verify.MSTest" Version="31.16.3" />
+ <PackageVersion Include="Aspire.Hosting.AppHost" Version="13.3.3" />
+ <PackageVersion Include="Aspire.Hosting.MongoDB" Version="13.3.3" />
+ <PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="10.6.0" />
+ <PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="10.6.0" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.15.3" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.15.3" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.15.2" />
@@ -75,7 +75,7 @@
<PackageVersion Include="Aspire.Hosting.Orchestration.$(NETCoreSdkRuntimeIdentifier)" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
- <PackageVersion Update="Aspire.Dashboard.Sdk.win-x64" Version="13.2.4" />
- <PackageVersion Update="Aspire.Hosting.Orchestration.win-x64" Version="13.2.4" />
+ <PackageVersion Update="Aspire.Dashboard.Sdk.win-x64" Version="13.3.3" />
+ <PackageVersion Update="Aspire.Hosting.Orchestration.win-x64" Version="13.3.3" />
</ItemGroup>
</Project>
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Core/Interfaces/Messages/IMessageTemplateService.cs b/src/Business/Grand.Business.Core/Interfaces/Messages/IMessageTemplateService.cs
index 491e4fb24..c107e3104 100644
--- a/src/Business/Grand.Business.Core/Interfaces/Messages/IMessageTemplateService.cs
+++ b/src/Business/Grand.Business.Core/Interfaces/Messages/IMessageTemplateService.cs
@@ -1,4 +1,5 @@
-using Grand.Domain.Messages;
+using Grand.Domain;
+using Grand.Domain.Messages;
namespace Grand.Business.Core.Interfaces.Messages;
@@ -44,8 +45,11 @@ public interface IMessageTemplateService
/// Gets all message templates
/// </summary>
/// <param name="storeId">Store identifier; pass "" to load all records</param>
- /// <returns>Message template list</returns>
- Task<IList<MessageTemplate>> GetAllMessageTemplates(string storeId);
+ /// <param name="keywords">Keywords to filter by name or subject; pass "" to skip</param>
+ /// <param name="pageIndex">Page index (0-based)</param>
+ /// <param name="pageSize">Page size</param>
+ /// <returns>Paged list of message templates</returns>
+ Task<IPagedList<MessageTemplate>> GetAllMessageTemplates(string storeId, string keywords = "", int pageIndex = 0, int pageSize = int.MaxValue);
/// <summary>
/// Create a copy of message template with all depended data
diff --git a/src/Business/Grand.Business.Messages/Services/MessageTemplateService.cs b/src/Business/Grand.Business.Messages/Services/MessageTemplateService.cs
index a9e64c48b..acabdda17 100644
--- a/src/Business/Grand.Business.Messages/Services/MessageTemplateService.cs
+++ b/src/Business/Grand.Business.Messages/Services/MessageTemplateService.cs
@@ -1,6 +1,7 @@
using Grand.Business.Core.Interfaces.Common.Security;
using Grand.Business.Core.Interfaces.Messages;
using Grand.Data;
+using Grand.Domain;
using Grand.Domain.Messages;
using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Caching.Constants;
@@ -136,28 +137,31 @@ public class MessageTemplateService : IMessageTemplateService
/// Gets all message templates
/// </summary>
/// <param name="storeId">Store identifier; pass "" to load all records</param>
- /// <returns>Message template list</returns>
- public virtual async Task<IList<MessageTemplate>> GetAllMessageTemplates(string storeId)
+ /// <param name="keywords">Keywords to filter by name or subject; pass "" to skip</param>
+ /// <param name="pageIndex">Page index (0-based)</param>
+ /// <param name="pageSize">Page size</param>
+ /// <returns>Paged list of message templates</returns>
+ public virtual async Task<IPagedList<MessageTemplate>> GetAllMessageTemplates(string storeId, string keywords = "", int pageIndex = 0, int pageSize = int.MaxValue)
{
- var key = string.Format(CacheKey.MESSAGETEMPLATES_ALL_KEY, storeId);
- return await _cacheBase.GetAsync(key, async () =>
- {
- var query = from p in _messageTemplateRepository.Table
- select p;
-
- query = query.OrderBy(t => t.Name);
-
- //Store acl
- if (string.IsNullOrEmpty(storeId) || _accessControlConfig.IgnoreStoreLimitations)
- return await Task.FromResult(query.ToList());
+ var query = from p in _messageTemplateRepository.Table
+ select p;
+ //Store acl
+ if (!string.IsNullOrEmpty(storeId) && !_accessControlConfig.IgnoreStoreLimitations)
query = from p in query
where !p.LimitedToStores || p.Stores.Contains(storeId)
select p;
- query = query.OrderBy(t => t.Name);
- return await Task.FromResult(query.ToList());
- });
+ if (!string.IsNullOrEmpty(keywords))
+ {
+ var lowerKeywords = keywords.ToLower();
+ query = query.Where(t => t.Name.ToLower().Contains(lowerKeywords) ||
+ (t.Subject != null && t.Subject.Contains(lowerKeywords, StringComparison.CurrentCultureIgnoreCase)));
+ }
+
+ query = query.OrderBy(t => t.Name);
+
+ return await PagedList<MessageTemplate>.Create(query, pageIndex, pageSize);
}
/// <summary>
diff --git a/src/Plugins/Authentication.Facebook/Authentication.Facebook.csproj b/src/Plugins/Authentication.Facebook/Authentication.Facebook.csproj
index 81006cd9d..d3de7b90d 100644
--- a/src/Plugins/Authentication.Facebook/Authentication.Facebook.csproj
+++ b/src/Plugins/Authentication.Facebook/Authentication.Facebook.csproj
@@ -21,7 +21,7 @@
<Target Name="CopyFile" AfterTargets="AfterBuild">
<ItemGroup>
- <CopyFiles Include="$(NuGetPackageRoot)\microsoft.aspnetcore.authentication.facebook\10.0.7\lib\net10.0\*.dll" />
+ <CopyFiles Include="$(NuGetPackageRoot)\microsoft.aspnetcore.authentication.facebook\10.0.8\lib\net10.0\*.dll" />
</ItemGroup>
<Copy SourceFiles="@(CopyFiles)" DestinationFolder="..\..\Web\Grand.Web\Plugins\Authentication.Facebook\" />
</Target>
diff --git a/src/Plugins/Authentication.Google/Authentication.Google.csproj b/src/Plugins/Authentication.Google/Authentication.Google.csproj
index a76e7720c..1db5fedda 100644
--- a/src/Plugins/Authentication.Google/Authentication.Google.csproj
+++ b/src/Plugins/Authentication.Google/Authentication.Google.csproj
@@ -20,7 +20,7 @@
<Target Name="CopyFile" AfterTargets="AfterBuild">
<ItemGroup>
- <CopyFiles Include="$(NuGetPackageRoot)\microsoft.aspnetcore.authentication.google\10.0.7\lib\net10.0\*.dll" />
+ <CopyFiles Include="$(NuGetPackageRoot)\microsoft.aspnetcore.authentication.google\10.0.8\lib\net10.0\*.dll" />
</ItemGroup>
<Copy SourceFiles="@(CopyFiles)" DestinationFolder="..\..\Web\Grand.Web\Plugins\Authentication.Google\" />
</Target>
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/MessageTemplate/List.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/MessageTemplate/List.cshtml
index 199f985f8..916688db4 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/MessageTemplate/List.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/MessageTemplate/List.cshtml
@@ -1,4 +1,5 @@
@model MessageTemplateListModel
+@inject AdminAreaSettings adminAreaSettings
@{
//page title
ViewBag.Title = Loc["Admin.Content.MessageTemplates"];
@@ -75,15 +76,14 @@
// Cancel the changes
this.cancelChanges();
},
+ pageSize: @(adminAreaSettings.DefaultGridPageSize),
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
pageable: {
refresh: true,
- numeric: false,
- previousNext: false,
- info: false
+ pageSizes: [@(adminAreaSettings.GridPageSizes)]
},
editable: {
confirmation: false,
diff --git a/src/Web/Grand.Web.Admin/Controllers/MessageTemplateController.cs b/src/Web/Grand.Web.Admin/Controllers/MessageTemplateController.cs
index b5d5de26d..cb1331e9f 100644
--- a/src/Web/Grand.Web.Admin/Controllers/MessageTemplateController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/MessageTemplateController.cs
@@ -77,12 +77,12 @@ public class MessageTemplateController : BaseAdminController
[HttpPost]
public async Task<IActionResult> List(DataSourceRequest command, MessageTemplateListModel model)
{
- var messageTemplates = await _messageTemplateService.GetAllMessageTemplates(model.SearchStoreId);
+ var messageTemplates = await _messageTemplateService.GetAllMessageTemplates(
+ model.SearchStoreId,
+ keywords: model.Name,
+ pageIndex: command.Page - 1,
+ pageSize: command.PageSize);
- if (!string.IsNullOrEmpty(model.Name))
- messageTemplates = messageTemplates.Where
- (x => x.Name.ToLowerInvariant().Contains(model.Name.ToLowerInvariant()) ||
- x.Subject.ToLowerInvariant().Contains(model.Name.ToLowerInvariant())).ToList();
var items = new List<MessageTemplateModel>();
foreach (var x in messageTemplates)
{
@@ -103,7 +103,7 @@ public class MessageTemplateController : BaseAdminController
var gridModel = new DataSourceResult {
Data = items,
- Total = messageTemplates.Count
+ Total = messageTemplates.TotalCount
};
return Json(gridModel);
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/MessageTemplate/Create.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/MessageTemplate/Create.cshtml
new file mode 100644
index 000000000..566cc6135
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/MessageTemplate/Create.cshtml
@@ -0,0 +1,36 @@
+@model MessageTemplateModel
+@{
+ ViewBag.Title = Loc["Admin.Content.MessageTemplates.AddNew"];
+ Layout = Constants.LayoutStore;
+}
+<form asp-area="@Constants.AreaStore" asp-controller="MessageTemplate" asp-action="Create" method="post">
+
+ <div class="row">
+ <div class="col-md-12">
+ <div class="x_panel light form-fit">
+ <div class="x_title">
+ <div class="caption">
+ <i class="fa fa-envelope-o"></i>
+ @Loc["Admin.Content.MessageTemplates.AddNew"]
+ <small>
+ <i class="fa fa-arrow-circle-left"></i>@Html.ActionLink(Loc["Admin.Content.MessageTemplates.BackToList"], "List")
+ </small>
+ </div>
+ <div class="actions">
+ <div class="btn-group btn-group-devided">
+ <button class="btn btn-success" type="submit" name="save">
+ <i class="fa fa-check"></i> @Loc["Admin.Common.Save"]
+ </button>
+ <button class="btn btn-success" type="submit" name="save-continue">
+ <i class="fa fa-check-circle"></i> @Loc["Admin.Common.SaveContinue"]
+ </button>
+ </div>
+ </div>
+ </div>
+ <div class="x_content form">
+ <partial name="Partials/CreateOrUpdate" model="Model"/>
+ </div>
+ </div>
+ </div>
+ </div>
+</form>
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/MessageTemplate/Edit.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/MessageTemplate/Edit.cshtml
new file mode 100644
index 000000000..e47a3d174
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/MessageTemplate/Edit.cshtml
@@ -0,0 +1,48 @@
+@model MessageTemplateModel
+@{
+ ViewBag.Title = Loc["Admin.Content.MessageTemplates.EditMessageTemplateDetails"];
+ Layout = Constants.LayoutStore;
+ var isReadOnly = (bool)(ViewBag.IsReadOnly ?? false);
+}
+<form asp-area="@Constants.AreaStore" asp-controller="MessageTemplate" asp-action="Edit" method="post">
+
+ <div class="row">
+ <div class="col-md-12">
+ <div class="x_panel light form-fit">
+ <div class="x_title">
+ <div class="caption">
+ <i class="fa fa-envelope-o"></i>
+ @Loc["Admin.Content.MessageTemplates.EditMessageTemplateDetails"] - @Model.Name
+ <small>
+ <i class="fa fa-arrow-circle-left"></i>@Html.ActionLink(Loc["Admin.Content.MessageTemplates.BackToList"], "List")
+ </small>
+ </div>
+ <div class="actions">
+ <div class="btn-group btn-group-devided">
+ @if (!isReadOnly)
+ {
+ <button class="btn btn-success" type="submit" name="save">
+ <i class="fa fa-check"></i> @Loc["Admin.Common.Save"]
+ </button>
+ <button class="btn btn-success" type="submit" name="save-continue">
+ <i class="fa fa-check-circle"></i> @Loc["Admin.Common.SaveContinue"]
+ </button>
+ <input type="submit" name="message-template-copy" asp-action="CopyTemplate" class="btn blue" value="@Loc["Admin.Content.MessageTemplates.Copy"]" onclick="return confirm('@Loc["Admin.Common.AreYouSure"]');"/>
+ <span id="message-template-delete" class="btn red">
+ <i class="fa fa-trash-o"></i> @Loc["Admin.Common.Delete"]
+ </span>
+ }
+ </div>
+ </div>
+ </div>
+ <div class="x_content form">
+ <partial name="Partials/CreateOrUpdate" model="Model"/>
+ </div>
+ </div>
+ </div>
+ </div>
+</form>
+@if (!isReadOnly)
+{
+ <admin-delete-confirmation button-id="message-template-delete"/>
+}
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/MessageTemplate/List.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/MessageTemplate/List.cshtml
new file mode 100644
index 000000000..87ecae4b2
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/MessageTemplate/List.cshtml
@@ -0,0 +1,144 @@
+@inject AdminAreaSettings adminAreaSettings
+@{
+ ViewBag.Title = Loc["Admin.Content.MessageTemplates"];
+ Layout = Constants.LayoutStore;
+}
+
+<div class="row">
+ <div class="col-md-12">
+ <div class="x_panel light form-fit">
+ <div class="x_title">
+ <div class="caption">
+ <i class="fa fa-envelope-o"></i>
+ @Loc["Admin.Content.MessageTemplates"]
+ </div>
+ <div class="actions btn-group btn-group-devided">
+ <a href="@Url.Action("Create", new { area = Constants.AreaStore })" class="btn green">
+ <i class="fa fa-plus"></i><span class="d-none d-sm-inline"> @Loc["Admin.Common.AddNew"] </span>
+ </a>
+ </div>
+ </div>
+ <div class="x_content form">
+ <admin-tabstrip name="messagetemplates-tabs">
+ <items>
+ <tabstrip-item text="@Loc["Admin.Content.MessageTemplates.Tab.Store"]" tab-index="0">
+ <content>
+ <div id="store-templates-grid"></div>
+ </content>
+ </tabstrip-item>
+ <tabstrip-item text="@Loc["Admin.Content.MessageTemplates.Tab.Global"]" tab-index="1">
+ <content>
+ <div id="global-templates-grid"></div>
+ </content>
+ </tabstrip-item>
+ </items>
+ </admin-tabstrip>
+ </div>
+ </div>
+ </div>
+</div>
+<script>
+ $(document).ready(function () {
+ $("#store-templates-grid").kendoGrid({
+ dataSource: {
+ transport: {
+ read: {
+ url: "@Html.Raw(Url.Action("ListStore", "MessageTemplate", new { area = Constants.AreaStore }))",
+ type: "POST",
+ dataType: "json",
+ data: addAntiForgeryToken
+ }
+ },
+ schema: {
+ data: "Data",
+ total: "Total",
+ errors: "Errors"
+ },
+ error: function(e) {
+ display_kendoui_grid_error(e);
+ this.cancelChanges();
+ },
+ pageSize: @(adminAreaSettings.DefaultGridPageSize),
+ serverPaging: true,
+ serverFiltering: true,
+ serverSorting: true
+ },
+ pageable: {
+ refresh: true,
+ pageSizes: [@(adminAreaSettings.GridPageSizes)]
+ },
+ scrollable: false,
+ columns: [{
+ field: "Name",
+ title: "@Loc["Admin.Content.MessageTemplates.Fields.Name"]",
+ width: 300,
+ template: '<a class="k-link" href="Edit/#=Id#">#=kendo.htmlEncode(Name)#</a>'
+ }, {
+ field: "Subject",
+ title: "@Loc["Admin.Content.MessageTemplates.Fields.Subject"]",
+ width: 200
+ }, {
+ field: "IsActive",
+ title: "@Loc["Admin.Content.MessageTemplates.Fields.IsActive"]",
+ width: 80,
+ headerAttributes: { style: "text-align:center" },
+ attributes: { style: "text-align:center" },
+ template: '# if(IsActive) {# <i class="fa fa-check" aria-hidden="true" style="color:green"></i> #} else {# <i class="fa fa-times" aria-hidden="true" style="color:red"></i> #} #'
+ }]
+ });
+
+ $("#global-templates-grid").kendoGrid({
+ dataSource: {
+ transport: {
+ read: {
+ url: "@Html.Raw(Url.Action("ListGlobal", "MessageTemplate", new { area = Constants.AreaStore }))",
+ type: "POST",
+ dataType: "json",
+ data: addAntiForgeryToken
+ }
+ },
+ schema: {
+ data: "Data",
+ total: "Total",
+ errors: "Errors"
+ },
+ error: function(e) {
+ display_kendoui_grid_error(e);
+ this.cancelChanges();
+ },
+ pageSize: @(adminAreaSettings.DefaultGridPageSize),
+ serverPaging: true,
+ serverFiltering: true,
+ serverSorting: true
+ },
+ pageable: {
+ refresh: true,
+ pageSizes: [@(adminAreaSettings.GridPageSizes)]
+ },
+ scrollable: false,
+ columns: [{
+ field: "Name",
+ title: "@Loc["Admin.Content.MessageTemplates.Fields.Name"]",
+ width: 300,
+ template: '<a class="k-link" href="Edit/#=Id#">#=kendo.htmlEncode(Name)#</a>'
+ }, {
+ field: "Subject",
+ title: "@Loc["Admin.Content.MessageTemplates.Fields.Subject"]",
+ width: 200
+ }, {
+ field: "IsActive",
+ title: "@Loc["Admin.Content.MessageTemplates.Fields.IsActive"]",
+ width: 80,
+ headerAttributes: { style: "text-align:center" },
+ attributes: { style: "text-align:center" },
+ template: '# if(IsActive) {# <i class="fa fa-check" aria-hidden="true" style="color:green"></i> #} else {# <i class="fa fa-times" aria-hidden="true" style="color:red"></i> #} #'
+ }, {
+ title: "@Loc["Admin.Common.Copy"]",
+ width: 100,
+ headerAttributes: { style: "text-align:center" },
+ attributes: { style: "text-align:center" },
+ template: '<form method="post" action="@Url.Action("CopyTemplate", "MessageTemplate", new { area = Constants.AreaStore })"><input type="hidden" name="Id" value="#=Id#"/><button type="submit" class="btn btn-sm btn-info" onclick="return confirm(\'@Loc["Admin.Common.AreYouSure"]\')" title="@Loc["Admin.Content.MessageTemplates.Copy"]"><i class="fa fa-copy"></i></button>@Html.AntiForgeryToken()</form>'
+ }]
+ });
+ });
+</script>
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/MessageTemplate/Partials/CreateOrUpdate.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/MessageTemplate/Partials/CreateOrUpdate.cshtml
new file mode 100644
index 000000000..8e3520ab3
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/MessageTemplate/Partials/CreateOrUpdate.cshtml
@@ -0,0 +1,212 @@
+@using Grand.Domain.Messages
+@using Microsoft.AspNetCore.Mvc.Razor
+@using Constants = Grand.SharedUIResources.Constants
+@model MessageTemplateModel
+
+<div asp-validation-summary="All"></div>
+<input asp-for="Id" type="hidden"/>
+<link rel="stylesheet" type="text/css" asp-src="@(Constants.WwwRoot)/administration/codemirror/codemirror.css"/>
+<script asp-location="Head" asp-src="@(Constants.WwwRoot)/administration/codemirror/codemirror.js"></script>
+<script asp-location="Head" asp-src="@(Constants.WwwRoot)/administration/codemirror/mode/xml/xml.js"></script>
+
+@{
+ Func<int, HelperResult>
+ template = @<div class="form-body">
+ <div class="form-group">
+ <admin-label asp-for="@Model.Locales[item].BccEmailAddresses"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="@Model.Locales[item].BccEmailAddresses"/>
+ <span asp-validation-for="@Model.Locales[item].BccEmailAddresses"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="@Model.Locales[item].Subject"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="@Model.Locales[item].Subject"/>
+ <span asp-validation-for="@Model.Locales[item].Subject"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="@Model.Locales[item].Body"/>
+ <div class="col-md-9 col-sm-9">
+ <div>
+ <label>@Loc["Admin.Content.MessageTemplates.Fields.AllowedTokens"]</label>
+ <input type="search" name="SearchTokens" class="form-control SearchTokens" placeholder="@Loc["Search"]"/>
+ </div>
+ <div class="AllowedTokens">
+ @foreach (var token in Model.AllowedTokens)
+ {
+ <button type="button" onclick="AddTokenToEditor(this)" class="btn btn-info">@token</button>
+ }
+ </div>
+ <admin-input asp-for="@Model.Locales[item].Body" asp-template="Codemirror"/>
+ <span asp-validation-for="@Model.Locales[item].Body"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="@Model.Locales[item].EmailAccountId"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-select asp-for="@Model.Locales[item].EmailAccountId" asp-items="@(new SelectList(Model.AvailableEmailAccounts, "Id", "DisplayName", Model.Locales[item].EmailAccountId))"/>
+ <span asp-validation-for="Locales[item].EmailAccountId"></span>
+ </div>
+ </div>
+ <input asp-for="@Model.Locales[item].LanguageId" type="hidden"/>
+ </div>;
+}
+
+<div class="form-horizontal">
+ <div class="form-body">
+ <div class="form-group">
+ <admin-label asp-for="Name"/>
+ <div class="col-md-9 col-sm-9">
+ @if (!string.IsNullOrEmpty(Model.Id))
+ {
+ <label class="control-label">@Model.Name</label>
+ <input asp-for="Name" type="hidden"/>
+ }
+ else
+ {
+ <admin-input asp-for="Name"/>
+ }
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="IsActive"/>
+ <div class="col-md-9 col-sm-9">
+ <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
+ <admin-input asp-for="IsActive"/>
+ <div class="control__indicator"></div>
+ </label>
+ <span asp-validation-for="IsActive"></span>
+ </div>
+ </div>
+ </div>
+
+ <localized-editor localized-template="@template" name="messagetemplate-localized" language-ids="@Model.Locales.Select(c => c.LanguageId).ToList()">
+ <div class="form-body">
+ <div class="form-group">
+ <admin-label asp-for="BccEmailAddresses"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="BccEmailAddresses"/>
+ <span asp-validation-for="BccEmailAddresses"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="Subject"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="Subject"/>
+ <span asp-validation-for="Subject"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="Body"/>
+ <div class="col-md-9 col-sm-9">
+ <div>
+ <label>@Loc["Admin.Content.MessageTemplates.Fields.AllowedTokens"]</label>
+ <input type="search" name="SearchTokens" class="form-control SearchTokens" placeholder="@Loc["Search"]"/>
+ </div>
+ <div class="AllowedTokens">
+ @foreach (var token in Model.AllowedTokens)
+ {
+ <button type="button" onclick="AddTokenToEditor(this)" class="btn btn-info">@token</button>
+ }
+ </div>
+ <admin-input asp-for="Body" asp-template="Codemirror"/>
+ <span asp-validation-for="Body"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="EmailAccountId"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-select asp-for="EmailAccountId" asp-items="@(new SelectList(Model.AvailableEmailAccounts, "Id", "DisplayName"))"/>
+ <span asp-validation-for="EmailAccountId"></span>
+ </div>
+ </div>
+ </div>
+ </localized-editor>
+
+ <div class="form-body">
+ <div class="form-group">
+ <admin-label asp-for="SendImmediately"/>
+ <div class="col-md-9 col-sm-9">
+ <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
+ <admin-input asp-for="SendImmediately"/>
+ <div class="control__indicator"></div>
+ </label>
+ <span asp-validation-for="SendImmediately"></span>
+ </div>
+ </div>
+ <div class="form-group" id="pnl-send-after">
+ <admin-label asp-for="DelayBeforeSend"/>
+ <div class="col-md-9 col-sm-9">
+ <div class="col-md-3 col-sm-3">
+ <admin-input asp-for="DelayBeforeSend"/>
+ <span asp-validation-for="DelayBeforeSend"></span>
+ </div>
+ <div class="col-md-3 col-sm-3">
+ <admin-select asp-for="DelayPeriodId" asp-items="EnumTranslationService.ToSelectList((MessageDelayPeriod)Model.DelayPeriodId)"/>
+ <span asp-validation-for="DelayPeriodId"></span>
+ </div>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="AttachedDownloadId"/>
+ <div class="col-md-9 col-sm-9">
+ <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
+ <div class="d-inline-flex flex-row-reverse">
+ <admin-input asp-for="HasAttachedDownload"/>
+ @Loc["Admin.Content.MessageTemplates.Fields.AttachedDownload.Exists"]
+ <div class="control__indicator mr-3"></div>
+ </div>
+ </label>
+ <div id="pnlAttachedDownload">
+ <admin-input asp-for="AttachedDownloadId"/>
+ <span asp-validation-for="AttachedDownloadId"></span>
+ </div>
+ </div>
+ </div>
+ </div>
+</div>
+<script>
+ $(document).ready(function () {
+ $("#@Html.IdFor(model => model.HasAttachedDownload)").change(toggleHasAttachedDownload);
+ $("#@Html.IdFor(model => model.SendImmediately)").click(sendImmediately);
+ toggleHasAttachedDownload();
+ sendImmediately();
+ $(".SearchTokens").on("input", function (e) { SearchTokens(e); })
+ });
+
+ function toggleHasAttachedDownload() {
+ if ($('#@Html.IdFor(model => model.HasAttachedDownload)').is(':checked')) {
+ $('#pnlAttachedDownload').show();
+ } else {
+ $('#pnlAttachedDownload').hide();
+ }
+ }
+
+ function sendImmediately() {
+ if ($('#@Html.IdFor(model => model.SendImmediately)').is(':checked'))
+ $('#pnl-send-after').hide();
+ else
+ $('#pnl-send-after').show();
+ }
+
+ function AddTokenToEditor(e) {
+ var cm = $('.CodeMirror')[0].CodeMirror;
+ var doc = cm.getDoc();
+ var cursor = doc.getCursor();
+ doc.replaceRange($(e).text(), cursor);
+ }
+
+ function SearchTokens(e) {
+ var searchVal = $(e.target).val();
+ var TokensPnl = $(e.target).closest(".form-group").find(".AllowedTokens");
+ $(TokensPnl).find(".btn").show()
+ .each(function (i, c) {
+ var Token = $(c).text();
+ if (Token.search(new RegExp(searchVal, "i")) == -1) {
+ $(c).hide();
+ }
+ });
+ }
+</script>
diff --git a/src/Web/Grand.Web.Store/Controllers/MessageTemplateController.cs b/src/Web/Grand.Web.Store/Controllers/MessageTemplateController.cs
new file mode 100644
index 000000000..9d80fa9c8
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Controllers/MessageTemplateController.cs
@@ -0,0 +1,306 @@
+using Grand.Business.Core.Extensions;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Messages;
+using Grand.Business.Core.Interfaces.Storage;
+using Grand.Domain.Permissions;
+using Grand.Infrastructure;
+using Grand.SharedKernel;
+using Grand.Web.AdminShared.Extensions.Mapping;
+using Grand.Web.AdminShared.Models.Messages;
+using Grand.Web.Common.DataSource;
+using Grand.Web.Common.Filters;
+using Grand.Web.Common.Security.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Grand.Web.Store.Controllers;
+
+[PermissionAuthorize(PermissionSystemName.MessageTemplates)]
+public class MessageTemplateController(
+ IMessageTemplateService messageTemplateService,
+ IEmailAccountService emailAccountService,
+ ILanguageService languageService,
+ ITranslationService translationService,
+ IMessageTokenProvider messageTokenProvider,
+ IDownloadService downloadService,
+ IContextAccessor contextAccessor) : BaseStoreController
+{
+ private string CurrentStoreId => contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+
+ public IActionResult Index()
+ {
+ return RedirectToAction("List");
+ }
+
+ public IActionResult List()
+ {
+ return View();
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.List)]
+ [HttpPost]
+ public async Task<IActionResult> ListGlobal(DataSourceRequest command)
+ {
+ var allTemplates = await messageTemplateService.GetAllMessageTemplates("");
+ var globalTemplates = allTemplates
+ .Where(t => !t.LimitedToStores)
+ .ToList();
+
+ var total = globalTemplates.Count;
+ var items = globalTemplates
+ .Skip((command.Page - 1) * command.PageSize)
+ .Take(command.PageSize)
+ .Select(x => x.ToModel())
+ .ToList();
+
+ var gridModel = new DataSourceResult {
+ Data = items,
+ Total = total
+ };
+
+ return Json(gridModel);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.List)]
+ [HttpPost]
+ public async Task<IActionResult> ListStore(DataSourceRequest command)
+ {
+ var allTemplates = await messageTemplateService.GetAllMessageTemplates("");
+ var storeTemplates = allTemplates
+ .Where(t => t.LimitedToStores && t.Stores.Contains(CurrentStoreId))
+ .ToList();
+
+ var total = storeTemplates.Count;
+ var items = storeTemplates
+ .Skip((command.Page - 1) * command.PageSize)
+ .Take(command.PageSize)
+ .Select(x => x.ToModel())
+ .ToList();
+
+ var gridModel = new DataSourceResult {
+ Data = items,
+ Total = total
+ };
+
+ return Json(gridModel);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Create)]
+ public async Task<IActionResult> Create()
+ {
+ var model = new MessageTemplateModel {
+ AllowedTokens = messageTokenProvider.GetListOfAllowedTokens()
+ };
+
+ foreach (var ea in await emailAccountService.GetAllEmailAccounts(CurrentStoreId))
+ model.AvailableEmailAccounts.Add(ea.ToModel());
+
+ await AddLocales(languageService, model.Locales);
+
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Create)]
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public async Task<IActionResult> Create(MessageTemplateModel model, bool continueEditing)
+ {
+ if (ModelState.IsValid)
+ {
+ // Prevent duplicate: check only for store-specific templates with this name for the current store.
+ // Pass keywords to pre-filter by name at the DB level, then verify exact match and store ownership.
+ var existingStoreTemplate = (await messageTemplateService.GetAllMessageTemplates("", keywords: model.Name))
+ .FirstOrDefault(t =>
+ t.Name == model.Name &&
+ t.LimitedToStores &&
+ t.Stores.Contains(CurrentStoreId));
+ if (existingStoreTemplate != null)
+ {
+ ModelState.AddModelError("Name", translationService.GetResource("Admin.Content.MessageTemplates.Fields.Name.AlreadyExists"));
+ model.HasAttachedDownload = !string.IsNullOrEmpty(model.AttachedDownloadId);
+ model.AllowedTokens = messageTokenProvider.GetListOfAllowedTokens();
+ foreach (var ea in await emailAccountService.GetAllEmailAccounts(CurrentStoreId))
+ model.AvailableEmailAccounts.Add(ea.ToModel());
+ return View(model);
+ }
+
+ var messageTemplate = model.ToEntity();
+ if (!model.HasAttachedDownload)
+ messageTemplate.AttachedDownloadId = "";
+ if (model.SendImmediately)
+ messageTemplate.DelayBeforeSend = null;
+
+ // Assign to the current store
+ messageTemplate.LimitedToStores = true;
+ messageTemplate.Stores = [CurrentStoreId];
+
+ await messageTemplateService.InsertMessageTemplate(messageTemplate);
+
+ Success(translationService.GetResource("Admin.Content.MessageTemplates.AddNew"));
+
+ if (continueEditing)
+ {
+ await SaveSelectedTabIndex();
+ return RedirectToAction("Edit", new { id = messageTemplate.Id });
+ }
+
+ return RedirectToAction("List");
+ }
+
+ model.HasAttachedDownload = !string.IsNullOrEmpty(model.AttachedDownloadId);
+ model.AllowedTokens = messageTokenProvider.GetListOfAllowedTokens();
+ foreach (var ea in await emailAccountService.GetAllEmailAccounts(CurrentStoreId))
+ model.AvailableEmailAccounts.Add(ea.ToModel());
+
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Preview)]
+ public async Task<IActionResult> Edit(string id)
+ {
+ var messageTemplate = await messageTemplateService.GetMessageTemplateById(id);
+ if (messageTemplate == null)
+ return RedirectToAction("List");
+
+ // Block access to templates that belong to a different store
+ if (messageTemplate.LimitedToStores && !messageTemplate.Stores.Contains(CurrentStoreId))
+ return RedirectToAction("List");
+
+ // Global templates (LimitedToStores=false) are shown read-only
+ ViewBag.IsReadOnly = !messageTemplate.LimitedToStores;
+
+ var model = messageTemplate.ToModel();
+ model.SendImmediately = !model.DelayBeforeSend.HasValue;
+ model.HasAttachedDownload = !string.IsNullOrEmpty(model.AttachedDownloadId);
+ model.AllowedTokens = messageTokenProvider.GetListOfAllowedTokens();
+
+ foreach (var ea in await emailAccountService.GetAllEmailAccounts(CurrentStoreId))
+ model.AvailableEmailAccounts.Add(ea.ToModel());
+
+ await AddLocales(languageService, model.Locales, (locale, languageId) =>
+ {
+ locale.BccEmailAddresses = messageTemplate.GetTranslation(x => x.BccEmailAddresses, languageId, false);
+ locale.Subject = messageTemplate.GetTranslation(x => x.Subject, languageId, false);
+ locale.Body = messageTemplate.GetTranslation(x => x.Body, languageId, false);
+ locale.EmailAccountId = messageTemplate.GetTranslation(x => x.EmailAccountId, languageId, false);
+ });
+
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public async Task<IActionResult> Edit(MessageTemplateModel model, bool continueEditing)
+ {
+ var messageTemplate = await messageTemplateService.GetMessageTemplateById(model.Id);
+ if (messageTemplate == null)
+ return RedirectToAction("List");
+
+ if (!messageTemplate.LimitedToStores || !messageTemplate.Stores.Contains(CurrentStoreId))
+ return RedirectToAction("List");
+
+ var prevAttachment = messageTemplate.AttachedDownloadId;
+
+ if (ModelState.IsValid)
+ {
+ messageTemplate = model.ToEntity(messageTemplate);
+ if (!model.HasAttachedDownload)
+ messageTemplate.AttachedDownloadId = "";
+ if (model.SendImmediately)
+ messageTemplate.DelayBeforeSend = null;
+
+ // Keep it assigned to the current store
+ messageTemplate.LimitedToStores = true;
+ messageTemplate.Stores = [CurrentStoreId];
+
+ if (!string.IsNullOrEmpty(prevAttachment) && prevAttachment != messageTemplate.AttachedDownloadId)
+ {
+ var attachment = await downloadService.GetDownloadById(prevAttachment);
+ if (attachment != null)
+ await downloadService.DeleteDownload(attachment);
+ }
+
+ await messageTemplateService.UpdateMessageTemplate(messageTemplate);
+
+ Success(translationService.GetResource("Admin.Content.MessageTemplates.Updated"));
+
+ if (continueEditing)
+ {
+ await SaveSelectedTabIndex();
+ return RedirectToAction("Edit", new { id = messageTemplate.Id });
+ }
+
+ return RedirectToAction("List");
+ }
+
+ model.HasAttachedDownload = !string.IsNullOrEmpty(model.AttachedDownloadId);
+ model.AllowedTokens = messageTokenProvider.GetListOfAllowedTokens();
+ foreach (var ea in await emailAccountService.GetAllEmailAccounts(CurrentStoreId))
+ model.AvailableEmailAccounts.Add(ea.ToModel());
+
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Delete)]
+ [HttpPost]
+ public async Task<IActionResult> Delete(string id)
+ {
+ var messageTemplate = await messageTemplateService.GetMessageTemplateById(id);
+ if (messageTemplate == null)
+ return RedirectToAction("List");
+
+ if (!messageTemplate.LimitedToStores || !messageTemplate.Stores.Contains(CurrentStoreId))
+ return RedirectToAction("List");
+
+ await messageTemplateService.DeleteMessageTemplate(messageTemplate);
+
+ if (!string.IsNullOrEmpty(messageTemplate.AttachedDownloadId))
+ {
+ var attachment = await downloadService.GetDownloadById(messageTemplate.AttachedDownloadId);
+ if (attachment != null)
+ await downloadService.DeleteDownload(attachment);
+ }
+
+ Success(translationService.GetResource("Admin.Content.MessageTemplates.Deleted"));
+ return RedirectToAction("List");
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [HttpPost]
+ public async Task<IActionResult> CopyTemplate(MessageTemplateModel model)
+ {
+ var messageTemplate = await messageTemplateService.GetMessageTemplateById(model.Id);
+ if (messageTemplate == null)
+ return RedirectToAction("List");
+
+ // Only allow copying global templates (LimitedToStores = false)
+ if (messageTemplate.LimitedToStores)
+ return RedirectToAction("List");
+
+ // Prevent duplicate: check if a store-specific template with the same name already exists for the current store
+ var existing = (await messageTemplateService.GetAllMessageTemplates("", keywords: messageTemplate.Name))
+ .FirstOrDefault(t => t.Name == messageTemplate.Name && t.LimitedToStores && t.Stores.Contains(CurrentStoreId));
+ if (existing != null)
+ {
+ Error(translationService.GetResource("Admin.Content.MessageTemplates.Fields.Name.AlreadyExists"));
+ return RedirectToAction("List");
+ }
+
+ try
+ {
+ var newMessageTemplate = await messageTemplateService.CopyMessageTemplate(messageTemplate);
+ // Assign copy to the current store
+ newMessageTemplate.LimitedToStores = true;
+ newMessageTemplate.Stores = [CurrentStoreId];
+ await messageTemplateService.UpdateMessageTemplate(newMessageTemplate);
+
+ Success(translationService.GetResource("Admin.Content.MessageTemplates.Copied"));
+ return RedirectToAction("Edit", new { id = newMessageTemplate.Id });
+ }
+ catch (GrandException exc)
+ {
+ Error(exc.Message);
+ return RedirectToAction("List");
+ }
+ }
+}
diff --git a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
index 4ed1399d6..527aba66d 100644
Binary files a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml and b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml differ