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 store-scoped gift voucher CRUD and global voucher listing to Grand.Web.Store #709

Krzysztof Pajakce419af7fc60
diff --git a/src/Business/Grand.Business.Checkout/Queries/Handlers/Orders/GetGiftVoucherQueryHandler.cs b/src/Business/Grand.Business.Checkout/Queries/Handlers/Orders/GetGiftVoucherQueryHandler.cs
index acb7c6e7b..aba41138c 100644
--- a/src/Business/Grand.Business.Checkout/Queries/Handlers/Orders/GetGiftVoucherQueryHandler.cs
+++ b/src/Business/Grand.Business.Checkout/Queries/Handlers/Orders/GetGiftVoucherQueryHandler.cs
@@ -22,6 +22,9 @@ public class GetGiftVoucherQueryHandler : IRequestHandler<GetGiftVoucherQuery, I
if (!string.IsNullOrEmpty(request.GiftVoucherId))
query = query.Where(gc => gc.Id == request.GiftVoucherId);
+ if (!string.IsNullOrEmpty(request.StoreId))
+ query = query.Where(gc => gc.StoreId == request.StoreId || gc.StoreId == null || gc.StoreId == "");
+
if (!string.IsNullOrEmpty(request.PurchasedWithOrderItemId))
query = query.Where(gc => gc.PurchasedWithOrderItem.Id == request.PurchasedWithOrderItemId);
@@ -40,4 +43,4 @@ public class GetGiftVoucherQueryHandler : IRequestHandler<GetGiftVoucherQuery, I
return Task.FromResult(query);
}
-}
\ No newline at end of file
+}
diff --git a/src/Business/Grand.Business.Checkout/Services/GiftVouchers/GiftVoucherService.cs b/src/Business/Grand.Business.Checkout/Services/GiftVouchers/GiftVoucherService.cs
index a9968ffa4..86aac0163 100644
--- a/src/Business/Grand.Business.Checkout/Services/GiftVouchers/GiftVoucherService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/GiftVouchers/GiftVoucherService.cs
@@ -51,6 +51,7 @@ public class GiftVoucherService : IGiftVoucherService
/// Gets all gift vouchers
/// </summary>
/// <param name="purchasedWithOrderItemId">Associated order ID; null to load all records</param>
+ /// <param name="storeId">Store identifier; null to load all records</param>
/// <param name="createdFromUtc">Created date from (UTC); null to load all records</param>
/// <param name="createdToUtc">Created date to (UTC); null to load all records</param>
/// <param name="isGiftVoucherActivated">Value indicating whether gift voucher is activated; null to load all records</param>
@@ -63,7 +64,7 @@ public class GiftVoucherService : IGiftVoucherService
DateTime? createdFromUtc = null, DateTime? createdToUtc = null,
bool? isGiftVoucherActivated = null, string giftVoucherCouponCode = null,
string recipientName = null,
- int pageIndex = 0, int pageSize = int.MaxValue)
+ int pageIndex = 0, int pageSize = int.MaxValue, string storeId = "")
{
var model = new GetGiftVoucherQuery {
CreatedFromUtc = createdFromUtc,
@@ -73,6 +74,7 @@ public class GiftVoucherService : IGiftVoucherService
PageIndex = pageIndex,
PageSize = pageSize,
PurchasedWithOrderItemId = purchasedWithOrderItemId,
+ StoreId = storeId,
RecipientName = recipientName
};
@@ -167,4 +169,4 @@ public class GiftVoucherService : IGiftVoucherService
}
#endregion
-}
\ No newline at end of file
+}
diff --git a/src/Business/Grand.Business.Core/Interfaces/Checkout/GiftVouchers/IGiftVoucherService.cs b/src/Business/Grand.Business.Core/Interfaces/Checkout/GiftVouchers/IGiftVoucherService.cs
index 0d675e239..2037f9ae1 100644
--- a/src/Business/Grand.Business.Core/Interfaces/Checkout/GiftVouchers/IGiftVoucherService.cs
+++ b/src/Business/Grand.Business.Core/Interfaces/Checkout/GiftVouchers/IGiftVoucherService.cs
@@ -19,6 +19,7 @@ public interface IGiftVoucherService
/// Gets all gift vouchers
/// </summary>
/// <param name="purchasedWithOrderItemId">Associated order ID; null to load all records</param>
+ /// <param name="storeId">Store identifier; null to load all records</param>
/// <param name="createdFromUtc">Created date from (UTC); null to load all records</param>
/// <param name="createdToUtc">Created date to (UTC); null to load all records</param>
/// <param name="isGiftVoucherActivated">Value indicating whether gift voucher is activated; null to load all records</param>
@@ -31,7 +32,7 @@ public interface IGiftVoucherService
DateTime? createdFromUtc = null, DateTime? createdToUtc = null,
bool? isGiftVoucherActivated = null, string giftVoucherCouponCode = null,
string recipientName = null,
- int pageIndex = 0, int pageSize = int.MaxValue);
+ int pageIndex = 0, int pageSize = int.MaxValue, string storeId = "");
/// <summary>
@@ -69,4 +70,4 @@ public interface IGiftVoucherService
/// </summary>
/// <returns>Result</returns>
string GenerateGiftVoucherCode();
-}
\ No newline at end of file
+}
diff --git a/src/Business/Grand.Business.Core/Queries/Checkout/Orders/GetGiftVoucherQuery.cs b/src/Business/Grand.Business.Core/Queries/Checkout/Orders/GetGiftVoucherQuery.cs
index a3f53ceb0..e4e71a5fe 100644
--- a/src/Business/Grand.Business.Core/Queries/Checkout/Orders/GetGiftVoucherQuery.cs
+++ b/src/Business/Grand.Business.Core/Queries/Checkout/Orders/GetGiftVoucherQuery.cs
@@ -6,6 +6,7 @@ namespace Grand.Business.Core.Queries.Checkout.Orders;
public class GetGiftVoucherQuery : IRequest<IQueryable<GiftVoucher>>
{
public string GiftVoucherId { get; set; } = "";
+ public string StoreId { get; set; } = "";
public string PurchasedWithOrderItemId { get; set; } = "";
public bool? IsGiftVoucherActivated { get; set; }
public string Code { get; set; } = "";
@@ -14,4 +15,4 @@ public class GetGiftVoucherQuery : IRequest<IQueryable<GiftVoucher>>
public string RecipientName { get; set; } = null;
public int PageIndex { get; set; } = 0;
public int PageSize { get; set; } = int.MaxValue;
-}
\ No newline at end of file
+}
diff --git a/src/Tests/Grand.Business.Checkout.Tests/Commands/Handlers/Orders/ActivatedValueForPurchasedGiftVouchersCommandHandlerTests.cs b/src/Tests/Grand.Business.Checkout.Tests/Commands/Handlers/Orders/ActivatedValueForPurchasedGiftVouchersCommandHandlerTests.cs
index 023790ce7..7f193e48f 100644
--- a/src/Tests/Grand.Business.Checkout.Tests/Commands/Handlers/Orders/ActivatedValueForPurchasedGiftVouchersCommandHandlerTests.cs
+++ b/src/Tests/Grand.Business.Checkout.Tests/Commands/Handlers/Orders/ActivatedValueForPurchasedGiftVouchersCommandHandlerTests.cs
@@ -41,7 +41,8 @@ public class ActivatedValueForPurchasedGiftVouchersCommandHandlerTests
_langService.Setup(c => c.GetLanguageById(It.IsAny<string>())).ReturnsAsync(new Language());
_giftVoucherMock.Setup(c => c.GetAllGiftVouchers(It.IsAny<string>(), It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(),
- It.IsAny<bool?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
+ It.IsAny<bool?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>(),
+ It.IsAny<string>()))
.ReturnsAsync(new PagedList<GiftVoucher> { gift });
await _handler.Handle(command, default);
@@ -62,11 +63,12 @@ public class ActivatedValueForPurchasedGiftVouchersCommandHandlerTests
_langService.Setup(c => c.GetLanguageById(It.IsAny<string>())).ReturnsAsync(new Language());
_giftVoucherMock.Setup(c => c.GetAllGiftVouchers(It.IsAny<string>(), It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(),
- It.IsAny<bool?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
+ It.IsAny<bool?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>(),
+ It.IsAny<string>()))
.ReturnsAsync(new PagedList<GiftVoucher> { gift });
await _handler.Handle(command, default);
Assert.IsFalse(gift.IsGiftVoucherActivated);
_giftVoucherMock.Verify(c => c.UpdateGiftVoucher(gift));
}
-}
\ No newline at end of file
+}
diff --git a/src/Web/Grand.Web.AdminShared/Interfaces/IGiftVoucherViewModelService.cs b/src/Web/Grand.Web.AdminShared/Interfaces/IGiftVoucherViewModelService.cs
index 8c6cfae0a..31c441da0 100644
--- a/src/Web/Grand.Web.AdminShared/Interfaces/IGiftVoucherViewModelService.cs
+++ b/src/Web/Grand.Web.AdminShared/Interfaces/IGiftVoucherViewModelService.cs
@@ -9,7 +9,7 @@ public interface IGiftVoucherViewModelService
Task<GiftVoucherModel> PrepareGiftVoucherModel(GiftVoucherModel model = null);
Task<(IEnumerable<GiftVoucherModel> giftVoucherModels, int totalCount)> PrepareGiftVoucherModel(
- GiftVoucherListModel model, int pageIndex, int pageSize);
+ GiftVoucherListModel model, int pageIndex, int pageSize, string storeId = "");
Task<GiftVoucherModel> FillGiftVoucherModel(GiftVoucher giftVoucher, GiftVoucherModel model);
Task NotifyRecipient(GiftVoucher giftVoucher);
@@ -21,4 +21,4 @@ public interface IGiftVoucherViewModelService
Task<(IEnumerable<GiftVoucherModel.GiftVoucherUsageHistoryModel> giftVoucherUsageHistoryModels, int totalCount)>
PrepareGiftVoucherUsageHistoryModels(GiftVoucher giftVoucher, int pageIndex, int pageSize);
-}
\ No newline at end of file
+}
diff --git a/src/Web/Grand.Web.AdminShared/Services/GiftVoucherViewModelService.cs b/src/Web/Grand.Web.AdminShared/Services/GiftVoucherViewModelService.cs
index 9f33c1b07..0ffb313a4 100644
--- a/src/Web/Grand.Web.AdminShared/Services/GiftVoucherViewModelService.cs
+++ b/src/Web/Grand.Web.AdminShared/Services/GiftVoucherViewModelService.cs
@@ -78,7 +78,7 @@ public class GiftVoucherViewModelService : IGiftVoucherViewModelService
}
public virtual async Task<(IEnumerable<GiftVoucherModel> giftVoucherModels, int totalCount)>
- PrepareGiftVoucherModel(GiftVoucherListModel model, int pageIndex, int pageSize)
+ PrepareGiftVoucherModel(GiftVoucherListModel model, int pageIndex, int pageSize, string storeId = "")
{
bool? isGiftVoucherActivated = null;
switch (model.ActivatedId)
@@ -92,6 +92,7 @@ public class GiftVoucherViewModelService : IGiftVoucherViewModelService
}
var giftVouchers = await _giftVoucherService.GetAllGiftVouchers(
+ storeId: storeId,
isGiftVoucherActivated: isGiftVoucherActivated,
giftVoucherCouponCode: model.CouponCode,
recipientName: model.RecipientName,
@@ -239,4 +240,4 @@ public class GiftVoucherViewModelService : IGiftVoucherViewModelService
private readonly IStoreService _storeService;
#endregion
-}
\ No newline at end of file
+}
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/GiftVoucher/Create.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/GiftVoucher/Create.cshtml
new file mode 100644
index 000000000..d0d00e986
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/GiftVoucher/Create.cshtml
@@ -0,0 +1,34 @@
+@model GiftVoucherModel
+
+@{
+ ViewBag.Title = Loc["Admin.GiftVouchers.AddNew"];
+}
+
+<form asp-area="@Constants.AreaStore" asp-controller="GiftVoucher" 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-gift"></i>
+ @Loc["Admin.GiftVouchers.AddNew"]
+ <small>
+ <i class="fa fa-arrow-circle-left"></i>@Html.ActionLink(Loc["Admin.GiftVouchers.BackToList"], "List")
+ </small>
+ </div>
+ <div class="actions 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 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/GiftVoucher/Edit.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/GiftVoucher/Edit.cshtml
new file mode 100644
index 000000000..f2d5c921b
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/GiftVoucher/Edit.cshtml
@@ -0,0 +1,38 @@
+@model GiftVoucherModel
+
+@{
+ ViewBag.Title = Loc["Admin.GiftVouchers.EditGiftVoucherDetails"];
+}
+
+<form asp-area="@Constants.AreaStore" asp-controller="GiftVoucher" 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-gift"></i>
+ @Loc["Admin.GiftVouchers.EditGiftVoucherDetails"]
+ <small>
+ <i class="fa fa-arrow-circle-left"></i>@Html.ActionLink(Loc["Admin.GiftVouchers.BackToList"], "List")
+ </small>
+ </div>
+ <div class="actions 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>
+ <span id="giftvoucher-delete" class="btn red">
+ <i class="fa fa-trash-o"></i> @Loc["Admin.Common.Delete"]
+ </span>
+ </div>
+ </div>
+ <div class="x_content form">
+ <partial name="Partials/CreateOrUpdate" model="Model"/>
+ </div>
+ </div>
+ </div>
+ </div>
+</form>
+<admin-delete-confirmation button-id="giftvoucher-delete"/>
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/GiftVoucher/List.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/GiftVoucher/List.cshtml
new file mode 100644
index 000000000..22465c5d8
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/GiftVoucher/List.cshtml
@@ -0,0 +1,156 @@
+@model GiftVoucherListModel
+@inject AdminAreaSettings adminAreaSettings
+
+@{
+ ViewBag.Title = Loc["Admin.GiftVouchers"];
+}
+
+<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-gift"></i>
+ @Loc["Admin.GiftVouchers"]
+ </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">
+ <div class="form-horizontal">
+ <div class="form-body">
+ <div class="row align-items-end">
+ <div class="col-md-3 col-sm-12 col-12">
+ <div class="form-group mb-0">
+ <admin-label asp-for="ActivatedId" class="d-flex flex-column align-items-start mw-100 px-0 text-left"/>
+ <admin-select asp-for="ActivatedId" asp-items="Model.ActivatedList"/>
+ </div>
+ </div>
+ <div class="col-md-3 col-sm-12 col-12">
+ <div class="form-group mb-0">
+ <admin-label asp-for="CouponCode" class="d-flex flex-column align-items-start mw-100 px-0 text-left"/>
+ <admin-input asp-for="CouponCode"/>
+ </div>
+ </div>
+ <div class="col-md-3 col-sm-12 col-12">
+ <div class="form-group mb-0">
+ <admin-label asp-for="RecipientName" class="d-flex flex-column align-items-start mw-100 px-0 text-left"/>
+ <admin-input asp-for="RecipientName"/>
+ </div>
+ </div>
+ <div class="col-md-3 col-sm-12 col-12 mt-md-0 mt-3">
+ <div class="form-actions">
+ <button class="btn btn-success filter-submit" id="search-giftvouchers">
+ <i class="fa fa-search"></i> @Loc["Admin.Common.Search"]
+ </button>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="x_content">
+ <div id="giftvouchers-grid"></div>
+ </div>
+ </div>
+ </div>
+</div>
+
+<script>
+ $(document).ready(function () {
+ $("#giftvouchers-grid").kendoGrid({
+ dataSource: {
+ transport: {
+ read: {
+ url: "@Html.Raw(Url.Action("GiftVoucherList", "GiftVoucher", new { area = Constants.AreaStore }))",
+ type: "POST",
+ dataType: "json",
+ data: additionalData
+ }
+ },
+ 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)]
+ },
+ editable: {
+ confirmation: false,
+ mode: "inline"
+ },
+ scrollable: false,
+ columns: [{
+ field: "AmountStr",
+ title: "@Loc["Admin.GiftVouchers.Fields.Amount"]",
+ template: '# if(StoreId) {# <a class="k-link" href="Edit/#=Id#">#=AmountStr#</a> #} else {# #=AmountStr# #} #',
+ width: 100,
+ }, {
+ field: "RemainingAmountStr",
+ title: "@Loc["Admin.GiftVouchers.Fields.RemainingAmount"]",
+ template: '# if(StoreId) {# <a class="k-link" href="Edit/#=Id#">#=RemainingAmountStr#</a> #} else {# #=RemainingAmountStr# #} #',
+ width: 100,
+ }, {
+ field: "Code",
+ title: "@Loc["Admin.GiftVouchers.Fields.Code"]",
+ template: '# if(StoreId) {# <a class="k-link" href="Edit/#=Id#">#=Code#</a> #} else {# #=Code# #} #',
+ width: 120,
+ }, {
+ field: "RecipientName",
+ title: "@Loc["Admin.GiftVouchers.Fields.RecipientName"]",
+ minScreenWidth: 750,
+ width: 150,
+ }, {
+ field: "IsGiftVoucherActivated",
+ title: "@Loc["Admin.GiftVouchers.Fields.IsGiftVoucherActivated"]",
+ width: 100,
+ headerAttributes: { style: "text-align:center" },
+ attributes: { style: "text-align:center" },
+ template: '# if(IsGiftVoucherActivated) {# <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> #} #'
+ }, {
+ field: "CreatedOn",
+ title: "@Loc["Admin.GiftVouchers.Fields.CreatedOn"]",
+ width: 180,
+ type: "date",
+ format: "{0:G}"
+ }]
+ });
+
+ $('#search-giftvouchers').click(function () {
+ var grid = $('#giftvouchers-grid').data('kendoGrid');
+ grid.dataSource.page(1);
+ return false;
+ });
+ });
+
+ $("#@Html.IdFor(model => model.CouponCode)").keydown(function (event) {
+ if (event.keyCode == 13) {
+ $("#search-giftvouchers").click();
+ return false;
+ }
+ });
+
+ function additionalData() {
+ var data = {
+ ActivatedId: $('#@Html.IdFor(model => model.ActivatedId)').val(),
+ CouponCode: $('#@Html.IdFor(model => model.CouponCode)').val(),
+ RecipientName: $('#@Html.IdFor(model => model.RecipientName)').val()
+ };
+ addAntiForgeryToken(data);
+ return data;
+ }
+</script>
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/GiftVoucher/Partials/CreateOrUpdate.TabHistory.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/GiftVoucher/Partials/CreateOrUpdate.TabHistory.cshtml
new file mode 100644
index 000000000..00e3a7c5d
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/GiftVoucher/Partials/CreateOrUpdate.TabHistory.cshtml
@@ -0,0 +1,58 @@
+@model GiftVoucherModel
+@inject AdminAreaSettings adminAreaSettings
+
+<div id="usagehistory-grid"></div>
+<script>
+ $(document).ready(function () {
+ $("#usagehistory-grid").kendoGrid({
+ dataSource: {
+ transport: {
+ read: {
+ url: "@Html.Raw(Url.Action("UsageHistoryList", "GiftVoucher", new { giftVoucherId = Model.Id, 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)]
+ },
+ editable: {
+ confirmation: false,
+ mode: "inline"
+ },
+ scrollable: false,
+ columns: [{
+ field: "CreatedOn",
+ title: "@Loc["Admin.GiftVouchers.History.CreatedOn"]",
+ width: 200,
+ type: "date",
+ format: "{0:G}"
+ }, {
+ field: "OrderId",
+ title: "@Loc["Admin.GiftVouchers.History.Order"]",
+ width: 200,
+ template: '<a href="@Url.Action("Edit", "Order", new { area = Constants.AreaStore })/#=OrderId#" class="k-button"><span class="k-icon k-i-eye"></span>&nbsp;@Loc["Admin.Common.View"] #=OrderNumber#</a>'
+ }, {
+ field: "UsedValue",
+ title: "@Loc["Admin.GiftVouchers.History.UsedValue"]",
+ width: 200
+ }]
+ });
+ });
+</script>
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/GiftVoucher/Partials/CreateOrUpdate.TabInfo.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/GiftVoucher/Partials/CreateOrUpdate.TabInfo.cshtml
new file mode 100644
index 000000000..2d6b885f9
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/GiftVoucher/Partials/CreateOrUpdate.TabInfo.cshtml
@@ -0,0 +1,181 @@
+@model GiftVoucherModel
+
+<script>
+ $(document).ready(function () {
+ $("#@Html.IdFor(model => model.GiftVoucherTypeId)").change(toggleGiftVoucherType);
+ toggleGiftVoucherType();
+ });
+
+ function toggleGiftVoucherType() {
+ var selectedGiftVoucherTypeId = $("#@Html.IdFor(model => model.GiftVoucherTypeId)").val();
+ if (selectedGiftVoucherTypeId == @(((int)GiftVoucherType.Virtual).ToString())) {
+ $('#pnlRecipientEmail').show();
+ $('#pnlSenderEmail').show();
+ $('#pnlNotifyRecipient').show();
+ }
+ else {
+ $('#pnlRecipientEmail').hide();
+ $('#pnlSenderEmail').hide();
+ $('#pnlNotifyRecipient').hide();
+ }
+ }
+</script>
+
+<div class="form-horizontal">
+ <div class="form-body">
+ <div class="form-group">
+ <admin-label asp-for="GiftVoucherTypeId"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-select asp-for="GiftVoucherTypeId" asp-items="EnumTranslationService.ToSelectList((GiftVoucherType)Model.GiftVoucherTypeId)"/>
+ <span asp-validation-for="GiftVoucherTypeId"></span>
+ </div>
+ </div>
+ @if (!string.IsNullOrEmpty(Model.PurchasedWithOrderId))
+ {
+ <div class="form-group">
+ <admin-label asp-for="PurchasedWithOrderId"/>
+ <div class="col-md-9 col-sm-9">
+ <label class="control-label">
+ <a href="@Url.Action("Edit", "Order", new { Id = Model.PurchasedWithOrderId, area = Constants.AreaStore })" class="k-button"><span class="k-icon k-i-eye"></span>&nbsp;@Loc["Admin.Common.View"] #@Model.PurchasedWithOrderNumber</a>
+ </label>
+ </div>
+ </div>
+ }
+ <div class="form-group">
+ <admin-label asp-for="Amount"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="Amount"/>
+ @if (!string.IsNullOrEmpty(Model.Id))
+ {
+ <text>[@Model.CurrencyCode]</text>
+ }
+ <span asp-validation-for="Amount"></span>
+ </div>
+ </div>
+ @if (string.IsNullOrEmpty(Model.Id))
+ {
+ <div class="form-group">
+ <admin-label asp-for="CurrencyCode" class="col-sm-3 control-label"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-select asp-for="CurrencyCode" asp-items="Model.AvailableCurrencies"/>
+ <span asp-validation-for="CurrencyCode"></span>
+ </div>
+ </div>
+ }
+ @if (!string.IsNullOrEmpty(Model.Id))
+ {
+ <div class="form-group">
+ <admin-label asp-for="RemainingAmountStr"/>
+ <div class="col-md-9 col-sm-9">
+ <label class="control-label">@Model.RemainingAmountStr</label>
+ </div>
+ </div>
+ }
+ <div class="form-group">
+ <admin-label asp-for="IsGiftVoucherActivated"/>
+ <div class="col-md-9 col-sm-9">
+ <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
+ <admin-input asp-for="IsGiftVoucherActivated"/>
+ <div class="control__indicator"></div>
+ </label>
+ <span asp-validation-for="IsGiftVoucherActivated"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="Code"/>
+ <div class="col-md-4 col-sm-6">
+ <div class="input-group">
+ <div class="input-group-control">
+ <admin-input asp-for="Code"/>
+ </div>
+ <div class="input-group-append">
+ <input type="button" id="generateCouponCode" class="btn default" value="@Loc["Admin.GiftVouchers.Fields.Code.Generate"]"/>
+ </div>
+ </div>
+ <span asp-validation-for="Code"></span>
+ <script>
+ $(document).ready(function () {
+ $('#generateCouponCode').click(function () {
+ var postData = {};
+ addAntiForgeryToken(postData);
+
+ $.ajax({
+ cache:false,
+ type: "POST",
+ url: "@(Url.Action("GenerateCouponCode", "GiftVoucher", new { area = Constants.AreaStore }))",
+ data: postData,
+ success: function (data) {
+ $('#@Html.IdFor(model => model.Code)').val(data.CouponCode);
+ },
+ error:function (){
+ alert('Failed to generate code.');
+ }
+ });
+ });
+ });
+ </script>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="RecipientName"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="RecipientName"/>
+ <span asp-validation-for="RecipientName"></span>
+ </div>
+ </div>
+ <div class="form-group" id="pnlRecipientEmail">
+ <admin-label asp-for="RecipientEmail"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="RecipientEmail"/>
+ <span asp-validation-for="RecipientEmail"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="SenderName"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="SenderName"/>
+ <span asp-validation-for="SenderName"></span>
+ </div>
+ </div>
+ <div class="form-group" id="pnlSenderEmail">
+ <admin-label asp-for="SenderEmail"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="SenderEmail"/>
+ <span asp-validation-for="SenderEmail"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="Message"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-textarea asp-for="Message"></admin-textarea>
+ <span asp-validation-for="Message"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="ValidTo"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="ValidTo"/>
+ <span asp-validation-for="ValidTo"></span>
+ </div>
+ </div>
+ @if (!string.IsNullOrEmpty(Model.Id))
+ {
+ <div class="form-group" id="pnlNotifyRecipient">
+ <admin-label asp-for="IsRecipientNotified"/>
+ <div class="col-md-9 col-sm-9">
+ <label class="control-label">@Model.IsRecipientNotified.ToString()</label>
+ <button type="submit" name="notifyRecipient" asp-action="NotifyRecipient" class="k-button"><span class="k-icon k-i-notification"></span>&nbsp;@Loc["Admin.GiftVouchers.Fields.IsRecipientNotified.Notify"]</button>
+ </div>
+ </div>
+ }
+ @if (!string.IsNullOrEmpty(Model.Id))
+ {
+ <div class="form-group">
+ <admin-label asp-for="CreatedOn"/>
+ <div class="col-md-9 col-sm-9">
+ <label class="control-label"> @Model.CreatedOn</label>
+ </div>
+ </div>
+ }
+ </div>
+</div>
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/GiftVoucher/Partials/CreateOrUpdate.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/GiftVoucher/Partials/CreateOrUpdate.cshtml
new file mode 100644
index 000000000..e7a8fba1a
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/GiftVoucher/Partials/CreateOrUpdate.cshtml
@@ -0,0 +1,26 @@
+@model GiftVoucherModel
+
+<div asp-validation-summary="All"></div>
+<input asp-for="Id" type="hidden"/>
+<input asp-for="StoreId" type="hidden"/>
+<admin-tabstrip name="giftvoucher-edit">
+ <items>
+ <tabstrip-item text="@Loc["Admin.GiftVouchers.Info"]" tab-index="0">
+ <content>
+ <div>
+ <partial name="Partials/CreateOrUpdate.TabInfo" model="Model"/>
+ </div>
+ </content>
+ </tabstrip-item>
+ @if (!string.IsNullOrEmpty(Model.Id))
+ {
+ <tabstrip-item text="@Loc["Admin.GiftVouchers.History"]" tab-index="1">
+ <content>
+ <div>
+ <partial name="Partials/CreateOrUpdate.TabHistory" model="Model"/>
+ </div>
+ </content>
+ </tabstrip-item>
+ }
+ </items>
+</admin-tabstrip>
diff --git a/src/Web/Grand.Web.Store/Controllers/GiftVoucherController.cs b/src/Web/Grand.Web.Store/Controllers/GiftVoucherController.cs
new file mode 100644
index 000000000..f95998f86
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Controllers/GiftVoucherController.cs
@@ -0,0 +1,214 @@
+using Grand.Business.Core.Interfaces.Checkout.GiftVouchers;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Domain.Orders;
+using Grand.Domain.Permissions;
+using Grand.Infrastructure;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Models.Orders;
+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.GiftVouchers)]
+public class GiftVoucherController : BaseStoreController
+{
+ private readonly IGiftVoucherViewModelService _giftVoucherViewModelService;
+ private readonly IGiftVoucherService _giftVoucherService;
+ private readonly ITranslationService _translationService;
+ private readonly IContextAccessor _contextAccessor;
+
+ public GiftVoucherController(
+ IGiftVoucherViewModelService giftVoucherViewModelService,
+ IGiftVoucherService giftVoucherService,
+ ITranslationService translationService,
+ IContextAccessor contextAccessor)
+ {
+ _giftVoucherViewModelService = giftVoucherViewModelService;
+ _giftVoucherService = giftVoucherService;
+ _translationService = translationService;
+ _contextAccessor = contextAccessor;
+ }
+
+ private string CurrentStoreId => _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+
+ public IActionResult Index()
+ {
+ return RedirectToAction("List");
+ }
+
+ public IActionResult List()
+ {
+ var model = _giftVoucherViewModelService.PrepareGiftVoucherListModel();
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.List)]
+ [HttpPost]
+ public async Task<IActionResult> GiftVoucherList(DataSourceRequest command, GiftVoucherListModel model)
+ {
+ var (giftVoucherModels, totalCount) =
+ await _giftVoucherViewModelService.PrepareGiftVoucherModel(model, command.Page, command.PageSize,
+ CurrentStoreId);
+
+ return Json(new DataSourceResult {
+ Data = giftVoucherModels.ToList(),
+ Total = totalCount
+ });
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Create)]
+ public async Task<IActionResult> Create()
+ {
+ var model = await PrepareStoreGiftVoucherModel();
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Create)]
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public async Task<IActionResult> Create(GiftVoucherModel model, bool continueEditing)
+ {
+ model.StoreId = CurrentStoreId;
+
+ if (ModelState.IsValid)
+ {
+ var giftVoucher = await _giftVoucherViewModelService.InsertGiftVoucherModel(model);
+ Success(_translationService.GetResource("Admin.GiftVouchers.Added"));
+ return continueEditing ? RedirectToAction("Edit", new { id = giftVoucher.Id }) : RedirectToAction("List");
+ }
+
+ model = await PrepareStoreGiftVoucherModel(model);
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Preview)]
+ public async Task<IActionResult> Edit(string id)
+ {
+ var giftVoucher = await GetCurrentStoreGiftVoucher(id);
+ if (giftVoucher == null)
+ return RedirectToAction("List");
+
+ var model = await _giftVoucherViewModelService.PrepareGiftVoucherModel(giftVoucher);
+ model = SetCurrentStore(model);
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public async Task<IActionResult> Edit(GiftVoucherModel model, bool continueEditing)
+ {
+ var giftVoucher = await GetCurrentStoreGiftVoucher(model.Id);
+ if (giftVoucher == null)
+ return RedirectToAction("List");
+
+ model.StoreId = CurrentStoreId;
+ await _giftVoucherViewModelService.FillGiftVoucherModel(giftVoucher, model);
+
+ if (ModelState.IsValid)
+ {
+ giftVoucher = await _giftVoucherViewModelService.UpdateGiftVoucherModel(giftVoucher, model);
+ Success(_translationService.GetResource("Admin.GiftVouchers.Updated"));
+
+ if (continueEditing)
+ {
+ await SaveSelectedTabIndex();
+ return RedirectToAction("Edit", new { id = giftVoucher.Id });
+ }
+
+ return RedirectToAction("List");
+ }
+
+ model = SetCurrentStore(model);
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [HttpPost]
+ public IActionResult GenerateCouponCode()
+ {
+ return Json(new { CouponCode = _giftVoucherService.GenerateGiftVoucherCode() });
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [HttpPost]
+ public async Task<IActionResult> NotifyRecipient(GiftVoucherNotifyRecipient model)
+ {
+ var giftVoucher = await GetCurrentStoreGiftVoucher(model.Id);
+ if (giftVoucher == null)
+ return RedirectToAction("List");
+
+ try
+ {
+ if (ModelState.IsValid)
+ await _giftVoucherViewModelService.NotifyRecipient(giftVoucher);
+ else
+ Error(ModelState);
+ }
+ catch (Exception exc)
+ {
+ Error(exc, false);
+ }
+
+ return RedirectToAction("Edit", new { id = model.Id });
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Delete)]
+ [HttpPost]
+ public async Task<IActionResult> Delete(GiftVoucherDeleteModel model)
+ {
+ var giftVoucher = await GetCurrentStoreGiftVoucher(model.Id);
+ if (giftVoucher == null)
+ return RedirectToAction("List");
+
+ if (ModelState.IsValid)
+ {
+ await _giftVoucherViewModelService.DeleteGiftVoucher(giftVoucher);
+ Success(_translationService.GetResource("Admin.GiftVouchers.Deleted"));
+ return RedirectToAction("List");
+ }
+
+ Error(ModelState);
+ return RedirectToAction("Edit", new { id = giftVoucher.Id });
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Preview)]
+ [HttpPost]
+ public async Task<IActionResult> UsageHistoryList(string giftVoucherId, DataSourceRequest command)
+ {
+ var giftVoucher = await GetCurrentStoreGiftVoucher(giftVoucherId);
+ if (giftVoucher == null)
+ throw new ArgumentException("No gift voucher found with the specified id");
+
+ var (giftVoucherUsageHistoryModels, totalCount) =
+ await _giftVoucherViewModelService.PrepareGiftVoucherUsageHistoryModels(giftVoucher, command.Page,
+ command.PageSize);
+
+ return Json(new DataSourceResult {
+ Data = giftVoucherUsageHistoryModels.ToList(),
+ Total = totalCount
+ });
+ }
+
+ private async Task<GiftVoucherModel> PrepareStoreGiftVoucherModel(GiftVoucherModel model = null)
+ {
+ model = await _giftVoucherViewModelService.PrepareGiftVoucherModel(model);
+ return SetCurrentStore(model);
+ }
+
+ private GiftVoucherModel SetCurrentStore(GiftVoucherModel model)
+ {
+ model.StoreId = CurrentStoreId;
+ model.AvailableStores = model.AvailableStores.Where(x => x.Value == CurrentStoreId).ToList();
+ return model;
+ }
+
+ private async Task<GiftVoucher> GetCurrentStoreGiftVoucher(string id)
+ {
+ var giftVoucher = await _giftVoucherService.GetGiftVoucherById(id);
+ return giftVoucher?.StoreId == CurrentStoreId ? giftVoucher : null;
+ }
+}