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.

ARCH-001 Phase 23: Shipping sub-entities (Warehouse/ShippingMethod/DeliveryDate/PickupPoint) consolidation (#824)

Krzysztof Pajak9b134561ee2e
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseDeliveryDateControllerTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseDeliveryDateControllerTests.cs
new file mode 100644
index 000000000..096d206a4
--- /dev/null
+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseDeliveryDateControllerTests.cs
@@ -0,0 +1,149 @@
+using Grand.Business.Core.Interfaces.Checkout.Shipping;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Localization;
+using Grand.Domain.Stores;
+using Grand.Infrastructure.Mapper;
+using Grand.Mapping;
+using Grand.Web.Admin.Controllers;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Mapper;
+using Grand.Web.AdminShared.Models.Shipping;
+using Grand.Web.AdminShared.Services;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+using DeliveryDate = Grand.Domain.Shipping.DeliveryDate;
+
+namespace Grand.Web.Admin.Tests.Controllers;
+
+[TestClass]
+public class BaseDeliveryDateControllerTests
+{
+ private Mock<IDeliveryDateService> _deliveryDateServiceMock;
+ private Mock<ILanguageService> _languageServiceMock;
+ private Mock<IStoreService> _storeServiceMock;
+ private Mock<ITranslationService> _translationServiceMock;
+
+ [TestInitialize]
+ public void Setup()
+ {
+ var mapperConfig = new MapperConfiguration(cfg => cfg.AddProfile<DeliveryDateProfile>());
+ AutoMapperConfig.Init(mapperConfig);
+
+ _deliveryDateServiceMock = new Mock<IDeliveryDateService>();
+ _languageServiceMock = new Mock<ILanguageService>();
+ _languageServiceMock.Setup(l => l.GetAllLanguages(It.IsAny<bool>(), It.IsAny<string>()))
+ .ReturnsAsync(new List<Language>());
+ _storeServiceMock = new Mock<IStoreService>();
+ _storeServiceMock.Setup(s => s.GetAllStores()).ReturnsAsync(new List<Store>());
+ _translationServiceMock = new Mock<ITranslationService>();
+ _translationServiceMock.Setup(t => t.GetResource(It.IsAny<string>())).Returns("msg");
+ }
+
+ private DeliveryDateController Build(IAdminDataScope<DeliveryDate> scope) =>
+ new(_deliveryDateServiceMock.Object, _languageServiceMock.Object, _storeServiceMock.Object,
+ _translationServiceMock.Object, scope)
+ {
+ ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() },
+ TempData = new Microsoft.AspNetCore.Mvc.ViewFeatures.TempDataDictionary(
+ new DefaultHttpContext(), Mock.Of<Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataProvider>())
+ };
+
+ [TestMethod]
+ public async Task Create_GlobalScope_DoesNotForceStoreId()
+ {
+ var controller = Build(new GlobalAdminDataScope<DeliveryDate>());
+ DeliveryDate inserted = null;
+ _deliveryDateServiceMock.Setup(s => s.InsertDeliveryDate(It.IsAny<DeliveryDate>()))
+ .Callback<DeliveryDate>(m => inserted = m).Returns(Task.CompletedTask);
+
+ var model = new DeliveryDateModel { Name = "DD1" };
+ await controller.CreateDeliveryDate(model, false);
+
+ Assert.AreEqual("", inserted!.StoreId ?? "");
+ }
+
+ [TestMethod]
+ public async Task Create_StoreScope_ForcesStoreId()
+ {
+ var contextAccessor = new Mock<Grand.Infrastructure.IContextAccessor>();
+ var workContext = new Mock<Grand.Infrastructure.IWorkContext>();
+ workContext.Setup(w => w.CurrentCustomer)
+ .Returns(new Grand.Domain.Customers.Customer { StaffStoreId = "store-1" });
+ contextAccessor.Setup(c => c.WorkContext).Returns(workContext.Object);
+ var scope = new StoreDeliveryDateDataScope(contextAccessor.Object);
+ var controller = Build(scope);
+
+ DeliveryDate inserted = null;
+ _deliveryDateServiceMock.Setup(s => s.InsertDeliveryDate(It.IsAny<DeliveryDate>()))
+ .Callback<DeliveryDate>(m => inserted = m).Returns(Task.CompletedTask);
+
+ var model = new DeliveryDateModel { Name = "DD1" };
+ await controller.CreateDeliveryDate(model, false);
+
+ Assert.AreEqual("store-1", inserted!.StoreId);
+ }
+
+ [TestMethod]
+ public async Task Edit_StoreScope_CrossStoreDeliveryDate_Denied()
+ {
+ var contextAccessor = new Mock<Grand.Infrastructure.IContextAccessor>();
+ var workContext = new Mock<Grand.Infrastructure.IWorkContext>();
+ workContext.Setup(w => w.CurrentCustomer)
+ .Returns(new Grand.Domain.Customers.Customer { StaffStoreId = "store-1" });
+ contextAccessor.Setup(c => c.WorkContext).Returns(workContext.Object);
+ var scope = new StoreDeliveryDateDataScope(contextAccessor.Object);
+ var controller = Build(scope);
+
+ _deliveryDateServiceMock.Setup(s => s.GetDeliveryDateById("dd-2"))
+ .ReturnsAsync(new DeliveryDate { Id = "dd-2", StoreId = "store-2" });
+
+ var result = await controller.EditDeliveryDate("dd-2") as RedirectToActionResult;
+
+ Assert.IsNotNull(result);
+ Assert.AreEqual("DeliveryDates", result.ActionName);
+ _deliveryDateServiceMock.Verify(s => s.UpdateDeliveryDate(It.IsAny<DeliveryDate>()), Times.Never);
+ }
+
+ [TestMethod]
+ public async Task CreateDeliveryDate_Get_DefaultsColorSquaresRgb()
+ {
+ var controller = Build(new GlobalAdminDataScope<DeliveryDate>());
+
+ var result = await controller.CreateDeliveryDate() as ViewResult;
+
+ var model = result!.Model as DeliveryDateModel;
+ Assert.IsNotNull(model);
+ Assert.AreEqual("#000000", model.ColorSquaresRgb);
+ }
+
+ [TestMethod]
+ public async Task EditDeliveryDate_Get_FillsBlankColorSquaresRgb_WithDefault()
+ {
+ var controller = Build(new GlobalAdminDataScope<DeliveryDate>());
+ _deliveryDateServiceMock.Setup(s => s.GetDeliveryDateById("dd-1"))
+ .ReturnsAsync(new DeliveryDate { Id = "dd-1", ColorSquaresRgb = "" });
+
+ var result = await controller.EditDeliveryDate("dd-1") as ViewResult;
+
+ var model = result!.Model as DeliveryDateModel;
+ Assert.IsNotNull(model);
+ Assert.AreEqual("#000000", model.ColorSquaresRgb);
+ }
+
+ [TestMethod]
+ public async Task EditDeliveryDate_Get_PreservesExistingColorSquaresRgb()
+ {
+ var controller = Build(new GlobalAdminDataScope<DeliveryDate>());
+ _deliveryDateServiceMock.Setup(s => s.GetDeliveryDateById("dd-1"))
+ .ReturnsAsync(new DeliveryDate { Id = "dd-1", ColorSquaresRgb = "#ff0000" });
+
+ var result = await controller.EditDeliveryDate("dd-1") as ViewResult;
+
+ var model = result!.Model as DeliveryDateModel;
+ Assert.IsNotNull(model);
+ Assert.AreEqual("#ff0000", model.ColorSquaresRgb);
+ }
+}
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/BasePickupPointControllerTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/BasePickupPointControllerTests.cs
new file mode 100644
index 000000000..0592d0477
--- /dev/null
+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/BasePickupPointControllerTests.cs
@@ -0,0 +1,132 @@
+using Grand.Business.Core.Interfaces.Checkout.Shipping;
+using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain;
+using Grand.Domain.Directory;
+using Grand.Domain.Shipping;
+using Grand.Domain.Stores;
+using Grand.Infrastructure.Mapper;
+using Grand.Mapping;
+using Grand.Web.Admin.Controllers;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Mapper;
+using Grand.Web.AdminShared.Models.Shipping;
+using Grand.Web.AdminShared.Services;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+using PickupPoint = Grand.Domain.Shipping.PickupPoint;
+
+namespace Grand.Web.Admin.Tests.Controllers;
+
+[TestClass]
+public class BasePickupPointControllerTests
+{
+ private Mock<IPickupPointService> _pickupPointServiceMock;
+ private Mock<IWarehouseService> _warehouseServiceMock;
+ private Mock<ICountryService> _countryServiceMock;
+ private Mock<IStoreService> _storeServiceMock;
+ private Mock<ITranslationService> _translationServiceMock;
+
+ [TestInitialize]
+ public void Setup()
+ {
+ var mapperConfig = new MapperConfiguration(cfg => cfg.AddProfile<PickupPointProfile>());
+ AutoMapperConfig.Init(mapperConfig);
+
+ _pickupPointServiceMock = new Mock<IPickupPointService>();
+ _warehouseServiceMock = new Mock<IWarehouseService>();
+ _warehouseServiceMock.Setup(w => w.GetAllWarehouses(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
+ .ReturnsAsync(new PagedList<Warehouse>());
+ _countryServiceMock = new Mock<ICountryService>();
+ _countryServiceMock.Setup(c => c.GetAllCountries(It.IsAny<string>(), It.IsAny<string>(), true))
+ .ReturnsAsync(new List<Country>());
+ _storeServiceMock = new Mock<IStoreService>();
+ _storeServiceMock.Setup(s => s.GetAllStores()).ReturnsAsync(new List<Store>());
+ _translationServiceMock = new Mock<ITranslationService>();
+ _translationServiceMock.Setup(t => t.GetResource(It.IsAny<string>())).Returns("msg");
+ }
+
+ private PickupPointController Build(IAdminDataScope<PickupPoint> scope) =>
+ new(_pickupPointServiceMock.Object, _warehouseServiceMock.Object, _countryServiceMock.Object,
+ _storeServiceMock.Object, _translationServiceMock.Object, scope)
+ {
+ ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() },
+ TempData = new Microsoft.AspNetCore.Mvc.ViewFeatures.TempDataDictionary(
+ new DefaultHttpContext(), Mock.Of<Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataProvider>())
+ };
+
+ [TestMethod]
+ public async Task Create_GlobalScope_DoesNotForceStoreId()
+ {
+ var controller = Build(new GlobalAdminDataScope<PickupPoint>());
+ PickupPoint inserted = null;
+ _pickupPointServiceMock.Setup(s => s.InsertPickupPoint(It.IsAny<PickupPoint>()))
+ .Callback<PickupPoint>(p => inserted = p).Returns(Task.CompletedTask);
+
+ var model = new PickupPointModel { Name = "PP1", Address = new() };
+ await controller.CreatePickupPoint(model, false);
+
+ Assert.AreEqual("", inserted!.StoreId ?? "");
+ }
+
+ [TestMethod]
+ public async Task Create_StoreScope_ForcesStoreId()
+ {
+ var contextAccessor = new Mock<Grand.Infrastructure.IContextAccessor>();
+ var workContext = new Mock<Grand.Infrastructure.IWorkContext>();
+ workContext.Setup(w => w.CurrentCustomer)
+ .Returns(new Grand.Domain.Customers.Customer { StaffStoreId = "store-1" });
+ contextAccessor.Setup(c => c.WorkContext).Returns(workContext.Object);
+ var scope = new StorePickupPointDataScope(contextAccessor.Object);
+ var controller = Build(scope);
+
+ PickupPoint inserted = null;
+ _pickupPointServiceMock.Setup(s => s.InsertPickupPoint(It.IsAny<PickupPoint>()))
+ .Callback<PickupPoint>(p => inserted = p).Returns(Task.CompletedTask);
+
+ var model = new PickupPointModel { Name = "PP1", Address = new() };
+ await controller.CreatePickupPoint(model, false);
+
+ Assert.AreEqual("store-1", inserted!.StoreId);
+ }
+
+ [TestMethod]
+ public async Task Edit_StoreScope_CrossStorePickupPoint_Denied()
+ {
+ var contextAccessor = new Mock<Grand.Infrastructure.IContextAccessor>();
+ var workContext = new Mock<Grand.Infrastructure.IWorkContext>();
+ workContext.Setup(w => w.CurrentCustomer)
+ .Returns(new Grand.Domain.Customers.Customer { StaffStoreId = "store-1" });
+ contextAccessor.Setup(c => c.WorkContext).Returns(workContext.Object);
+ var scope = new StorePickupPointDataScope(contextAccessor.Object);
+ var controller = Build(scope);
+
+ _pickupPointServiceMock.Setup(s => s.GetPickupPointById("pp-2"))
+ .ReturnsAsync(new PickupPoint { Id = "pp-2", StoreId = "store-2" });
+
+ var result = await controller.EditPickupPoint("pp-2") as RedirectToActionResult;
+
+ Assert.IsNotNull(result);
+ Assert.AreEqual("PickupPoints", result.ActionName);
+ _pickupPointServiceMock.Verify(s => s.UpdatePickupPoint(It.IsAny<PickupPoint>()), Times.Never);
+ }
+
+ [TestMethod]
+ public async Task CreateGet_StoreScope_WarehouseDropdownScopedToOwnStore()
+ {
+ var contextAccessor = new Mock<Grand.Infrastructure.IContextAccessor>();
+ var workContext = new Mock<Grand.Infrastructure.IWorkContext>();
+ workContext.Setup(w => w.CurrentCustomer)
+ .Returns(new Grand.Domain.Customers.Customer { StaffStoreId = "store-1" });
+ contextAccessor.Setup(c => c.WorkContext).Returns(workContext.Object);
+ var scope = new StorePickupPointDataScope(contextAccessor.Object);
+ var controller = Build(scope);
+
+ await controller.CreatePickupPoint();
+
+ _warehouseServiceMock.Verify(s => s.GetAllWarehouses("store-1", 0, int.MaxValue), Times.Once);
+ }
+}
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseShippingMethodControllerTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseShippingMethodControllerTests.cs
new file mode 100644
index 000000000..75c35ac16
--- /dev/null
+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseShippingMethodControllerTests.cs
@@ -0,0 +1,109 @@
+using Grand.Business.Core.Interfaces.Checkout.Shipping;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Localization;
+using Grand.Domain.Stores;
+using Grand.Infrastructure.Mapper;
+using Grand.Mapping;
+using Grand.Web.Admin.Controllers;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Mapper;
+using Grand.Web.AdminShared.Models.Shipping;
+using Grand.Web.AdminShared.Services;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+using ShippingMethod = Grand.Domain.Shipping.ShippingMethod;
+
+namespace Grand.Web.Admin.Tests.Controllers;
+
+[TestClass]
+public class BaseShippingMethodControllerTests
+{
+ private Mock<IShippingMethodService> _shippingMethodServiceMock;
+ private Mock<ILanguageService> _languageServiceMock;
+ private Mock<IStoreService> _storeServiceMock;
+ private Mock<ITranslationService> _translationServiceMock;
+
+ [TestInitialize]
+ public void Setup()
+ {
+ var mapperConfig = new MapperConfiguration(cfg => cfg.AddProfile<ShippingMethodProfile>());
+ AutoMapperConfig.Init(mapperConfig);
+
+ _shippingMethodServiceMock = new Mock<IShippingMethodService>();
+ _languageServiceMock = new Mock<ILanguageService>();
+ _languageServiceMock.Setup(l => l.GetAllLanguages(It.IsAny<bool>(), It.IsAny<string>()))
+ .ReturnsAsync(new List<Language>());
+ _storeServiceMock = new Mock<IStoreService>();
+ _storeServiceMock.Setup(s => s.GetAllStores()).ReturnsAsync(new List<Store>());
+ _translationServiceMock = new Mock<ITranslationService>();
+ _translationServiceMock.Setup(t => t.GetResource(It.IsAny<string>())).Returns("msg");
+ }
+
+ private ShippingMethodController Build(IAdminDataScope<ShippingMethod> scope) =>
+ new(_shippingMethodServiceMock.Object, _languageServiceMock.Object, _storeServiceMock.Object,
+ _translationServiceMock.Object, scope)
+ {
+ ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() },
+ TempData = new Microsoft.AspNetCore.Mvc.ViewFeatures.TempDataDictionary(
+ new DefaultHttpContext(), Mock.Of<Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataProvider>())
+ };
+
+ [TestMethod]
+ public async Task Create_GlobalScope_DoesNotForceStoreId()
+ {
+ var controller = Build(new GlobalAdminDataScope<ShippingMethod>());
+ ShippingMethod inserted = null;
+ _shippingMethodServiceMock.Setup(s => s.InsertShippingMethod(It.IsAny<ShippingMethod>()))
+ .Callback<ShippingMethod>(m => inserted = m).Returns(Task.CompletedTask);
+
+ var model = new ShippingMethodModel { Name = "SM1" };
+ await controller.CreateMethod(model, false);
+
+ Assert.AreEqual("", inserted!.StoreId ?? "");
+ }
+
+ [TestMethod]
+ public async Task Create_StoreScope_ForcesStoreId()
+ {
+ var contextAccessor = new Mock<Grand.Infrastructure.IContextAccessor>();
+ var workContext = new Mock<Grand.Infrastructure.IWorkContext>();
+ workContext.Setup(w => w.CurrentCustomer)
+ .Returns(new Grand.Domain.Customers.Customer { StaffStoreId = "store-1" });
+ contextAccessor.Setup(c => c.WorkContext).Returns(workContext.Object);
+ var scope = new StoreShippingMethodDataScope(contextAccessor.Object);
+ var controller = Build(scope);
+
+ ShippingMethod inserted = null;
+ _shippingMethodServiceMock.Setup(s => s.InsertShippingMethod(It.IsAny<ShippingMethod>()))
+ .Callback<ShippingMethod>(m => inserted = m).Returns(Task.CompletedTask);
+
+ var model = new ShippingMethodModel { Name = "SM1" };
+ await controller.CreateMethod(model, false);
+
+ Assert.AreEqual("store-1", inserted!.StoreId);
+ }
+
+ [TestMethod]
+ public async Task Edit_StoreScope_CrossStoreMethod_Denied()
+ {
+ var contextAccessor = new Mock<Grand.Infrastructure.IContextAccessor>();
+ var workContext = new Mock<Grand.Infrastructure.IWorkContext>();
+ workContext.Setup(w => w.CurrentCustomer)
+ .Returns(new Grand.Domain.Customers.Customer { StaffStoreId = "store-1" });
+ contextAccessor.Setup(c => c.WorkContext).Returns(workContext.Object);
+ var scope = new StoreShippingMethodDataScope(contextAccessor.Object);
+ var controller = Build(scope);
+
+ _shippingMethodServiceMock.Setup(s => s.GetShippingMethodById("sm-2"))
+ .ReturnsAsync(new ShippingMethod { Id = "sm-2", StoreId = "store-2" });
+
+ var result = await controller.EditMethod("sm-2") as RedirectToActionResult;
+
+ Assert.IsNotNull(result);
+ Assert.AreEqual("Methods", result.ActionName);
+ _shippingMethodServiceMock.Verify(s => s.UpdateShippingMethod(It.IsAny<ShippingMethod>()), Times.Never);
+ }
+}
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseWarehouseControllerTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseWarehouseControllerTests.cs
new file mode 100644
index 000000000..c850299bf
--- /dev/null
+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseWarehouseControllerTests.cs
@@ -0,0 +1,104 @@
+using Grand.Business.Core.Interfaces.Checkout.Shipping;
+using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Directory;
+using Grand.Domain.Stores;
+using Grand.Web.Admin.Controllers;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Models.Shipping;
+using Grand.Web.AdminShared.Services;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+using Warehouse = Grand.Domain.Shipping.Warehouse;
+
+namespace Grand.Web.Admin.Tests.Controllers;
+
+[TestClass]
+public class BaseWarehouseControllerTests
+{
+ private Mock<IWarehouseService> _warehouseServiceMock;
+ private Mock<ICountryService> _countryServiceMock;
+ private Mock<IStoreService> _storeServiceMock;
+ private Mock<ITranslationService> _translationServiceMock;
+
+ [TestInitialize]
+ public void Setup()
+ {
+ _warehouseServiceMock = new Mock<IWarehouseService>();
+ _countryServiceMock = new Mock<ICountryService>();
+ _countryServiceMock.Setup(c => c.GetAllCountries(It.IsAny<string>(), It.IsAny<string>(), true))
+ .ReturnsAsync(new List<Country>());
+ _storeServiceMock = new Mock<IStoreService>();
+ _storeServiceMock.Setup(s => s.GetAllStores()).ReturnsAsync(new List<Store>());
+ _translationServiceMock = new Mock<ITranslationService>();
+ _translationServiceMock.Setup(t => t.GetResource(It.IsAny<string>())).Returns("msg");
+ }
+
+ private WarehouseController Build(IAdminDataScope<Warehouse> scope) =>
+ new(_warehouseServiceMock.Object, _countryServiceMock.Object, _storeServiceMock.Object,
+ _translationServiceMock.Object, scope)
+ {
+ ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() },
+ TempData = new Microsoft.AspNetCore.Mvc.ViewFeatures.TempDataDictionary(
+ new DefaultHttpContext(), Mock.Of<Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataProvider>())
+ };
+
+ [TestMethod]
+ public async Task Create_GlobalScope_DoesNotForceStoreId()
+ {
+ var controller = Build(new GlobalAdminDataScope<Warehouse>());
+ Warehouse inserted = null;
+ _warehouseServiceMock.Setup(s => s.InsertWarehouse(It.IsAny<Warehouse>()))
+ .Callback<Warehouse>(w => inserted = w).Returns(Task.CompletedTask);
+
+ var model = new WarehouseModel { Name = "WH1", Address = new() };
+ await controller.CreateWarehouse(model, false);
+
+ Assert.AreEqual("", inserted!.StoreId ?? "");
+ }
+
+ [TestMethod]
+ public async Task Create_StoreScope_ForcesStoreId()
+ {
+ var contextAccessor = new Mock<Grand.Infrastructure.IContextAccessor>();
+ var workContext = new Mock<Grand.Infrastructure.IWorkContext>();
+ workContext.Setup(w => w.CurrentCustomer)
+ .Returns(new Grand.Domain.Customers.Customer { StaffStoreId = "store-1" });
+ contextAccessor.Setup(c => c.WorkContext).Returns(workContext.Object);
+ var scope = new StoreWarehouseDataScope(contextAccessor.Object);
+ var controller = Build(scope);
+
+ Warehouse inserted = null;
+ _warehouseServiceMock.Setup(s => s.InsertWarehouse(It.IsAny<Warehouse>()))
+ .Callback<Warehouse>(w => inserted = w).Returns(Task.CompletedTask);
+
+ var model = new WarehouseModel { Name = "WH1", Address = new() };
+ await controller.CreateWarehouse(model, false);
+
+ Assert.AreEqual("store-1", inserted!.StoreId);
+ }
+
+ [TestMethod]
+ public async Task Edit_StoreScope_CrossStoreWarehouse_Denied()
+ {
+ var contextAccessor = new Mock<Grand.Infrastructure.IContextAccessor>();
+ var workContext = new Mock<Grand.Infrastructure.IWorkContext>();
+ workContext.Setup(w => w.CurrentCustomer)
+ .Returns(new Grand.Domain.Customers.Customer { StaffStoreId = "store-1" });
+ contextAccessor.Setup(c => c.WorkContext).Returns(workContext.Object);
+ var scope = new StoreWarehouseDataScope(contextAccessor.Object);
+ var controller = Build(scope);
+
+ _warehouseServiceMock.Setup(s => s.GetWarehouseById("wh-2"))
+ .ReturnsAsync(new Warehouse { Id = "wh-2", StoreId = "store-2" });
+
+ var result = await controller.EditWarehouse("wh-2") as RedirectToActionResult;
+
+ Assert.IsNotNull(result);
+ Assert.AreEqual("Warehouses", result.ActionName);
+ _warehouseServiceMock.Verify(s => s.UpdateWarehouse(It.IsAny<Warehouse>()), Times.Never);
+ }
+}
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/DeliveryDateControllerAttributeTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/DeliveryDateControllerAttributeTests.cs
new file mode 100644
index 000000000..a2133a985
--- /dev/null
+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/DeliveryDateControllerAttributeTests.cs
@@ -0,0 +1,48 @@
+using System.Reflection;
+using Grand.Web.Admin.Controllers;
+using Grand.Web.Common.Filters;
+using Grand.Web.Common.Security.Authorization;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Grand.Web.Admin.Tests.Controllers;
+
+[TestClass]
+public class DeliveryDateControllerAttributeTests
+{
+ private static readonly Type ControllerType = typeof(DeliveryDateController);
+
+ [TestMethod]
+ public void Controller_HasAreaAdmin() =>
+ Assert.AreEqual("Admin", ControllerType.GetCustomAttribute<AreaAttribute>()?.RouteValue);
+
+ [TestMethod]
+ public void Controller_HasAuthorizeAdmin() =>
+ Assert.IsNotNull(ControllerType.GetCustomAttribute<AuthorizeAdminAttribute>());
+
+ [TestMethod]
+ public void Controller_HasAutoValidateAntiforgeryToken() =>
+ Assert.IsNotNull(ControllerType.GetCustomAttribute<AutoValidateAntiforgeryTokenAttribute>());
+
+ [TestMethod]
+ public void Controller_HasAuthorizeMenu() =>
+ Assert.IsNotNull(ControllerType.GetCustomAttribute<AuthorizeMenuAttribute>());
+
+ [TestMethod]
+ public void Controller_HasRouteTemplate_PreservingShippingSegment()
+ {
+ var route = ControllerType.GetCustomAttribute<RouteAttribute>();
+ Assert.IsNotNull(route);
+ Assert.AreEqual("[area]/Shipping/[action]", route.Template);
+ }
+
+ [TestMethod]
+ public void CreateDeliveryDate_Get_And_Post_BothPresent()
+ {
+ var methods = ControllerType.GetMethods().Where(m => m.Name == "CreateDeliveryDate").ToList();
+ Assert.AreEqual(2, methods.Count);
+ Assert.IsTrue(methods.Any(m => m.GetCustomAttribute<HttpPostAttribute>() != null));
+ Assert.IsTrue(methods.Any(m => m.GetCustomAttribute<HttpGetAttribute>() != null));
+ }
+}
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/PickupPointControllerAttributeTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/PickupPointControllerAttributeTests.cs
new file mode 100644
index 000000000..7121c0bde
--- /dev/null
+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/PickupPointControllerAttributeTests.cs
@@ -0,0 +1,48 @@
+using System.Reflection;
+using Grand.Web.Admin.Controllers;
+using Grand.Web.Common.Filters;
+using Grand.Web.Common.Security.Authorization;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Grand.Web.Admin.Tests.Controllers;
+
+[TestClass]
+public class PickupPointControllerAttributeTests
+{
+ private static readonly Type ControllerType = typeof(PickupPointController);
+
+ [TestMethod]
+ public void Controller_HasAreaAdmin() =>
+ Assert.AreEqual("Admin", ControllerType.GetCustomAttribute<AreaAttribute>()?.RouteValue);
+
+ [TestMethod]
+ public void Controller_HasAuthorizeAdmin() =>
+ Assert.IsNotNull(ControllerType.GetCustomAttribute<AuthorizeAdminAttribute>());
+
+ [TestMethod]
+ public void Controller_HasAutoValidateAntiforgeryToken() =>
+ Assert.IsNotNull(ControllerType.GetCustomAttribute<AutoValidateAntiforgeryTokenAttribute>());
+
+ [TestMethod]
+ public void Controller_HasAuthorizeMenu() =>
+ Assert.IsNotNull(ControllerType.GetCustomAttribute<AuthorizeMenuAttribute>());
+
+ [TestMethod]
+ public void Controller_HasRouteTemplate_PreservingShippingSegment()
+ {
+ var route = ControllerType.GetCustomAttribute<RouteAttribute>();
+ Assert.IsNotNull(route);
+ Assert.AreEqual("[area]/Shipping/[action]", route.Template);
+ }
+
+ [TestMethod]
+ public void CreatePickupPoint_Get_And_Post_BothPresent()
+ {
+ var methods = ControllerType.GetMethods().Where(m => m.Name == "CreatePickupPoint").ToList();
+ Assert.AreEqual(2, methods.Count);
+ Assert.IsTrue(methods.Any(m => m.GetCustomAttribute<HttpPostAttribute>() != null));
+ Assert.IsTrue(methods.Any(m => m.GetCustomAttribute<HttpGetAttribute>() != null));
+ }
+}
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/RoutedDeliveryDateDataScopeTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/RoutedDeliveryDateDataScopeTests.cs
new file mode 100644
index 000000000..3c42bc130
--- /dev/null
+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/RoutedDeliveryDateDataScopeTests.cs
@@ -0,0 +1,71 @@
+using Grand.Domain.Customers;
+using Grand.Domain.Shipping;
+using Grand.Infrastructure;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Services;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Routing;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Web.Admin.Tests.Controllers;
+
+[TestClass]
+public class RoutedDeliveryDateDataScopeTests
+{
+ private static RoutedDeliveryDateDataScope Build(string area)
+ {
+ var httpContext = new DefaultHttpContext();
+ if (area != null)
+ httpContext.Request.RouteValues = new RouteValueDictionary { ["area"] = area };
+
+ var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
+ httpContextAccessorMock.Setup(a => a.HttpContext).Returns(httpContext);
+
+ var global = new GlobalAdminDataScope<DeliveryDate>();
+ var store = new StoreDeliveryDateDataScope(BuildContextAccessor());
+ return new RoutedDeliveryDateDataScope(httpContextAccessorMock.Object, global, store);
+ }
+
+ private static IContextAccessor BuildContextAccessor()
+ {
+ var workContext = new Mock<Grand.Infrastructure.IWorkContext>();
+ workContext.Setup(w => w.CurrentCustomer).Returns(new Customer { StaffStoreId = "store-1" });
+ var contextAccessorMock = new Mock<IContextAccessor>();
+ contextAccessorMock.Setup(c => c.WorkContext).Returns(workContext.Object);
+ return contextAccessorMock.Object;
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_AdminArea_ResolvesToGlobalScope()
+ {
+ Assert.IsNull(Build("Admin").DefaultStoreId);
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_StoreArea_ResolvesToStoreScope()
+ {
+ Assert.AreEqual("store-1", Build("Store").DefaultStoreId);
+ }
+
+ [TestMethod]
+ public void CanView_StoreArea_ForwardsToStoreScope()
+ {
+ // Regression guard for the Order-phase lesson: a routed scope must forward every
+ // interface member, not just HasAccess/DefaultStoreId.
+ var routed = Build("Store");
+ Assert.IsFalse(routed.CanView(new DeliveryDate { StoreId = "store-2" }).Result);
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_VendorArea_ThrowsFailClosed()
+ {
+ Assert.ThrowsExactly<InvalidOperationException>(() => _ = Build("Vendor").DefaultStoreId);
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_MissingArea_ThrowsFailClosed()
+ {
+ Assert.ThrowsExactly<InvalidOperationException>(() => _ = Build(null).DefaultStoreId);
+ }
+}
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/RoutedPickupPointDataScopeTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/RoutedPickupPointDataScopeTests.cs
new file mode 100644
index 000000000..0f0a6b3f7
--- /dev/null
+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/RoutedPickupPointDataScopeTests.cs
@@ -0,0 +1,71 @@
+using Grand.Domain.Customers;
+using Grand.Domain.Shipping;
+using Grand.Infrastructure;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Services;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Routing;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Web.Admin.Tests.Controllers;
+
+[TestClass]
+public class RoutedPickupPointDataScopeTests
+{
+ private static RoutedPickupPointDataScope Build(string area)
+ {
+ var httpContext = new DefaultHttpContext();
+ if (area != null)
+ httpContext.Request.RouteValues = new RouteValueDictionary { ["area"] = area };
+
+ var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
+ httpContextAccessorMock.Setup(a => a.HttpContext).Returns(httpContext);
+
+ var global = new GlobalAdminDataScope<PickupPoint>();
+ var store = new StorePickupPointDataScope(BuildContextAccessor());
+ return new RoutedPickupPointDataScope(httpContextAccessorMock.Object, global, store);
+ }
+
+ private static IContextAccessor BuildContextAccessor()
+ {
+ var workContext = new Mock<Grand.Infrastructure.IWorkContext>();
+ workContext.Setup(w => w.CurrentCustomer).Returns(new Customer { StaffStoreId = "store-1" });
+ var contextAccessorMock = new Mock<IContextAccessor>();
+ contextAccessorMock.Setup(c => c.WorkContext).Returns(workContext.Object);
+ return contextAccessorMock.Object;
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_AdminArea_ResolvesToGlobalScope()
+ {
+ Assert.IsNull(Build("Admin").DefaultStoreId);
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_StoreArea_ResolvesToStoreScope()
+ {
+ Assert.AreEqual("store-1", Build("Store").DefaultStoreId);
+ }
+
+ [TestMethod]
+ public void CanView_StoreArea_ForwardsToStoreScope()
+ {
+ // Regression guard for the Order-phase lesson: a routed scope must forward every
+ // interface member, not just HasAccess/DefaultStoreId.
+ var routed = Build("Store");
+ Assert.IsFalse(routed.CanView(new PickupPoint { StoreId = "store-2" }).Result);
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_VendorArea_ThrowsFailClosed()
+ {
+ Assert.ThrowsExactly<InvalidOperationException>(() => _ = Build("Vendor").DefaultStoreId);
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_MissingArea_ThrowsFailClosed()
+ {
+ Assert.ThrowsExactly<InvalidOperationException>(() => _ = Build(null).DefaultStoreId);
+ }
+}
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/RoutedShippingMethodDataScopeTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/RoutedShippingMethodDataScopeTests.cs
new file mode 100644
index 000000000..bbcfa574d
--- /dev/null
+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/RoutedShippingMethodDataScopeTests.cs
@@ -0,0 +1,71 @@
+using Grand.Domain.Customers;
+using Grand.Domain.Shipping;
+using Grand.Infrastructure;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Services;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Routing;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Web.Admin.Tests.Controllers;
+
+[TestClass]
+public class RoutedShippingMethodDataScopeTests
+{
+ private static RoutedShippingMethodDataScope Build(string area)
+ {
+ var httpContext = new DefaultHttpContext();
+ if (area != null)
+ httpContext.Request.RouteValues = new RouteValueDictionary { ["area"] = area };
+
+ var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
+ httpContextAccessorMock.Setup(a => a.HttpContext).Returns(httpContext);
+
+ var global = new GlobalAdminDataScope<ShippingMethod>();
+ var store = new StoreShippingMethodDataScope(BuildContextAccessor());
+ return new RoutedShippingMethodDataScope(httpContextAccessorMock.Object, global, store);
+ }
+
+ private static IContextAccessor BuildContextAccessor()
+ {
+ var workContext = new Mock<Grand.Infrastructure.IWorkContext>();
+ workContext.Setup(w => w.CurrentCustomer).Returns(new Customer { StaffStoreId = "store-1" });
+ var contextAccessorMock = new Mock<IContextAccessor>();
+ contextAccessorMock.Setup(c => c.WorkContext).Returns(workContext.Object);
+ return contextAccessorMock.Object;
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_AdminArea_ResolvesToGlobalScope()
+ {
+ Assert.IsNull(Build("Admin").DefaultStoreId);
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_StoreArea_ResolvesToStoreScope()
+ {
+ Assert.AreEqual("store-1", Build("Store").DefaultStoreId);
+ }
+
+ [TestMethod]
+ public void CanView_StoreArea_ForwardsToStoreScope()
+ {
+ // Regression guard for the Order-phase lesson: a routed scope must forward every
+ // interface member, not just HasAccess/DefaultStoreId.
+ var routed = Build("Store");
+ Assert.IsFalse(routed.CanView(new ShippingMethod { StoreId = "store-2" }).Result);
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_VendorArea_ThrowsFailClosed()
+ {
+ Assert.ThrowsExactly<InvalidOperationException>(() => _ = Build("Vendor").DefaultStoreId);
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_MissingArea_ThrowsFailClosed()
+ {
+ Assert.ThrowsExactly<InvalidOperationException>(() => _ = Build(null).DefaultStoreId);
+ }
+}
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/RoutedWarehouseDataScopeTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/RoutedWarehouseDataScopeTests.cs
new file mode 100644
index 000000000..318718001
--- /dev/null
+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/RoutedWarehouseDataScopeTests.cs
@@ -0,0 +1,71 @@
+using Grand.Domain.Customers;
+using Grand.Domain.Shipping;
+using Grand.Infrastructure;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Services;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Routing;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Web.Admin.Tests.Controllers;
+
+[TestClass]
+public class RoutedWarehouseDataScopeTests
+{
+ private static RoutedWarehouseDataScope Build(string area)
+ {
+ var httpContext = new DefaultHttpContext();
+ if (area != null)
+ httpContext.Request.RouteValues = new RouteValueDictionary { ["area"] = area };
+
+ var httpContextAccessorMock = new Mock<IHttpContextAccessor>();
+ httpContextAccessorMock.Setup(a => a.HttpContext).Returns(httpContext);
+
+ var global = new GlobalAdminDataScope<Warehouse>();
+ var store = new StoreWarehouseDataScope(BuildContextAccessor());
+ return new RoutedWarehouseDataScope(httpContextAccessorMock.Object, global, store);
+ }
+
+ private static IContextAccessor BuildContextAccessor()
+ {
+ var workContext = new Mock<Grand.Infrastructure.IWorkContext>();
+ workContext.Setup(w => w.CurrentCustomer).Returns(new Customer { StaffStoreId = "store-1" });
+ var contextAccessorMock = new Mock<IContextAccessor>();
+ contextAccessorMock.Setup(c => c.WorkContext).Returns(workContext.Object);
+ return contextAccessorMock.Object;
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_AdminArea_ResolvesToGlobalScope()
+ {
+ Assert.IsNull(Build("Admin").DefaultStoreId);
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_StoreArea_ResolvesToStoreScope()
+ {
+ Assert.AreEqual("store-1", Build("Store").DefaultStoreId);
+ }
+
+ [TestMethod]
+ public void CanView_StoreArea_ForwardsToStoreScope()
+ {
+ // Regression guard for the Order-phase lesson: a routed scope must forward every
+ // interface member, not just HasAccess/DefaultStoreId.
+ var routed = Build("Store");
+ Assert.IsFalse(routed.CanView(new Warehouse { StoreId = "store-2" }).Result);
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_VendorArea_ThrowsFailClosed()
+ {
+ Assert.ThrowsExactly<InvalidOperationException>(() => _ = Build("Vendor").DefaultStoreId);
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_MissingArea_ThrowsFailClosed()
+ {
+ Assert.ThrowsExactly<InvalidOperationException>(() => _ = Build(null).DefaultStoreId);
+ }
+}
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/ShippingMethodControllerAttributeTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/ShippingMethodControllerAttributeTests.cs
new file mode 100644
index 000000000..deab8ff21
--- /dev/null
+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/ShippingMethodControllerAttributeTests.cs
@@ -0,0 +1,48 @@
+using System.Reflection;
+using Grand.Web.Admin.Controllers;
+using Grand.Web.Common.Filters;
+using Grand.Web.Common.Security.Authorization;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Grand.Web.Admin.Tests.Controllers;
+
+[TestClass]
+public class ShippingMethodControllerAttributeTests
+{
+ private static readonly Type ControllerType = typeof(ShippingMethodController);
+
+ [TestMethod]
+ public void Controller_HasAreaAdmin() =>
+ Assert.AreEqual("Admin", ControllerType.GetCustomAttribute<AreaAttribute>()?.RouteValue);
+
+ [TestMethod]
+ public void Controller_HasAuthorizeAdmin() =>
+ Assert.IsNotNull(ControllerType.GetCustomAttribute<AuthorizeAdminAttribute>());
+
+ [TestMethod]
+ public void Controller_HasAutoValidateAntiforgeryToken() =>
+ Assert.IsNotNull(ControllerType.GetCustomAttribute<AutoValidateAntiforgeryTokenAttribute>());
+
+ [TestMethod]
+ public void Controller_HasAuthorizeMenu() =>
+ Assert.IsNotNull(ControllerType.GetCustomAttribute<AuthorizeMenuAttribute>());
+
+ [TestMethod]
+ public void Controller_HasRouteTemplate_PreservingShippingSegment()
+ {
+ var route = ControllerType.GetCustomAttribute<RouteAttribute>();
+ Assert.IsNotNull(route);
+ Assert.AreEqual("[area]/Shipping/[action]", route.Template);
+ }
+
+ [TestMethod]
+ public void CreateMethod_Get_And_Post_BothPresent()
+ {
+ var methods = ControllerType.GetMethods().Where(m => m.Name == "CreateMethod").ToList();
+ Assert.AreEqual(2, methods.Count);
+ Assert.IsTrue(methods.Any(m => m.GetCustomAttribute<HttpPostAttribute>() != null));
+ Assert.IsTrue(methods.Any(m => m.GetCustomAttribute<HttpGetAttribute>() != null));
+ }
+}
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/StoreDeliveryDateDataScopeTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/StoreDeliveryDateDataScopeTests.cs
new file mode 100644
index 000000000..e2be04da9
--- /dev/null
+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/StoreDeliveryDateDataScopeTests.cs
@@ -0,0 +1,58 @@
+using Grand.Domain.Customers;
+using Grand.Domain.Shipping;
+using Grand.Infrastructure;
+using Grand.Web.AdminShared.Services;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Web.Admin.Tests.Controllers;
+
+[TestClass]
+public class StoreDeliveryDateDataScopeTests
+{
+ private static StoreDeliveryDateDataScope Build(string staffStoreId)
+ {
+ var customer = new Customer { StaffStoreId = staffStoreId };
+ var workContextMock = new Mock<IWorkContext>();
+ workContextMock.Setup(w => w.CurrentCustomer).Returns(customer);
+ var contextAccessorMock = new Mock<IContextAccessor>();
+ contextAccessorMock.Setup(c => c.WorkContext).Returns(workContextMock.Object);
+ return new StoreDeliveryDateDataScope(contextAccessorMock.Object);
+ }
+
+ [TestMethod]
+ public async Task HasAccess_MatchingStoreId_True()
+ {
+ var scope = Build("store-1");
+ Assert.IsTrue(await scope.HasAccess(new DeliveryDate { StoreId = "store-1" }));
+ }
+
+ [TestMethod]
+ public async Task HasAccess_MismatchedStoreId_False()
+ {
+ var scope = Build("store-1");
+ Assert.IsFalse(await scope.HasAccess(new DeliveryDate { StoreId = "store-2" }));
+ }
+
+ [TestMethod]
+ public async Task HasAccess_GlobalDeliveryDate_False()
+ {
+ var scope = Build("store-1");
+ Assert.IsFalse(await scope.HasAccess(new DeliveryDate { StoreId = "" }));
+ }
+
+ [TestMethod]
+ public async Task HasAccess_NullEntity_False()
+ {
+ var scope = Build("store-1");
+ Assert.IsFalse(await scope.HasAccess(null));
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_ReturnsStaffStoreId()
+ {
+ var scope = Build("store-1");
+ Assert.AreEqual("store-1", scope.DefaultStoreId);
+ Assert.IsNull(scope.DefaultVendorId);
+ }
+}
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/StorePickupPointDataScopeTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/StorePickupPointDataScopeTests.cs
new file mode 100644
index 000000000..6f1862881
--- /dev/null
+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/StorePickupPointDataScopeTests.cs
@@ -0,0 +1,58 @@
+using Grand.Domain.Customers;
+using Grand.Domain.Shipping;
+using Grand.Infrastructure;
+using Grand.Web.AdminShared.Services;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Web.Admin.Tests.Controllers;
+
+[TestClass]
+public class StorePickupPointDataScopeTests
+{
+ private static StorePickupPointDataScope Build(string staffStoreId)
+ {
+ var customer = new Customer { StaffStoreId = staffStoreId };
+ var workContextMock = new Mock<IWorkContext>();
+ workContextMock.Setup(w => w.CurrentCustomer).Returns(customer);
+ var contextAccessorMock = new Mock<IContextAccessor>();
+ contextAccessorMock.Setup(c => c.WorkContext).Returns(workContextMock.Object);
+ return new StorePickupPointDataScope(contextAccessorMock.Object);
+ }
+
+ [TestMethod]
+ public async Task HasAccess_MatchingStoreId_True()
+ {
+ var scope = Build("store-1");
+ Assert.IsTrue(await scope.HasAccess(new PickupPoint { StoreId = "store-1" }));
+ }
+
+ [TestMethod]
+ public async Task HasAccess_MismatchedStoreId_False()
+ {
+ var scope = Build("store-1");
+ Assert.IsFalse(await scope.HasAccess(new PickupPoint { StoreId = "store-2" }));
+ }
+
+ [TestMethod]
+ public async Task HasAccess_GlobalPickupPoint_False()
+ {
+ var scope = Build("store-1");
+ Assert.IsFalse(await scope.HasAccess(new PickupPoint { StoreId = "" }));
+ }
+
+ [TestMethod]
+ public async Task HasAccess_NullEntity_False()
+ {
+ var scope = Build("store-1");
+ Assert.IsFalse(await scope.HasAccess(null));
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_ReturnsStaffStoreId()
+ {
+ var scope = Build("store-1");
+ Assert.AreEqual("store-1", scope.DefaultStoreId);
+ Assert.IsNull(scope.DefaultVendorId);
+ }
+}
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/StoreShippingMethodDataScopeTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/StoreShippingMethodDataScopeTests.cs
new file mode 100644
index 000000000..8a77fc3c7
--- /dev/null
+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/StoreShippingMethodDataScopeTests.cs
@@ -0,0 +1,59 @@
+using Grand.Domain.Customers;
+using Grand.Domain.Shipping;
+using Grand.Infrastructure;
+using Grand.Web.AdminShared.Services;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Web.Admin.Tests.Controllers;
+
+[TestClass]
+public class StoreShippingMethodDataScopeTests
+{
+ private static StoreShippingMethodDataScope Build(string staffStoreId)
+ {
+ var customer = new Customer { StaffStoreId = staffStoreId };
+ var workContextMock = new Mock<IWorkContext>();
+ workContextMock.Setup(w => w.CurrentCustomer).Returns(customer);
+ var contextAccessorMock = new Mock<IContextAccessor>();
+ contextAccessorMock.Setup(c => c.WorkContext).Returns(workContextMock.Object);
+ return new StoreShippingMethodDataScope(contextAccessorMock.Object);
+ }
+
+ [TestMethod]
+ public async Task HasAccess_MatchingStoreId_True()
+ {
+ var scope = Build("store-1");
+ Assert.IsTrue(await scope.HasAccess(new ShippingMethod { StoreId = "store-1" }));
+ }
+
+ [TestMethod]
+ public async Task HasAccess_MismatchedStoreId_False()
+ {
+ var scope = Build("store-1");
+ Assert.IsFalse(await scope.HasAccess(new ShippingMethod { StoreId = "store-2" }));
+ }
+
+ [TestMethod]
+ public async Task HasAccess_GlobalShippingMethod_False()
+ {
+ // Strict own-store-only for mutation, even though GetAllShippingMethods(storeId) itself
+ // returns own-store-OR-global for the List grid — a deliberate, pre-existing asymmetry.
+ var scope = Build("store-1");
+ Assert.IsFalse(await scope.HasAccess(new ShippingMethod { StoreId = "" }));
+ }
+
+ [TestMethod]
+ public async Task HasAccess_NullEntity_False()
+ {
+ var scope = Build("store-1");
+ Assert.IsFalse(await scope.HasAccess(null));
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_ReturnsStaffStoreId()
+ {
+ var scope = Build("store-1");
+ Assert.AreEqual("store-1", scope.DefaultStoreId);
+ }
+}
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/StoreWarehouseDataScopeTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/StoreWarehouseDataScopeTests.cs
new file mode 100644
index 000000000..8743ee4ec
--- /dev/null
+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/StoreWarehouseDataScopeTests.cs
@@ -0,0 +1,58 @@
+using Grand.Domain.Customers;
+using Grand.Domain.Shipping;
+using Grand.Infrastructure;
+using Grand.Web.AdminShared.Services;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Web.Admin.Tests.Controllers;
+
+[TestClass]
+public class StoreWarehouseDataScopeTests
+{
+ private static StoreWarehouseDataScope Build(string staffStoreId)
+ {
+ var customer = new Customer { StaffStoreId = staffStoreId };
+ var workContextMock = new Mock<IWorkContext>();
+ workContextMock.Setup(w => w.CurrentCustomer).Returns(customer);
+ var contextAccessorMock = new Mock<IContextAccessor>();
+ contextAccessorMock.Setup(c => c.WorkContext).Returns(workContextMock.Object);
+ return new StoreWarehouseDataScope(contextAccessorMock.Object);
+ }
+
+ [TestMethod]
+ public async Task HasAccess_MatchingStoreId_True()
+ {
+ var scope = Build("store-1");
+ Assert.IsTrue(await scope.HasAccess(new Warehouse { StoreId = "store-1" }));
+ }
+
+ [TestMethod]
+ public async Task HasAccess_MismatchedStoreId_False()
+ {
+ var scope = Build("store-1");
+ Assert.IsFalse(await scope.HasAccess(new Warehouse { StoreId = "store-2" }));
+ }
+
+ [TestMethod]
+ public async Task HasAccess_GlobalWarehouse_False()
+ {
+ var scope = Build("store-1");
+ Assert.IsFalse(await scope.HasAccess(new Warehouse { StoreId = "" }));
+ }
+
+ [TestMethod]
+ public async Task HasAccess_NullEntity_False()
+ {
+ var scope = Build("store-1");
+ Assert.IsFalse(await scope.HasAccess(null));
+ }
+
+ [TestMethod]
+ public void DefaultStoreId_ReturnsStaffStoreId()
+ {
+ var scope = Build("store-1");
+ Assert.AreEqual("store-1", scope.DefaultStoreId);
+ Assert.IsNull(scope.DefaultVendorId);
+ }
+}
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/WarehouseControllerAttributeTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/WarehouseControllerAttributeTests.cs
new file mode 100644
index 000000000..4a71c9c32
--- /dev/null
+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/WarehouseControllerAttributeTests.cs
@@ -0,0 +1,48 @@
+using System.Reflection;
+using Grand.Web.Admin.Controllers;
+using Grand.Web.Common.Filters;
+using Grand.Web.Common.Security.Authorization;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Grand.Web.Admin.Tests.Controllers;
+
+[TestClass]
+public class WarehouseControllerAttributeTests
+{
+ private static readonly Type ControllerType = typeof(WarehouseController);
+
+ [TestMethod]
+ public void Controller_HasAreaAdmin() =>
+ Assert.AreEqual("Admin", ControllerType.GetCustomAttribute<AreaAttribute>()?.RouteValue);
+
+ [TestMethod]
+ public void Controller_HasAuthorizeAdmin() =>
+ Assert.IsNotNull(ControllerType.GetCustomAttribute<AuthorizeAdminAttribute>());
+
+ [TestMethod]
+ public void Controller_HasAutoValidateAntiforgeryToken() =>
+ Assert.IsNotNull(ControllerType.GetCustomAttribute<AutoValidateAntiforgeryTokenAttribute>());
+
+ [TestMethod]
+ public void Controller_HasAuthorizeMenu() =>
+ Assert.IsNotNull(ControllerType.GetCustomAttribute<AuthorizeMenuAttribute>());
+
+ [TestMethod]
+ public void Controller_HasRouteTemplate_PreservingShippingSegment()
+ {
+ var route = ControllerType.GetCustomAttribute<RouteAttribute>();
+ Assert.IsNotNull(route);
+ Assert.AreEqual("[area]/Shipping/[action]", route.Template);
+ }
+
+ [TestMethod]
+ public void CreateWarehouse_Get_And_Post_BothPresent()
+ {
+ var methods = ControllerType.GetMethods().Where(m => m.Name == "CreateWarehouse").ToList();
+ Assert.AreEqual(2, methods.Count);
+ Assert.IsTrue(methods.Any(m => m.GetCustomAttribute<HttpPostAttribute>() != null));
+ Assert.IsTrue(methods.Any(m => m.GetCustomAttribute<HttpGetAttribute>() != null));
+ }
+}
diff --git a/src/Tests/Grand.Web.Common.Tests/Controllers/SharedViewFolderAttributeTests.cs b/src/Tests/Grand.Web.Common.Tests/Controllers/SharedViewFolderAttributeTests.cs
new file mode 100644
index 000000000..502458bb6
--- /dev/null
+++ b/src/Tests/Grand.Web.Common.Tests/Controllers/SharedViewFolderAttributeTests.cs
@@ -0,0 +1,46 @@
+using System.Linq;
+using Grand.Web.AdminShared.Controllers;
+using Grand.Web.Common.Controllers;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Grand.Web.Common.Tests.Controllers;
+
+[TestClass]
+public class SharedViewFolderAttributeTests
+{
+ private static void AssertHasSharedViewFolder<T>(string expectedControllerName)
+ {
+ var attributes = typeof(T).GetCustomAttributes(typeof(SharedViewFolderAttribute), true)
+ .Cast<SharedViewFolderAttribute>()
+ .ToList();
+
+ Assert.AreEqual(1, attributes.Count,
+ $"{typeof(T).Name} should carry exactly one [SharedViewFolder] attribute.");
+ Assert.AreEqual(expectedControllerName, attributes[0].ControllerName,
+ $"{typeof(T).Name}'s [SharedViewFolder] should target the '{expectedControllerName}' view folder.");
+ }
+
+ [TestMethod]
+ public void BaseWarehouseController_HasSharedViewFolder_Shipping()
+ {
+ AssertHasSharedViewFolder<BaseWarehouseController>("Shipping");
+ }
+
+ [TestMethod]
+ public void BaseShippingMethodController_HasSharedViewFolder_Shipping()
+ {
+ AssertHasSharedViewFolder<BaseShippingMethodController>("Shipping");
+ }
+
+ [TestMethod]
+ public void BaseDeliveryDateController_HasSharedViewFolder_Shipping()
+ {
+ AssertHasSharedViewFolder<BaseDeliveryDateController>("Shipping");
+ }
+
+ [TestMethod]
+ public void BasePickupPointController_HasSharedViewFolder_Shipping()
+ {
+ AssertHasSharedViewFolder<BasePickupPointController>("Shipping");
+ }
+}
diff --git a/src/Tests/Grand.Web.Common.Tests/Grand.Web.Common.Tests.csproj b/src/Tests/Grand.Web.Common.Tests/Grand.Web.Common.Tests.csproj
index 82aa90c93..b8e41fb8d 100644
--- a/src/Tests/Grand.Web.Common.Tests/Grand.Web.Common.Tests.csproj
+++ b/src/Tests/Grand.Web.Common.Tests/Grand.Web.Common.Tests.csproj
@@ -20,6 +20,7 @@
<ItemGroup>
<ProjectReference Include="..\..\Core\Grand.SharedKernel\Grand.SharedKernel.csproj" />
<ProjectReference Include="..\..\Web\Grand.Web.Common\Grand.Web.Common.csproj" />
+ <ProjectReference Include="..\..\Web\Grand.Web.AdminShared\Grand.Web.AdminShared.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="App_Data\Settings.cfg">
diff --git a/src/Tests/Grand.Web.Common.Tests/Infrastructure/SharedViewFolderControllerNameConventionTests.cs b/src/Tests/Grand.Web.Common.Tests/Infrastructure/SharedViewFolderControllerNameConventionTests.cs
new file mode 100644
index 000000000..e6c111044
--- /dev/null
+++ b/src/Tests/Grand.Web.Common.Tests/Infrastructure/SharedViewFolderControllerNameConventionTests.cs
@@ -0,0 +1,53 @@
+using System.Linq;
+using System.Reflection;
+using Grand.Web.Common.Controllers;
+using Grand.Web.Common.Infrastructure;
+using Microsoft.AspNetCore.Mvc.ApplicationModels;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Grand.Web.Common.Tests.Infrastructure;
+
+[SharedViewFolder("TestFolder")]
+public class SharedViewFolderConventionFakeControllerWithAttribute
+{
+}
+
+public class SharedViewFolderConventionFakeControllerWithoutAttribute
+{
+}
+
+[TestClass]
+public class SharedViewFolderControllerNameConventionTests
+{
+ private static ControllerModel CreateControllerModel(System.Type type)
+ {
+ var typeInfo = type.GetTypeInfo();
+ var attributes = typeInfo.GetCustomAttributes(true).ToList();
+ return new ControllerModel(typeInfo, attributes);
+ }
+
+ [TestMethod]
+ public void Apply_ControllerWithAttribute_SetsControllerNameFromAttribute()
+ {
+ var controllerModel = CreateControllerModel(typeof(SharedViewFolderConventionFakeControllerWithAttribute));
+ var originalName = controllerModel.ControllerName;
+
+ var convention = new SharedViewFolderControllerNameConvention();
+ convention.Apply(controllerModel);
+
+ Assert.AreEqual("TestFolder", controllerModel.ControllerName);
+ Assert.AreNotEqual(originalName, controllerModel.ControllerName);
+ }
+
+ [TestMethod]
+ public void Apply_ControllerWithoutAttribute_LeavesControllerNameUnchanged()
+ {
+ var controllerModel = CreateControllerModel(typeof(SharedViewFolderConventionFakeControllerWithoutAttribute));
+ var originalName = controllerModel.ControllerName;
+
+ var convention = new SharedViewFolderControllerNameConvention();
+ convention.Apply(controllerModel);
+
+ Assert.AreEqual(originalName, controllerModel.ControllerName);
+ }
+}
diff --git a/src/Tests/Grand.Web.Store.Tests/Controllers/DeliveryDateControllerAttributeTests.cs b/src/Tests/Grand.Web.Store.Tests/Controllers/DeliveryDateControllerAttributeTests.cs
new file mode 100644
index 000000000..b8bfb32a0
--- /dev/null
+++ b/src/Tests/Grand.Web.Store.Tests/Controllers/DeliveryDateControllerAttributeTests.cs
@@ -0,0 +1,41 @@
+using System.Reflection;
+using Grand.Domain.Permissions;
+using Grand.Web.Common.Filters;
+using Grand.Web.Common.Security.Authorization;
+using Grand.Web.Store.Controllers;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Grand.Web.Store.Tests.Controllers;
+
+[TestClass]
+public class DeliveryDateControllerAttributeTests
+{
+ private static readonly Type ControllerType = typeof(DeliveryDateController);
+
+ [TestMethod]
+ public void Controller_HasAreaStore() =>
+ Assert.AreEqual("Store", ControllerType.GetCustomAttribute<AreaAttribute>()?.RouteValue);
+
+ [TestMethod]
+ public void Controller_HasAuthorizeStore() =>
+ Assert.IsNotNull(ControllerType.GetCustomAttribute<AuthorizeStoreAttribute>());
+
+ [TestMethod]
+ public void Controller_HasRouteTemplate_PreservingShippingSegment()
+ {
+ var route = ControllerType.GetCustomAttribute<RouteAttribute>();
+ Assert.IsNotNull(route);
+ Assert.AreEqual("[area]/Shipping/[action]", route.Template);
+ }
+
+ [TestMethod]
+ public void DeleteDeliveryDate_HasPermissionAuthorizeAction_Delete()
+ {
+ var method = ControllerType.GetMethod("DeleteDeliveryDate");
+ var attr = method!.GetCustomAttribute<PermissionAuthorizeActionAttribute>();
+ Assert.IsNotNull(attr);
+ Assert.AreEqual(PermissionActionName.Delete, attr.PermissionAction);
+ }
+}
diff --git a/src/Tests/Grand.Web.Store.Tests/Controllers/PickupPointControllerAttributeTests.cs b/src/Tests/Grand.Web.Store.Tests/Controllers/PickupPointControllerAttributeTests.cs
new file mode 100644
index 000000000..e6c6d8441
--- /dev/null
+++ b/src/Tests/Grand.Web.Store.Tests/Controllers/PickupPointControllerAttributeTests.cs
@@ -0,0 +1,41 @@
+using System.Reflection;
+using Grand.Domain.Permissions;
+using Grand.Web.Common.Filters;
+using Grand.Web.Common.Security.Authorization;
+using Grand.Web.Store.Controllers;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Grand.Web.Store.Tests.Controllers;
+
+[TestClass]
+public class PickupPointControllerAttributeTests
+{
+ private static readonly Type ControllerType = typeof(PickupPointController);
+
+ [TestMethod]
+ public void Controller_HasAreaStore() =>
+ Assert.AreEqual("Store", ControllerType.GetCustomAttribute<AreaAttribute>()?.RouteValue);
+
+ [TestMethod]
+ public void Controller_HasAuthorizeStore() =>
+ Assert.IsNotNull(ControllerType.GetCustomAttribute<AuthorizeStoreAttribute>());
+
+ [TestMethod]
+ public void Controller_HasRouteTemplate_PreservingShippingSegment()
+ {
+ var route = ControllerType.GetCustomAttribute<RouteAttribute>();
+ Assert.IsNotNull(route);
+ Assert.AreEqual("[area]/Shipping/[action]", route.Template);
+ }
+
+ [TestMethod]
+ public void DeletePickupPoint_HasPermissionAuthorizeAction_Delete()
+ {
+ var method = ControllerType.GetMethod("DeletePickupPoint");
+ var attr = method!.GetCustomAttribute<PermissionAuthorizeActionAttribute>();
+ Assert.IsNotNull(attr);
+ Assert.AreEqual(PermissionActionName.Delete, attr.PermissionAction);
+ }
+}
diff --git a/src/Tests/Grand.Web.Store.Tests/Controllers/ShippingControllerTests.cs b/src/Tests/Grand.Web.Store.Tests/Controllers/ShippingControllerTests.cs
index fbf89ff47..b6fc0f1a6 100644
--- a/src/Tests/Grand.Web.Store.Tests/Controllers/ShippingControllerTests.cs
+++ b/src/Tests/Grand.Web.Store.Tests/Controllers/ShippingControllerTests.cs
@@ -47,12 +47,8 @@ public class ShippingControllerTests
_controller = new ShippingController(
new Mock<IShippingService>().Object,
_shippingMethodServiceMock.Object,
- new Mock<IDeliveryDateService>().Object,
- new Mock<IWarehouseService>().Object,
- new Mock<IPickupPointService>().Object,
_countryServiceMock.Object,
_groupServiceMock.Object,
- new Mock<ILanguageService>().Object,
_translationServiceMock.Object,
new Mock<ISettingService>().Object,
_contextAccessorMock.Object);
diff --git a/src/Tests/Grand.Web.Store.Tests/Controllers/ShippingMethodControllerAttributeTests.cs b/src/Tests/Grand.Web.Store.Tests/Controllers/ShippingMethodControllerAttributeTests.cs
new file mode 100644
index 000000000..a088e3d25
--- /dev/null
+++ b/src/Tests/Grand.Web.Store.Tests/Controllers/ShippingMethodControllerAttributeTests.cs
@@ -0,0 +1,41 @@
+using System.Reflection;
+using Grand.Domain.Permissions;
+using Grand.Web.Common.Filters;
+using Grand.Web.Common.Security.Authorization;
+using Grand.Web.Store.Controllers;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Grand.Web.Store.Tests.Controllers;
+
+[TestClass]
+public class ShippingMethodControllerAttributeTests
+{
+ private static readonly Type ControllerType = typeof(ShippingMethodController);
+
+ [TestMethod]
+ public void Controller_HasAreaStore() =>
+ Assert.AreEqual("Store", ControllerType.GetCustomAttribute<AreaAttribute>()?.RouteValue);
+
+ [TestMethod]
+ public void Controller_HasAuthorizeStore() =>
+ Assert.IsNotNull(ControllerType.GetCustomAttribute<AuthorizeStoreAttribute>());
+
+ [TestMethod]
+ public void Controller_HasRouteTemplate_PreservingShippingSegment()
+ {
+ var route = ControllerType.GetCustomAttribute<RouteAttribute>();
+ Assert.IsNotNull(route);
+ Assert.AreEqual("[area]/Shipping/[action]", route.Template);
+ }
+
+ [TestMethod]
+ public void DeleteMethod_HasPermissionAuthorizeAction_Delete()
+ {
+ var method = ControllerType.GetMethod("DeleteMethod");
+ var attr = method!.GetCustomAttribute<PermissionAuthorizeActionAttribute>();
+ Assert.IsNotNull(attr);
+ Assert.AreEqual(PermissionActionName.Delete, attr.PermissionAction);
+ }
+}
diff --git a/src/Tests/Grand.Web.Store.Tests/Controllers/WarehouseControllerAttributeTests.cs b/src/Tests/Grand.Web.Store.Tests/Controllers/WarehouseControllerAttributeTests.cs
new file mode 100644
index 000000000..42860f734
--- /dev/null
+++ b/src/Tests/Grand.Web.Store.Tests/Controllers/WarehouseControllerAttributeTests.cs
@@ -0,0 +1,41 @@
+using System.Reflection;
+using Grand.Domain.Permissions;
+using Grand.Web.Common.Filters;
+using Grand.Web.Common.Security.Authorization;
+using Grand.Web.Store.Controllers;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Grand.Web.Store.Tests.Controllers;
+
+[TestClass]
+public class WarehouseControllerAttributeTests
+{
+ private static readonly Type ControllerType = typeof(WarehouseController);
+
+ [TestMethod]
+ public void Controller_HasAreaStore() =>
+ Assert.AreEqual("Store", ControllerType.GetCustomAttribute<AreaAttribute>()?.RouteValue);
+
+ [TestMethod]
+ public void Controller_HasAuthorizeStore() =>
+ Assert.IsNotNull(ControllerType.GetCustomAttribute<AuthorizeStoreAttribute>());
+
+ [TestMethod]
+ public void Controller_HasRouteTemplate_PreservingShippingSegment()
+ {
+ var route = ControllerType.GetCustomAttribute<RouteAttribute>();
+ Assert.IsNotNull(route);
+ Assert.AreEqual("[area]/Shipping/[action]", route.Template);
+ }
+
+ [TestMethod]
+ public void DeleteWarehouse_HasPermissionAuthorizeAction_Delete()
+ {
+ var method = ControllerType.GetMethod("DeleteWarehouse");
+ var attr = method!.GetCustomAttribute<PermissionAuthorizeActionAttribute>();
+ Assert.IsNotNull(attr);
+ Assert.AreEqual(PermissionActionName.Delete, attr.PermissionAction);
+ }
+}
diff --git a/src/Web/Grand.Web.Admin/Controllers/DeliveryDateController.cs b/src/Web/Grand.Web.Admin/Controllers/DeliveryDateController.cs
new file mode 100644
index 000000000..64e61674b
--- /dev/null
+++ b/src/Web/Grand.Web.Admin/Controllers/DeliveryDateController.cs
@@ -0,0 +1,54 @@
+using Grand.Business.Core.Interfaces.Checkout.Shipping;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Permissions;
+using Grand.Web.AdminShared.Controllers;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Models.Shipping;
+using Grand.Web.Common.DataSource;
+using Grand.Web.Common.Filters;
+using Grand.Web.Admin.Extensions;
+using Grand.Web.Common.Security.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Grand.Web.Admin.Controllers;
+
+[Area(Constants.AreaAdmin)]
+[AuthorizeAdmin]
+[AutoValidateAntiforgeryToken]
+[AuthorizeMenu]
+[PermissionAuthorize(PermissionSystemName.ShippingSettings)]
+[Route("[area]/Shipping/[action]")]
+public class DeliveryDateController(
+ IDeliveryDateService deliveryDateService,
+ ILanguageService languageService,
+ IStoreService storeService,
+ ITranslationService translationService,
+ IAdminDataScope<Grand.Domain.Shipping.DeliveryDate> scope)
+ : BaseDeliveryDateController(deliveryDateService, languageService, storeService, translationService, scope)
+{
+ [HttpGet]
+ public IActionResult DeliveryDates() => View();
+
+ [HttpPost]
+ public Task<IActionResult> DeliveryDates(DataSourceRequest command) => DeliveryDateListCore();
+
+ [HttpGet]
+ public Task<IActionResult> CreateDeliveryDate() => DeliveryDateCreateGetCore();
+
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public Task<IActionResult> CreateDeliveryDate(DeliveryDateModel model, bool continueEditing) =>
+ DeliveryDateCreatePostCore(model, continueEditing);
+
+ [HttpGet]
+ public Task<IActionResult> EditDeliveryDate(string id) => DeliveryDateEditGetCore(id);
+
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public Task<IActionResult> EditDeliveryDate(DeliveryDateModel model, bool continueEditing) =>
+ DeliveryDateEditPostCore(model, continueEditing);
+
+ [HttpPost]
+ public Task<IActionResult> DeleteDeliveryDate(string id) => DeliveryDateDeleteCore(id);
+}
diff --git a/src/Web/Grand.Web.Admin/Controllers/PickupPointController.cs b/src/Web/Grand.Web.Admin/Controllers/PickupPointController.cs
new file mode 100644
index 000000000..adf153b11
--- /dev/null
+++ b/src/Web/Grand.Web.Admin/Controllers/PickupPointController.cs
@@ -0,0 +1,56 @@
+using Grand.Business.Core.Interfaces.Checkout.Shipping;
+using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Permissions;
+using Grand.Web.AdminShared.Controllers;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Models.Shipping;
+using Grand.Web.Common.DataSource;
+using Grand.Web.Common.Filters;
+using Grand.Web.Admin.Extensions;
+using Grand.Web.Common.Security.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Grand.Web.Admin.Controllers;
+
+[Area(Constants.AreaAdmin)]
+[AuthorizeAdmin]
+[AutoValidateAntiforgeryToken]
+[AuthorizeMenu]
+[PermissionAuthorize(PermissionSystemName.ShippingSettings)]
+[Route("[area]/Shipping/[action]")]
+public class PickupPointController(
+ IPickupPointService pickupPointService,
+ IWarehouseService warehouseService,
+ ICountryService countryService,
+ IStoreService storeService,
+ ITranslationService translationService,
+ IAdminDataScope<Grand.Domain.Shipping.PickupPoint> scope)
+ : BasePickupPointController(pickupPointService, warehouseService, countryService, storeService, translationService, scope)
+{
+ [HttpGet]
+ public IActionResult PickupPoints() => View();
+
+ [HttpPost]
+ public Task<IActionResult> PickupPoints(DataSourceRequest command) => PickupPointListCore();
+
+ [HttpGet]
+ public Task<IActionResult> CreatePickupPoint() => PickupPointCreateGetCore();
+
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public Task<IActionResult> CreatePickupPoint(PickupPointModel model, bool continueEditing) =>
+ PickupPointCreatePostCore(model, continueEditing);
+
+ [HttpGet]
+ public Task<IActionResult> EditPickupPoint(string id) => PickupPointEditGetCore(id);
+
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public Task<IActionResult> EditPickupPoint(PickupPointModel model, bool continueEditing) =>
+ PickupPointEditPostCore(model, continueEditing);
+
+ [HttpPost]
+ public Task<IActionResult> DeletePickupPoint(string id) => PickupPointDeleteCore(id);
+}
diff --git a/src/Web/Grand.Web.Admin/Controllers/ShippingController.cs b/src/Web/Grand.Web.Admin/Controllers/ShippingController.cs
index 8f92de5fb..7067bd737 100644
--- a/src/Web/Grand.Web.Admin/Controllers/ShippingController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/ShippingController.cs
@@ -31,25 +31,17 @@ public class ShippingController : BaseAdminController
public ShippingController(
IShippingService shippingService,
IShippingMethodService shippingMethodService,
- IPickupPointService pickupPointService,
- IDeliveryDateService deliveryDateService,
- IWarehouseService warehouseService,
ISettingService settingService,
ICountryService countryService,
ITranslationService translationService,
- ILanguageService languageService,
IStoreService storeService,
IGroupService groupService)
{
_shippingService = shippingService;
_shippingMethodService = shippingMethodService;
- _pickupPointService = pickupPointService;
- _deliveryDateService = deliveryDateService;
- _warehouseService = warehouseService;
_settingService = settingService;
_countryService = countryService;
_translationService = translationService;
- _languageService = languageService;
_storeService = storeService;
_groupService = groupService;
}
@@ -60,119 +52,14 @@ public class ShippingController : BaseAdminController
private readonly IShippingService _shippingService;
private readonly IShippingMethodService _shippingMethodService;
- private readonly IPickupPointService _pickupPointService;
- private readonly IDeliveryDateService _deliveryDateService;
- private readonly IWarehouseService _warehouseService;
private readonly ISettingService _settingService;
private readonly ICountryService _countryService;
private readonly ITranslationService _translationService;
- private readonly ILanguageService _languageService;
private readonly IStoreService _storeService;
private readonly IGroupService _groupService;
#endregion
- #region Utilities
-
- protected virtual async Task PrepareAddressWarehouseModel(WarehouseModel model)
- {
- model.Address.AvailableCountries.Add(new SelectListItem
- { Text = _translationService.GetResource("Admin.Address.SelectCountry"), Value = "" });
- foreach (var c in await _countryService.GetAllCountries(showHidden: true))
- model.Address.AvailableCountries.Add(new SelectListItem
- { Text = c.Name, Value = c.Id, Selected = c.Id == model.Address.CountryId });
- //states
- var states = !string.IsNullOrEmpty(model.Address.CountryId)
- ? (await _countryService.GetCountryById(model.Address.CountryId))?.StateProvinces
- : new List<StateProvince>();
- if (states?.Count > 0)
- foreach (var s in states)
- model.Address.AvailableStates.Add(new SelectListItem
- { Text = s.Name, Value = s.Id, Selected = s.Id == model.Address.StateProvinceId });
-
- model.Address.CountryEnabled = true;
- model.Address.StateProvinceEnabled = true;
- model.Address.CityEnabled = true;
- model.Address.StreetAddressEnabled = true;
- model.Address.ZipPostalCodeEnabled = true;
- model.Address.ZipPostalCodeRequired = true;
- model.Address.PhoneEnabled = true;
- model.Address.FaxEnabled = true;
- model.Address.CompanyEnabled = true;
-
- model.AvailableStores.Add(new SelectListItem {
- Text = _translationService.GetResource("Admin.Configuration.Shipping.Warehouses.SelectStore"), Value = ""
- });
- foreach (var s in await _storeService.GetAllStores())
- model.AvailableStores.Add(new SelectListItem {
- Text = s.Shortcut, Value = s.Id, Selected = s.Id == model.StoreId
- });
- }
-
- protected virtual async Task PrepareDeliveryDateModel(DeliveryDateModel model)
- {
- model.AvailableStores.Add(new SelectListItem {
- Text = _translationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.SelectStore"), Value = ""
- });
- foreach (var s in await _storeService.GetAllStores())
- model.AvailableStores.Add(new SelectListItem {
- Text = s.Shortcut, Value = s.Id, Selected = s.Id == model.StoreId
- });
- }
-
- protected virtual async Task PrepareShippingMethodModel(ShippingMethodModel model)
- {
- model.AvailableStores.Add(new SelectListItem {
- Text = _translationService.GetResource("Admin.Configuration.Shipping.Methods.SelectStore"), Value = ""
- });
- foreach (var s in await _storeService.GetAllStores())
- model.AvailableStores.Add(new SelectListItem {
- Text = s.Shortcut, Value = s.Id, Selected = s.Id == model.StoreId
- });
- }
-
- protected virtual async Task PreparePickupPointModel(PickupPointModel model)
- {
- model.Address.AvailableCountries.Add(new SelectListItem
- { Text = _translationService.GetResource("Admin.Address.SelectCountry"), Value = "" });
- foreach (var c in await _countryService.GetAllCountries(showHidden: true))
- model.Address.AvailableCountries.Add(new SelectListItem
- { Text = c.Name, Value = c.Id, Selected = c.Id == model.Address.CountryId });
- //states
- var states = !string.IsNullOrEmpty(model.Address.CountryId)
- ? (await _countryService.GetCountryById(model.Address.CountryId))?.StateProvinces
- : new List<StateProvince>();
- if (states?.Count > 0)
- foreach (var s in states)
- model.Address.AvailableStates.Add(new SelectListItem
- { Text = s.Name, Value = s.Id, Selected = s.Id == model.Address.StateProvinceId });
-
- model.Address.CountryEnabled = true;
- model.Address.StateProvinceEnabled = true;
- model.Address.CityEnabled = true;
- model.Address.StreetAddressEnabled = true;
- model.Address.ZipPostalCodeEnabled = true;
- model.Address.ZipPostalCodeRequired = true;
- model.Address.PhoneEnabled = true;
- model.Address.FaxEnabled = true;
- model.Address.CompanyEnabled = true;
-
- model.AvailableStores.Add(new SelectListItem {
- Text = _translationService.GetResource("Admin.Configuration.Shipping.PickupPoint.SelectStore"), Value = ""
- });
- foreach (var c in await _storeService.GetAllStores())
- model.AvailableStores.Add(new SelectListItem { Text = c.Shortcut, Value = c.Id, Selected = c.Id == model.StoreId });
-
- model.AvailableWarehouses.Add(new SelectListItem {
- Text = _translationService.GetResource("Admin.Configuration.Shipping.PickupPoint.SelectWarehouse"),
- Value = ""
- });
- foreach (var c in await _warehouseService.GetAllWarehouses())
- model.AvailableWarehouses.Add(new SelectListItem { Text = c.Name, Value = c.Id });
- }
-
- #endregion
-
#region Shipping rate methods
public IActionResult Providers()
@@ -236,117 +123,6 @@ public class ShippingController : BaseAdminController
#endregion
- #region Shipping methods
-
- public IActionResult Methods()
- {
- return View();
- }
-
- [HttpPost]
- public async Task<IActionResult> Methods(DataSourceRequest command)
- {
- var storeMap = (await _storeService.GetAllStores()).ToDictionary(s => s.Id, s => s.Shortcut);
- var shippingMethodsModel = (await _shippingMethodService.GetAllShippingMethods())
- .Select(x => {
- var m = x.ToModel();
- m.StoreName = !string.IsNullOrEmpty(x.StoreId) && storeMap.TryGetValue(x.StoreId, out var name) ? name : "";
- return m;
- })
- .ToList();
- var gridModel = new DataSourceResult {
- Data = shippingMethodsModel,
- Total = shippingMethodsModel.Count
- };
-
- return Json(gridModel);
- }
-
-
- public async Task<IActionResult> CreateMethod()
- {
- var model = new ShippingMethodModel();
- //locales
- await AddLocales(_languageService, model.Locales);
- await PrepareShippingMethodModel(model);
- return View(model);
- }
-
- [HttpPost]
- [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
- public async Task<IActionResult> CreateMethod(ShippingMethodModel model, bool continueEditing)
- {
- if (ModelState.IsValid)
- {
- var sm = model.ToEntity();
- await _shippingMethodService.InsertShippingMethod(sm);
-
- Success(_translationService.GetResource("Admin.Configuration.Shipping.Methods.Added"));
- return continueEditing ? RedirectToAction("EditMethod", new { id = sm.Id }) : RedirectToAction("Methods");
- }
-
- //If we got this far, something failed, redisplay form
- await PrepareShippingMethodModel(model);
- return View(model);
- }
-
- public async Task<IActionResult> EditMethod(string id)
- {
- var sm = await _shippingMethodService.GetShippingMethodById(id);
- if (sm == null)
- //No shipping method found with the specified id
- return RedirectToAction("Methods");
-
- var model = sm.ToModel();
- //locales
- await AddLocales(_languageService, model.Locales, (locale, languageId) =>
- {
- locale.Name = sm.GetTranslation(x => x.Name, languageId, false);
- locale.Description = sm.GetTranslation(x => x.Description, languageId, false);
- });
- await PrepareShippingMethodModel(model);
- return View(model);
- }
-
- [HttpPost]
- [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
- public async Task<IActionResult> EditMethod(ShippingMethodModel model, bool continueEditing)
- {
- var sm = await _shippingMethodService.GetShippingMethodById(model.Id);
- if (sm == null)
- //No shipping method found with the specified id
- return RedirectToAction("Methods");
-
- if (ModelState.IsValid)
- {
- sm = model.ToEntity(sm);
- await _shippingMethodService.UpdateShippingMethod(sm);
-
- Success(_translationService.GetResource("Admin.Configuration.Shipping.Methods.Updated"));
- return continueEditing ? RedirectToAction("EditMethod", new { id = sm.Id }) : RedirectToAction("Methods");
- }
-
- //If we got this far, something failed, redisplay form
- await PrepareShippingMethodModel(model);
- return View(model);
- }
-
- [HttpPost]
- public async Task<IActionResult> DeleteMethod(string id)
- {
- var sm = await _shippingMethodService.GetShippingMethodById(id);
- if (sm == null)
- //No shipping method found with the specified id
- return RedirectToAction("Methods");
-
- await _shippingMethodService.DeleteShippingMethod(sm);
-
- Success(_translationService.GetResource("Admin.Configuration.Shipping.Methods.Deleted"));
- return RedirectToAction("Methods");
- }
-
- #endregion
-
#region Shipping Settings
public async Task<IActionResult> Settings()
@@ -405,345 +181,6 @@ public class ShippingController : BaseAdminController
#endregion
- #region Delivery dates
-
- public IActionResult DeliveryDates()
- {
- return View();
- }
-
- [HttpPost]
- public async Task<IActionResult> DeliveryDates(DataSourceRequest command)
- {
- var storeMap = (await _storeService.GetAllStores()).ToDictionary(s => s.Id, s => s.Shortcut);
- var deliveryDatesModel = (await _deliveryDateService.GetAllDeliveryDates())
- .Select(x => {
- var m = x.ToModel();
- m.StoreName = !string.IsNullOrEmpty(x.StoreId) && storeMap.TryGetValue(x.StoreId, out var name) ? name : "";
- return m;
- })
- .ToList();
- var gridModel = new DataSourceResult {
- Data = deliveryDatesModel,
- Total = deliveryDatesModel.Count
- };
-
- return Json(gridModel);
- }
-
- public async Task<IActionResult> CreateDeliveryDate()
- {
- var model = new DeliveryDateModel {
- ColorSquaresRgb = "#000000"
- };
- //locales
- await AddLocales(_languageService, model.Locales);
- await PrepareDeliveryDateModel(model);
- return View(model);
- }
-
- [HttpPost]
- [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
- public async Task<IActionResult> CreateDeliveryDate(DeliveryDateModel model, bool continueEditing)
- {
- if (ModelState.IsValid)
- {
- var deliveryDate = model.ToEntity();
- await _deliveryDateService.InsertDeliveryDate(deliveryDate);
- Success(_translationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.Added"));
- return continueEditing
- ? RedirectToAction("EditDeliveryDate", new { id = deliveryDate.Id })
- : RedirectToAction("DeliveryDates");
- }
-
- //If we got this far, something failed, redisplay form
- await PrepareDeliveryDateModel(model);
- return View(model);
- }
-
- public async Task<IActionResult> EditDeliveryDate(string id)
- {
- var deliveryDate = await _deliveryDateService.GetDeliveryDateById(id);
- if (deliveryDate == null)
- //No delivery date found with the specified id
- return RedirectToAction("DeliveryDates");
-
- var model = deliveryDate.ToModel();
-
- if (string.IsNullOrEmpty(model.ColorSquaresRgb)) model.ColorSquaresRgb = "#000000";
-
- //locales
- await AddLocales(_languageService, model.Locales, (locale, languageId) =>
- {
- locale.Name = deliveryDate.GetTranslation(x => x.Name, languageId, false);
- });
-
- await PrepareDeliveryDateModel(model);
- return View(model);
- }
-
- [HttpPost]
- [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
- public async Task<IActionResult> EditDeliveryDate(DeliveryDateModel model, bool continueEditing)
- {
- var deliveryDate = await _deliveryDateService.GetDeliveryDateById(model.Id);
- if (deliveryDate == null)
- //No delivery date found with the specified id
- return RedirectToAction("DeliveryDates");
-
- if (ModelState.IsValid)
- {
- deliveryDate = model.ToEntity(deliveryDate);
- await _deliveryDateService.UpdateDeliveryDate(deliveryDate);
- //locales
- Success(_translationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.Updated"));
- return continueEditing
- ? RedirectToAction("EditDeliveryDate", new { id = deliveryDate.Id })
- : RedirectToAction("DeliveryDates");
- }
-
- //If we got this far, something failed, redisplay form
- await PrepareDeliveryDateModel(model);
- return View(model);
- }
-
- [HttpPost]
- public async Task<IActionResult> DeleteDeliveryDate(string id)
- {
- var deliveryDate = await _deliveryDateService.GetDeliveryDateById(id);
- if (deliveryDate == null)
- //No delivery date found with the specified id
- return RedirectToAction("DeliveryDates");
- if (ModelState.IsValid)
- {
- await _deliveryDateService.DeleteDeliveryDate(deliveryDate);
-
- Success(_translationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.Deleted"));
- return RedirectToAction("DeliveryDates");
- }
-
- Error(ModelState);
- return RedirectToAction("EditDeliveryDate", new { id });
- }
-
- #endregion
-
- #region Warehouses
-
- public IActionResult Warehouses()
- {
- return View();
- }
-
- [HttpPost]
- public async Task<IActionResult> Warehouses(DataSourceRequest command)
- {
- var storeMap = (await _storeService.GetAllStores()).ToDictionary(s => s.Id, s => s.Shortcut);
- var warehousesModel = (await _warehouseService.GetAllWarehouses())
- .Select(x => {
- var m = x.ToModel();
- m.StoreName = !string.IsNullOrEmpty(x.StoreId) && storeMap.TryGetValue(x.StoreId, out var name) ? name : "";
- return m;
- })
- .ToList();
- var gridModel = new DataSourceResult {
- Data = warehousesModel,
- Total = warehousesModel.Count
- };
-
- return Json(gridModel);
- }
-
- public async Task<IActionResult> CreateWarehouse()
- {
- var model = new WarehouseModel();
- await PrepareAddressWarehouseModel(model);
- return View(model);
- }
-
- [HttpPost]
- [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
- public async Task<IActionResult> CreateWarehouse(WarehouseModel model, bool continueEditing)
- {
- if (ModelState.IsValid)
- {
- var warehouse = model.ToEntity();
- var address = model.Address.ToEntity();
- warehouse.Address = address;
- await _warehouseService.InsertWarehouse(warehouse);
-
- Success(_translationService.GetResource("Admin.Configuration.Shipping.Warehouses.Added"));
- return continueEditing
- ? RedirectToAction("EditWarehouse", new { id = warehouse.Id })
- : RedirectToAction("Warehouses");
- }
-
- //If we got this far, something failed, redisplay form
- await PrepareAddressWarehouseModel(model);
- return View(model);
- }
-
- public async Task<IActionResult> EditWarehouse(string id)
- {
- var warehouse = await _warehouseService.GetWarehouseById(id);
- if (warehouse == null)
- //No warehouse found with the specified id
- return RedirectToAction("Warehouses");
-
- var model = warehouse.ToModel();
- await PrepareAddressWarehouseModel(model);
- return View(model);
- }
-
- [HttpPost]
- [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
- public async Task<IActionResult> EditWarehouse(WarehouseModel model, bool continueEditing)
- {
- var warehouse = await _warehouseService.GetWarehouseById(model.Id);
- if (warehouse == null)
- //No warehouse found with the specified id
- return RedirectToAction("Warehouses");
-
- if (ModelState.IsValid)
- {
- warehouse = model.ToEntity(warehouse);
- await _warehouseService.UpdateWarehouse(warehouse);
- Success(_translationService.GetResource("Admin.Configuration.Shipping.Warehouses.Updated"));
- return continueEditing
- ? RedirectToAction("EditWarehouse", new { id = warehouse.Id })
- : RedirectToAction("Warehouses");
- }
-
- //If we got this far, something failed, redisplay form
- await PrepareAddressWarehouseModel(model);
- return View(model);
- }
-
- [HttpPost]
- public async Task<IActionResult> DeleteWarehouse(string id)
- {
- var warehouse = await _warehouseService.GetWarehouseById(id);
- if (warehouse == null)
- //No warehouse found with the specified id
- return RedirectToAction("Warehouses");
-
- await _warehouseService.DeleteWarehouse(warehouse);
-
- Success(_translationService.GetResource("Admin.Configuration.Shipping.warehouses.Deleted"));
- return RedirectToAction("Warehouses");
- }
-
- #endregion
-
- #region PickupPoints
-
- public IActionResult PickupPoints()
- {
- return View();
- }
-
- [HttpPost]
- public async Task<IActionResult> PickupPoints(DataSourceRequest command)
- {
- var storeMap = (await _storeService.GetAllStores()).ToDictionary(s => s.Id, s => s.Shortcut);
- var pickupPointsModel = (await _pickupPointService.GetAllPickupPoints())
- .Select(x => {
- var m = x.ToModel();
- m.StoreName = !string.IsNullOrEmpty(x.StoreId) && storeMap.TryGetValue(x.StoreId, out var name) ? name : "";
- return m;
- })
- .ToList();
-
- var gridModel = new DataSourceResult {
- Data = pickupPointsModel,
- Total = pickupPointsModel.Count
- };
-
- return Json(gridModel);
- }
-
- public async Task<IActionResult> CreatePickupPoint()
- {
- var model = new PickupPointModel();
- await PreparePickupPointModel(model);
- return View(model);
- }
-
-
- [HttpPost]
- [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
- public async Task<IActionResult> CreatePickupPoint(PickupPointModel model, bool continueEditing)
- {
- if (ModelState.IsValid)
- {
- var pickuppoint = model.ToEntity();
- await _pickupPointService.InsertPickupPoint(pickuppoint);
-
- Success(_translationService.GetResource("Admin.Configuration.Shipping.PickupPoints.Added"));
- return continueEditing
- ? RedirectToAction("EditPickupPoint", new { id = pickuppoint.Id })
- : RedirectToAction("PickupPoints");
- }
-
- //If we got this far, something failed, redisplay form
- await PreparePickupPointModel(model);
- return View(model);
- }
-
- public async Task<IActionResult> EditPickupPoint(string id)
- {
- var pickuppoint = await _pickupPointService.GetPickupPointById(id);
- if (pickuppoint == null)
- //No pickup pint found with the specified id
- return RedirectToAction("PickupPoints");
-
- var model = pickuppoint.ToModel();
- await PreparePickupPointModel(model);
-
- return View(model);
- }
-
- [HttpPost]
- [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
- public async Task<IActionResult> EditPickupPoint(PickupPointModel model, bool continueEditing)
- {
- var pickupPoint = await _pickupPointService.GetPickupPointById(model.Id);
- if (pickupPoint == null)
- //No pickup point found with the specified id
- return RedirectToAction("PickupPoints");
-
- if (ModelState.IsValid)
- {
- pickupPoint = model.ToEntity(pickupPoint);
- await _pickupPointService.UpdatePickupPoint(pickupPoint);
-
- Success(_translationService.GetResource("Admin.Configuration.Shipping.PickupPoints.Updated"));
- return continueEditing
- ? RedirectToAction("EditPickupPoint", new { id = pickupPoint.Id })
- : RedirectToAction("PickupPoints");
- }
-
- //If we got this far, something failed, redisplay form
- await PreparePickupPointModel(model);
- return View(model);
- }
-
- [HttpPost]
- public async Task<IActionResult> DeletePickupPoint(string id)
- {
- var pickupPoint = await _pickupPointService.GetPickupPointById(id);
- if (pickupPoint == null)
- //No pickup point found with the specified id
- return RedirectToAction("PickupPoints");
-
- await _pickupPointService.DeletePickupPoint(pickupPoint);
-
- Success(_translationService.GetResource("Admin.Configuration.Shipping.PickupPoints.Deleted"));
- return RedirectToAction("PickupPoints");
- }
-
- #endregion
-
#region Restrictions
public async Task<IActionResult> Restrictions(string storeId = "")
diff --git a/src/Web/Grand.Web.Admin/Controllers/ShippingMethodController.cs b/src/Web/Grand.Web.Admin/Controllers/ShippingMethodController.cs
new file mode 100644
index 000000000..0949920f7
--- /dev/null
+++ b/src/Web/Grand.Web.Admin/Controllers/ShippingMethodController.cs
@@ -0,0 +1,54 @@
+using Grand.Business.Core.Interfaces.Checkout.Shipping;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Permissions;
+using Grand.Web.AdminShared.Controllers;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Models.Shipping;
+using Grand.Web.Common.DataSource;
+using Grand.Web.Common.Filters;
+using Grand.Web.Admin.Extensions;
+using Grand.Web.Common.Security.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Grand.Web.Admin.Controllers;
+
+[Area(Constants.AreaAdmin)]
+[AuthorizeAdmin]
+[AutoValidateAntiforgeryToken]
+[AuthorizeMenu]
+[PermissionAuthorize(PermissionSystemName.ShippingSettings)]
+[Route("[area]/Shipping/[action]")]
+public class ShippingMethodController(
+ IShippingMethodService shippingMethodService,
+ ILanguageService languageService,
+ IStoreService storeService,
+ ITranslationService translationService,
+ IAdminDataScope<Grand.Domain.Shipping.ShippingMethod> scope)
+ : BaseShippingMethodController(shippingMethodService, languageService, storeService, translationService, scope)
+{
+ [HttpGet]
+ public IActionResult Methods() => View();
+
+ [HttpPost]
+ public Task<IActionResult> Methods(DataSourceRequest command) => ShippingMethodListCore();
+
+ [HttpGet]
+ public Task<IActionResult> CreateMethod() => ShippingMethodCreateGetCore();
+
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public Task<IActionResult> CreateMethod(ShippingMethodModel model, bool continueEditing) =>
+ ShippingMethodCreatePostCore(model, continueEditing);
+
+ [HttpGet]
+ public Task<IActionResult> EditMethod(string id) => ShippingMethodEditGetCore(id);
+
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public Task<IActionResult> EditMethod(ShippingMethodModel model, bool continueEditing) =>
+ ShippingMethodEditPostCore(model, continueEditing);
+
+ [HttpPost]
+ public Task<IActionResult> DeleteMethod(string id) => ShippingMethodDeleteCore(id);
+}
diff --git a/src/Web/Grand.Web.Admin/Controllers/WarehouseController.cs b/src/Web/Grand.Web.Admin/Controllers/WarehouseController.cs
new file mode 100644
index 000000000..fa28442b7
--- /dev/null
+++ b/src/Web/Grand.Web.Admin/Controllers/WarehouseController.cs
@@ -0,0 +1,55 @@
+using Grand.Business.Core.Interfaces.Checkout.Shipping;
+using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Permissions;
+using Grand.Web.AdminShared.Controllers;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Models.Shipping;
+using Grand.Web.Common.DataSource;
+using Grand.Web.Common.Filters;
+using Grand.Web.Admin.Extensions;
+using Grand.Web.Common.Security.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Grand.Web.Admin.Controllers;
+
+[Area(Constants.AreaAdmin)]
+[AuthorizeAdmin]
+[AutoValidateAntiforgeryToken]
+[AuthorizeMenu]
+[PermissionAuthorize(PermissionSystemName.ShippingSettings)]
+[Route("[area]/Shipping/[action]")]
+public class WarehouseController(
+ IWarehouseService warehouseService,
+ ICountryService countryService,
+ IStoreService storeService,
+ ITranslationService translationService,
+ IAdminDataScope<Grand.Domain.Shipping.Warehouse> scope)
+ : BaseWarehouseController(warehouseService, countryService, storeService, translationService, scope)
+{
+ [HttpGet]
+ public IActionResult Warehouses() => View();
+
+ [HttpPost]
+ public Task<IActionResult> Warehouses(DataSourceRequest command) => WarehouseListCore();
+
+ [HttpGet]
+ public Task<IActionResult> CreateWarehouse() => WarehouseCreateGetCore();
+
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public Task<IActionResult> CreateWarehouse(WarehouseModel model, bool continueEditing) =>
+ WarehouseCreatePostCore(model, continueEditing);
+
+ [HttpGet]
+ public Task<IActionResult> EditWarehouse(string id) => WarehouseEditGetCore(id);
+
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public Task<IActionResult> EditWarehouse(WarehouseModel model, bool continueEditing) =>
+ WarehouseEditPostCore(model, continueEditing);
+
+ [HttpPost]
+ public Task<IActionResult> DeleteWarehouse(string id) => WarehouseDeleteCore(id);
+}
diff --git a/src/Web/Grand.Web.AdminShared/Controllers/BaseDeliveryDateController.cs b/src/Web/Grand.Web.AdminShared/Controllers/BaseDeliveryDateController.cs
new file mode 100644
index 000000000..7227c3c32
--- /dev/null
+++ b/src/Web/Grand.Web.AdminShared/Controllers/BaseDeliveryDateController.cs
@@ -0,0 +1,112 @@
+using Grand.Business.Core.Extensions;
+using Grand.Business.Core.Interfaces.Checkout.Shipping;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Shipping;
+using Grand.Web.AdminShared.Extensions.Mapping;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Models.Shipping;
+using Grand.Web.Common.Controllers;
+using Grand.Web.Common.DataSource;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Rendering;
+
+namespace Grand.Web.AdminShared.Controllers;
+
+[SharedViewFolder("Shipping")]
+public abstract class BaseDeliveryDateController(
+ IDeliveryDateService deliveryDateService,
+ ILanguageService languageService,
+ IStoreService storeService,
+ ITranslationService translationService,
+ IAdminDataScope<DeliveryDate> scope) : BaseController
+{
+ protected virtual async Task PrepareDeliveryDateModel(DeliveryDateModel model)
+ {
+ if (scope.DefaultStoreId is null)
+ {
+ model.AvailableStores.Add(new SelectListItem {
+ Text = translationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.SelectStore"),
+ Value = ""
+ });
+ foreach (var s in await storeService.GetAllStores())
+ model.AvailableStores.Add(new SelectListItem { Text = s.Shortcut, Value = s.Id, Selected = s.Id == model.StoreId });
+ }
+ }
+
+ protected virtual async Task<IActionResult> DeliveryDateListCore()
+ {
+ var storeMap = (await storeService.GetAllStores()).ToDictionary(s => s.Id, s => s.Shortcut);
+ var dates = (await deliveryDateService.GetAllDeliveryDates(scope.DefaultStoreId ?? "")).ToList();
+ var model = dates.Select(x => {
+ var m = x.ToModel();
+ m.StoreName = !string.IsNullOrEmpty(x.StoreId) && storeMap.TryGetValue(x.StoreId, out var name) ? name : "";
+ return m;
+ }).ToList();
+ return Json(new DataSourceResult { Data = model, Total = model.Count });
+ }
+
+ protected virtual async Task<IActionResult> DeliveryDateCreateGetCore()
+ {
+ var model = new DeliveryDateModel { ColorSquaresRgb = "#000000" };
+ await AddLocales(languageService, model.Locales);
+ await PrepareDeliveryDateModel(model);
+ return View(model);
+ }
+
+ protected virtual async Task<IActionResult> DeliveryDateCreatePostCore(DeliveryDateModel model, bool continueEditing)
+ {
+ if (!ModelState.IsValid)
+ {
+ await PrepareDeliveryDateModel(model);
+ return View(model);
+ }
+ var deliveryDate = model.ToEntity();
+ if (scope.DefaultStoreId is not null) deliveryDate.StoreId = scope.DefaultStoreId;
+ await deliveryDateService.InsertDeliveryDate(deliveryDate);
+ Success(translationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.Added"));
+ return continueEditing
+ ? RedirectToAction("EditDeliveryDate", new { id = deliveryDate.Id })
+ : RedirectToAction("DeliveryDates");
+ }
+
+ protected virtual async Task<IActionResult> DeliveryDateEditGetCore(string id)
+ {
+ var deliveryDate = await deliveryDateService.GetDeliveryDateById(id);
+ if (deliveryDate == null || !await scope.HasAccess(deliveryDate)) return RedirectToAction("DeliveryDates");
+ var model = deliveryDate.ToModel();
+ if (string.IsNullOrEmpty(model.ColorSquaresRgb)) model.ColorSquaresRgb = "#000000";
+ await AddLocales(languageService, model.Locales, (locale, languageId) => {
+ locale.Name = deliveryDate.GetTranslation(x => x.Name, languageId, false);
+ });
+ await PrepareDeliveryDateModel(model);
+ return View(model);
+ }
+
+ protected virtual async Task<IActionResult> DeliveryDateEditPostCore(DeliveryDateModel model, bool continueEditing)
+ {
+ var deliveryDate = await deliveryDateService.GetDeliveryDateById(model.Id);
+ if (deliveryDate == null || !await scope.HasAccess(deliveryDate)) return RedirectToAction("DeliveryDates");
+ if (!ModelState.IsValid)
+ {
+ await PrepareDeliveryDateModel(model);
+ return View(model);
+ }
+ deliveryDate = model.ToEntity(deliveryDate);
+ if (scope.DefaultStoreId is not null) deliveryDate.StoreId = scope.DefaultStoreId;
+ await deliveryDateService.UpdateDeliveryDate(deliveryDate);
+ Success(translationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.Updated"));
+ return continueEditing
+ ? RedirectToAction("EditDeliveryDate", new { id = deliveryDate.Id })
+ : RedirectToAction("DeliveryDates");
+ }
+
+ protected virtual async Task<IActionResult> DeliveryDateDeleteCore(string id)
+ {
+ var deliveryDate = await deliveryDateService.GetDeliveryDateById(id);
+ if (deliveryDate == null || !await scope.HasAccess(deliveryDate)) return RedirectToAction("DeliveryDates");
+ await deliveryDateService.DeleteDeliveryDate(deliveryDate);
+ Success(translationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.Deleted"));
+ return RedirectToAction("DeliveryDates");
+ }
+}
diff --git a/src/Web/Grand.Web.AdminShared/Controllers/BasePickupPointController.cs b/src/Web/Grand.Web.AdminShared/Controllers/BasePickupPointController.cs
new file mode 100644
index 000000000..93bf9b6b4
--- /dev/null
+++ b/src/Web/Grand.Web.AdminShared/Controllers/BasePickupPointController.cs
@@ -0,0 +1,139 @@
+using Grand.Business.Core.Interfaces.Checkout.Shipping;
+using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Directory;
+using Grand.Domain.Shipping;
+using Grand.Web.AdminShared.Extensions.Mapping;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Models.Shipping;
+using Grand.Web.Common.Controllers;
+using Grand.Web.Common.DataSource;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Rendering;
+
+namespace Grand.Web.AdminShared.Controllers;
+
+[SharedViewFolder("Shipping")]
+public abstract class BasePickupPointController(
+ IPickupPointService pickupPointService,
+ IWarehouseService warehouseService,
+ ICountryService countryService,
+ IStoreService storeService,
+ ITranslationService translationService,
+ IAdminDataScope<PickupPoint> scope) : BaseController
+{
+ protected virtual async Task PreparePickupPointModel(PickupPointModel model)
+ {
+ model.Address.AvailableCountries.Add(new SelectListItem
+ { Text = translationService.GetResource("Admin.Address.SelectCountry"), Value = "" });
+ foreach (var c in await countryService.GetAllCountries(showHidden: true))
+ model.Address.AvailableCountries.Add(new SelectListItem
+ { Text = c.Name, Value = c.Id, Selected = c.Id == model.Address.CountryId });
+ var states = !string.IsNullOrEmpty(model.Address.CountryId)
+ ? (await countryService.GetCountryById(model.Address.CountryId))?.StateProvinces
+ : new List<StateProvince>();
+ if (states?.Count > 0)
+ foreach (var s in states)
+ model.Address.AvailableStates.Add(new SelectListItem
+ { Text = s.Name, Value = s.Id, Selected = s.Id == model.Address.StateProvinceId });
+
+ model.Address.CountryEnabled = true;
+ model.Address.StateProvinceEnabled = true;
+ model.Address.CityEnabled = true;
+ model.Address.StreetAddressEnabled = true;
+ model.Address.ZipPostalCodeEnabled = true;
+ model.Address.ZipPostalCodeRequired = true;
+ model.Address.PhoneEnabled = true;
+ model.Address.FaxEnabled = true;
+ model.Address.CompanyEnabled = true;
+
+ if (scope.DefaultStoreId is null)
+ {
+ model.AvailableStores.Add(new SelectListItem {
+ Text = translationService.GetResource("Admin.Configuration.Shipping.PickupPoint.SelectStore"),
+ Value = ""
+ });
+ foreach (var s in await storeService.GetAllStores())
+ model.AvailableStores.Add(new SelectListItem { Text = s.Shortcut, Value = s.Id, Selected = s.Id == model.StoreId });
+ }
+
+ model.AvailableWarehouses.Add(new SelectListItem {
+ Text = translationService.GetResource("Admin.Configuration.Shipping.PickupPoint.SelectWarehouse"),
+ Value = ""
+ });
+ foreach (var w in await warehouseService.GetAllWarehouses(scope.DefaultStoreId ?? ""))
+ model.AvailableWarehouses.Add(new SelectListItem { Text = w.Name, Value = w.Id, Selected = w.Id == model.WarehouseId });
+ }
+
+ protected virtual async Task<IActionResult> PickupPointListCore()
+ {
+ var storeMap = (await storeService.GetAllStores()).ToDictionary(s => s.Id, s => s.Shortcut);
+ var points = (await pickupPointService.GetAllPickupPoints(scope.DefaultStoreId ?? "")).ToList();
+ var model = points.Select(x => {
+ var m = x.ToModel();
+ m.StoreName = !string.IsNullOrEmpty(x.StoreId) && storeMap.TryGetValue(x.StoreId, out var name) ? name : "";
+ return m;
+ }).ToList();
+ return Json(new DataSourceResult { Data = model, Total = model.Count });
+ }
+
+ protected virtual async Task<IActionResult> PickupPointCreateGetCore()
+ {
+ var model = new PickupPointModel();
+ await PreparePickupPointModel(model);
+ return View(model);
+ }
+
+ protected virtual async Task<IActionResult> PickupPointCreatePostCore(PickupPointModel model, bool continueEditing)
+ {
+ if (!ModelState.IsValid)
+ {
+ await PreparePickupPointModel(model);
+ return View(model);
+ }
+ var pickupPoint = model.ToEntity();
+ if (scope.DefaultStoreId is not null) pickupPoint.StoreId = scope.DefaultStoreId;
+ await pickupPointService.InsertPickupPoint(pickupPoint);
+ Success(translationService.GetResource("Admin.Configuration.Shipping.PickupPoints.Added"));
+ return continueEditing
+ ? RedirectToAction("EditPickupPoint", new { id = pickupPoint.Id })
+ : RedirectToAction("PickupPoints");
+ }
+
+ protected virtual async Task<IActionResult> PickupPointEditGetCore(string id)
+ {
+ var pickupPoint = await pickupPointService.GetPickupPointById(id);
+ if (pickupPoint == null || !await scope.HasAccess(pickupPoint)) return RedirectToAction("PickupPoints");
+ var model = pickupPoint.ToModel();
+ await PreparePickupPointModel(model);
+ return View(model);
+ }
+
+ protected virtual async Task<IActionResult> PickupPointEditPostCore(PickupPointModel model, bool continueEditing)
+ {
+ var pickupPoint = await pickupPointService.GetPickupPointById(model.Id);
+ if (pickupPoint == null || !await scope.HasAccess(pickupPoint)) return RedirectToAction("PickupPoints");
+ if (!ModelState.IsValid)
+ {
+ await PreparePickupPointModel(model);
+ return View(model);
+ }
+ pickupPoint = model.ToEntity(pickupPoint);
+ if (scope.DefaultStoreId is not null) pickupPoint.StoreId = scope.DefaultStoreId;
+ await pickupPointService.UpdatePickupPoint(pickupPoint);
+ Success(translationService.GetResource("Admin.Configuration.Shipping.PickupPoints.Updated"));
+ return continueEditing
+ ? RedirectToAction("EditPickupPoint", new { id = pickupPoint.Id })
+ : RedirectToAction("PickupPoints");
+ }
+
+ protected virtual async Task<IActionResult> PickupPointDeleteCore(string id)
+ {
+ var pickupPoint = await pickupPointService.GetPickupPointById(id);
+ if (pickupPoint == null || !await scope.HasAccess(pickupPoint)) return RedirectToAction("PickupPoints");
+ await pickupPointService.DeletePickupPoint(pickupPoint);
+ Success(translationService.GetResource("Admin.Configuration.Shipping.PickupPoints.Deleted"));
+ return RedirectToAction("PickupPoints");
+ }
+}
diff --git a/src/Web/Grand.Web.AdminShared/Controllers/BaseShippingMethodController.cs b/src/Web/Grand.Web.AdminShared/Controllers/BaseShippingMethodController.cs
new file mode 100644
index 000000000..763651d50
--- /dev/null
+++ b/src/Web/Grand.Web.AdminShared/Controllers/BaseShippingMethodController.cs
@@ -0,0 +1,108 @@
+using Grand.Business.Core.Extensions;
+using Grand.Business.Core.Interfaces.Checkout.Shipping;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Shipping;
+using Grand.Web.AdminShared.Extensions.Mapping;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Models.Shipping;
+using Grand.Web.Common.Controllers;
+using Grand.Web.Common.DataSource;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Rendering;
+
+namespace Grand.Web.AdminShared.Controllers;
+
+[SharedViewFolder("Shipping")]
+public abstract class BaseShippingMethodController(
+ IShippingMethodService shippingMethodService,
+ ILanguageService languageService,
+ IStoreService storeService,
+ ITranslationService translationService,
+ IAdminDataScope<ShippingMethod> scope) : BaseController
+{
+ protected virtual async Task PrepareShippingMethodModel(ShippingMethodModel model)
+ {
+ if (scope.DefaultStoreId is null)
+ {
+ model.AvailableStores.Add(new SelectListItem {
+ Text = translationService.GetResource("Admin.Configuration.Shipping.Methods.SelectStore"),
+ Value = ""
+ });
+ foreach (var s in await storeService.GetAllStores())
+ model.AvailableStores.Add(new SelectListItem { Text = s.Shortcut, Value = s.Id, Selected = s.Id == model.StoreId });
+ }
+ }
+
+ protected virtual async Task<IActionResult> ShippingMethodListCore()
+ {
+ var storeMap = (await storeService.GetAllStores()).ToDictionary(s => s.Id, s => s.Shortcut);
+ var methods = await shippingMethodService.GetAllShippingMethods(storeId: scope.DefaultStoreId ?? "");
+ var model = methods.Select(x => {
+ var m = x.ToModel();
+ m.StoreName = !string.IsNullOrEmpty(x.StoreId) && storeMap.TryGetValue(x.StoreId, out var name) ? name : "";
+ return m;
+ }).ToList();
+ return Json(new DataSourceResult { Data = model, Total = model.Count });
+ }
+
+ protected virtual async Task<IActionResult> ShippingMethodCreateGetCore()
+ {
+ var model = new ShippingMethodModel();
+ await AddLocales(languageService, model.Locales);
+ await PrepareShippingMethodModel(model);
+ return View(model);
+ }
+
+ protected virtual async Task<IActionResult> ShippingMethodCreatePostCore(ShippingMethodModel model, bool continueEditing)
+ {
+ if (!ModelState.IsValid)
+ {
+ await PrepareShippingMethodModel(model);
+ return View(model);
+ }
+ var sm = model.ToEntity();
+ if (scope.DefaultStoreId is not null) sm.StoreId = scope.DefaultStoreId;
+ await shippingMethodService.InsertShippingMethod(sm);
+ Success(translationService.GetResource("Admin.Configuration.Shipping.Methods.Added"));
+ return continueEditing ? RedirectToAction("EditMethod", new { id = sm.Id }) : RedirectToAction("Methods");
+ }
+
+ protected virtual async Task<IActionResult> ShippingMethodEditGetCore(string id)
+ {
+ var sm = await shippingMethodService.GetShippingMethodById(id);
+ if (sm == null || !await scope.HasAccess(sm)) return RedirectToAction("Methods");
+ var model = sm.ToModel();
+ await AddLocales(languageService, model.Locales, (locale, languageId) => {
+ locale.Name = sm.GetTranslation(x => x.Name, languageId, false);
+ locale.Description = sm.GetTranslation(x => x.Description, languageId, false);
+ });
+ await PrepareShippingMethodModel(model);
+ return View(model);
+ }
+
+ protected virtual async Task<IActionResult> ShippingMethodEditPostCore(ShippingMethodModel model, bool continueEditing)
+ {
+ var sm = await shippingMethodService.GetShippingMethodById(model.Id);
+ if (sm == null || !await scope.HasAccess(sm)) return RedirectToAction("Methods");
+ if (!ModelState.IsValid)
+ {
+ await PrepareShippingMethodModel(model);
+ return View(model);
+ }
+ sm = model.ToEntity(sm);
+ if (scope.DefaultStoreId is not null) sm.StoreId = scope.DefaultStoreId;
+ await shippingMethodService.UpdateShippingMethod(sm);
+ Success(translationService.GetResource("Admin.Configuration.Shipping.Methods.Updated"));
+ return continueEditing ? RedirectToAction("EditMethod", new { id = sm.Id }) : RedirectToAction("Methods");
+ }
+
+ protected virtual async Task<IActionResult> ShippingMethodDeleteCore(string id)
+ {
+ var sm = await shippingMethodService.GetShippingMethodById(id);
+ if (sm == null || !await scope.HasAccess(sm)) return RedirectToAction("Methods");
+ await shippingMethodService.DeleteShippingMethod(sm);
+ Success(translationService.GetResource("Admin.Configuration.Shipping.Methods.Deleted"));
+ return RedirectToAction("Methods");
+ }
+}
diff --git a/src/Web/Grand.Web.AdminShared/Controllers/BaseWarehouseController.cs b/src/Web/Grand.Web.AdminShared/Controllers/BaseWarehouseController.cs
new file mode 100644
index 000000000..c2da91f3a
--- /dev/null
+++ b/src/Web/Grand.Web.AdminShared/Controllers/BaseWarehouseController.cs
@@ -0,0 +1,132 @@
+using Grand.Business.Core.Interfaces.Checkout.Shipping;
+using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Directory;
+using Grand.Web.AdminShared.Extensions.Mapping;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Models.Shipping;
+using Grand.Web.Common.Controllers;
+using Grand.Web.Common.DataSource;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Rendering;
+
+namespace Grand.Web.AdminShared.Controllers;
+
+[SharedViewFolder("Shipping")]
+public abstract class BaseWarehouseController(
+ IWarehouseService warehouseService,
+ ICountryService countryService,
+ IStoreService storeService,
+ ITranslationService translationService,
+ IAdminDataScope<Grand.Domain.Shipping.Warehouse> scope) : BaseController
+{
+ protected virtual async Task PrepareWarehouseModel(WarehouseModel model)
+ {
+ model.Address.AvailableCountries.Add(new SelectListItem
+ { Text = translationService.GetResource("Admin.Address.SelectCountry"), Value = "" });
+ foreach (var c in await countryService.GetAllCountries(showHidden: true))
+ model.Address.AvailableCountries.Add(new SelectListItem
+ { Text = c.Name, Value = c.Id, Selected = c.Id == model.Address.CountryId });
+ var states = !string.IsNullOrEmpty(model.Address.CountryId)
+ ? (await countryService.GetCountryById(model.Address.CountryId))?.StateProvinces
+ : new List<StateProvince>();
+ if (states?.Count > 0)
+ foreach (var s in states)
+ model.Address.AvailableStates.Add(new SelectListItem
+ { Text = s.Name, Value = s.Id, Selected = s.Id == model.Address.StateProvinceId });
+
+ model.Address.CountryEnabled = true;
+ model.Address.StateProvinceEnabled = true;
+ model.Address.CityEnabled = true;
+ model.Address.StreetAddressEnabled = true;
+ model.Address.ZipPostalCodeEnabled = true;
+ model.Address.ZipPostalCodeRequired = true;
+ model.Address.PhoneEnabled = true;
+ model.Address.FaxEnabled = true;
+ model.Address.CompanyEnabled = true;
+
+ if (scope.DefaultStoreId is null)
+ {
+ model.AvailableStores.Add(new SelectListItem {
+ Text = translationService.GetResource("Admin.Configuration.Shipping.Warehouses.SelectStore"),
+ Value = ""
+ });
+ foreach (var s in await storeService.GetAllStores())
+ model.AvailableStores.Add(new SelectListItem { Text = s.Shortcut, Value = s.Id, Selected = s.Id == model.StoreId });
+ }
+ }
+
+ protected virtual async Task<IActionResult> WarehouseListCore()
+ {
+ var storeMap = (await storeService.GetAllStores()).ToDictionary(s => s.Id, s => s.Shortcut);
+ var warehouses = (await warehouseService.GetAllWarehouses(scope.DefaultStoreId ?? "")).ToList();
+ var model = warehouses.Select(x => {
+ var m = x.ToModel();
+ m.StoreName = !string.IsNullOrEmpty(x.StoreId) && storeMap.TryGetValue(x.StoreId, out var name) ? name : "";
+ return m;
+ }).ToList();
+ return Json(new DataSourceResult { Data = model, Total = model.Count });
+ }
+
+ protected virtual async Task<IActionResult> WarehouseCreateGetCore()
+ {
+ var model = new WarehouseModel();
+ await PrepareWarehouseModel(model);
+ return View(model);
+ }
+
+ protected virtual async Task<IActionResult> WarehouseCreatePostCore(WarehouseModel model, bool continueEditing)
+ {
+ if (!ModelState.IsValid)
+ {
+ await PrepareWarehouseModel(model);
+ return View(model);
+ }
+ var warehouse = model.ToEntity();
+ warehouse.Address = model.Address.ToEntity();
+ if (scope.DefaultStoreId is not null) warehouse.StoreId = scope.DefaultStoreId;
+ await warehouseService.InsertWarehouse(warehouse);
+ Success(translationService.GetResource("Admin.Configuration.Shipping.Warehouses.Added"));
+ return continueEditing
+ ? RedirectToAction("EditWarehouse", new { id = warehouse.Id })
+ : RedirectToAction("Warehouses");
+ }
+
+ protected virtual async Task<IActionResult> WarehouseEditGetCore(string id)
+ {
+ var warehouse = await warehouseService.GetWarehouseById(id);
+ if (warehouse == null || !await scope.HasAccess(warehouse)) return RedirectToAction("Warehouses");
+ var model = warehouse.ToModel();
+ await PrepareWarehouseModel(model);
+ return View(model);
+ }
+
+ protected virtual async Task<IActionResult> WarehouseEditPostCore(WarehouseModel model, bool continueEditing)
+ {
+ var warehouse = await warehouseService.GetWarehouseById(model.Id);
+ if (warehouse == null || !await scope.HasAccess(warehouse)) return RedirectToAction("Warehouses");
+ if (!ModelState.IsValid)
+ {
+ await PrepareWarehouseModel(model);
+ return View(model);
+ }
+ warehouse = model.ToEntity(warehouse);
+ warehouse.Address = model.Address.ToEntity();
+ if (scope.DefaultStoreId is not null) warehouse.StoreId = scope.DefaultStoreId;
+ await warehouseService.UpdateWarehouse(warehouse);
+ Success(translationService.GetResource("Admin.Configuration.Shipping.Warehouses.Updated"));
+ return continueEditing
+ ? RedirectToAction("EditWarehouse", new { id = warehouse.Id })
+ : RedirectToAction("Warehouses");
+ }
+
+ protected virtual async Task<IActionResult> WarehouseDeleteCore(string id)
+ {
+ var warehouse = await warehouseService.GetWarehouseById(id);
+ if (warehouse == null || !await scope.HasAccess(warehouse)) return RedirectToAction("Warehouses");
+ await warehouseService.DeleteWarehouse(warehouse);
+ Success(translationService.GetResource("Admin.Configuration.Shipping.Warehouses.Deleted"));
+ return RedirectToAction("Warehouses");
+ }
+}
diff --git a/src/Web/Grand.Web.AdminShared/Services/RoutedDeliveryDateDataScope.cs b/src/Web/Grand.Web.AdminShared/Services/RoutedDeliveryDateDataScope.cs
new file mode 100644
index 000000000..c1aced9fc
--- /dev/null
+++ b/src/Web/Grand.Web.AdminShared/Services/RoutedDeliveryDateDataScope.cs
@@ -0,0 +1,35 @@
+#nullable enable
+
+using Grand.Domain.Shipping;
+using Grand.Web.AdminShared.Interfaces;
+using Microsoft.AspNetCore.Http;
+
+namespace Grand.Web.AdminShared.Services;
+
+public class RoutedDeliveryDateDataScope(
+ IHttpContextAccessor httpContextAccessor,
+ GlobalAdminDataScope<DeliveryDate> globalScope,
+ StoreDeliveryDateDataScope storeScope) : IAdminDataScope<DeliveryDate>
+{
+ private IAdminDataScope<DeliveryDate> Resolved
+ {
+ get
+ {
+ var area = httpContextAccessor.HttpContext?.Request.RouteValues["area"] as string;
+ return area switch {
+ "Admin" => globalScope,
+ "Store" => storeScope,
+ _ => throw new InvalidOperationException(
+ $"RoutedDeliveryDateDataScope: unrecognized or missing area '{area}'.")
+ };
+ }
+ }
+
+ public Task<bool> HasAccess(DeliveryDate entity) => Resolved.HasAccess(entity);
+ public Task<bool> CanView(DeliveryDate entity) => Resolved.CanView(entity);
+ public string? DefaultStoreId => Resolved.DefaultStoreId;
+ public string ResourceKeyPrefix => Resolved.ResourceKeyPrefix;
+ public bool ShowStoreSelector => Resolved.ShowStoreSelector;
+ public string? DefaultVendorId => Resolved.DefaultVendorId;
+ public bool CanFeatureOnHomepage => Resolved.CanFeatureOnHomepage;
+}
diff --git a/src/Web/Grand.Web.AdminShared/Services/RoutedPickupPointDataScope.cs b/src/Web/Grand.Web.AdminShared/Services/RoutedPickupPointDataScope.cs
new file mode 100644
index 000000000..998edec44
--- /dev/null
+++ b/src/Web/Grand.Web.AdminShared/Services/RoutedPickupPointDataScope.cs
@@ -0,0 +1,35 @@
+#nullable enable
+
+using Grand.Domain.Shipping;
+using Grand.Web.AdminShared.Interfaces;
+using Microsoft.AspNetCore.Http;
+
+namespace Grand.Web.AdminShared.Services;
+
+public class RoutedPickupPointDataScope(
+ IHttpContextAccessor httpContextAccessor,
+ GlobalAdminDataScope<PickupPoint> globalScope,
+ StorePickupPointDataScope storeScope) : IAdminDataScope<PickupPoint>
+{
+ private IAdminDataScope<PickupPoint> Resolved
+ {
+ get
+ {
+ var area = httpContextAccessor.HttpContext?.Request.RouteValues["area"] as string;
+ return area switch {
+ "Admin" => globalScope,
+ "Store" => storeScope,
+ _ => throw new InvalidOperationException(
+ $"RoutedPickupPointDataScope: unrecognized or missing area '{area}'.")
+ };
+ }
+ }
+
+ public Task<bool> HasAccess(PickupPoint entity) => Resolved.HasAccess(entity);
+ public Task<bool> CanView(PickupPoint entity) => Resolved.CanView(entity);
+ public string? DefaultStoreId => Resolved.DefaultStoreId;
+ public string ResourceKeyPrefix => Resolved.ResourceKeyPrefix;
+ public bool ShowStoreSelector => Resolved.ShowStoreSelector;
+ public string? DefaultVendorId => Resolved.DefaultVendorId;
+ public bool CanFeatureOnHomepage => Resolved.CanFeatureOnHomepage;
+}
diff --git a/src/Web/Grand.Web.AdminShared/Services/RoutedShippingMethodDataScope.cs b/src/Web/Grand.Web.AdminShared/Services/RoutedShippingMethodDataScope.cs
new file mode 100644
index 000000000..cdea27c10
--- /dev/null
+++ b/src/Web/Grand.Web.AdminShared/Services/RoutedShippingMethodDataScope.cs
@@ -0,0 +1,35 @@
+#nullable enable
+
+using Grand.Domain.Shipping;
+using Grand.Web.AdminShared.Interfaces;
+using Microsoft.AspNetCore.Http;
+
+namespace Grand.Web.AdminShared.Services;
+
+public class RoutedShippingMethodDataScope(
+ IHttpContextAccessor httpContextAccessor,
+ GlobalAdminDataScope<ShippingMethod> globalScope,
+ StoreShippingMethodDataScope storeScope) : IAdminDataScope<ShippingMethod>
+{
+ private IAdminDataScope<ShippingMethod> Resolved
+ {
+ get
+ {
+ var area = httpContextAccessor.HttpContext?.Request.RouteValues["area"] as string;
+ return area switch {
+ "Admin" => globalScope,
+ "Store" => storeScope,
+ _ => throw new InvalidOperationException(
+ $"RoutedShippingMethodDataScope: unrecognized or missing area '{area}'.")
+ };
+ }
+ }
+
+ public Task<bool> HasAccess(ShippingMethod entity) => Resolved.HasAccess(entity);
+ public Task<bool> CanView(ShippingMethod entity) => Resolved.CanView(entity);
+ public string? DefaultStoreId => Resolved.DefaultStoreId;
+ public string ResourceKeyPrefix => Resolved.ResourceKeyPrefix;
+ public bool ShowStoreSelector => Resolved.ShowStoreSelector;
+ public string? DefaultVendorId => Resolved.DefaultVendorId;
+ public bool CanFeatureOnHomepage => Resolved.CanFeatureOnHomepage;
+}
diff --git a/src/Web/Grand.Web.AdminShared/Services/RoutedWarehouseDataScope.cs b/src/Web/Grand.Web.AdminShared/Services/RoutedWarehouseDataScope.cs
new file mode 100644
index 000000000..f3885ce8b
--- /dev/null
+++ b/src/Web/Grand.Web.AdminShared/Services/RoutedWarehouseDataScope.cs
@@ -0,0 +1,42 @@
+#nullable enable
+
+using Grand.Domain.Shipping;
+using Grand.Web.AdminShared.Interfaces;
+using Microsoft.AspNetCore.Http;
+
+namespace Grand.Web.AdminShared.Services;
+
+/// <summary>
+/// Resolves the correct per-host <see cref="IAdminDataScope{Warehouse}" /> implementation at
+/// request time, based on the current request's "area" route value — same fix and same reason as
+/// <see cref="RoutedCategoryDataScope"/>: Grand.Web (the combined host) loads Admin and Store
+/// together in one DI container. No Vendor branch: Vendor has no Shipping screen at all, so any
+/// "Vendor" (or other unrecognized/missing) area value fails closed.
+/// </summary>
+public class RoutedWarehouseDataScope(
+ IHttpContextAccessor httpContextAccessor,
+ GlobalAdminDataScope<Warehouse> globalScope,
+ StoreWarehouseDataScope storeScope) : IAdminDataScope<Warehouse>
+{
+ private IAdminDataScope<Warehouse> Resolved
+ {
+ get
+ {
+ var area = httpContextAccessor.HttpContext?.Request.RouteValues["area"] as string;
+ return area switch {
+ "Admin" => globalScope,
+ "Store" => storeScope,
+ _ => throw new InvalidOperationException(
+ $"RoutedWarehouseDataScope: unrecognized or missing area '{area}'.")
+ };
+ }
+ }
+
+ public Task<bool> HasAccess(Warehouse entity) => Resolved.HasAccess(entity);
+ public Task<bool> CanView(Warehouse entity) => Resolved.CanView(entity);
+ public string? DefaultStoreId => Resolved.DefaultStoreId;
+ public string ResourceKeyPrefix => Resolved.ResourceKeyPrefix;
+ public bool ShowStoreSelector => Resolved.ShowStoreSelector;
+ public string? DefaultVendorId => Resolved.DefaultVendorId;
+ public bool CanFeatureOnHomepage => Resolved.CanFeatureOnHomepage;
+}
diff --git a/src/Web/Grand.Web.AdminShared/Services/StoreDeliveryDateDataScope.cs b/src/Web/Grand.Web.AdminShared/Services/StoreDeliveryDateDataScope.cs
new file mode 100644
index 000000000..1f1082965
--- /dev/null
+++ b/src/Web/Grand.Web.AdminShared/Services/StoreDeliveryDateDataScope.cs
@@ -0,0 +1,20 @@
+#nullable enable
+
+using Grand.Domain.Shipping;
+using Grand.Infrastructure;
+using Grand.Web.AdminShared.Interfaces;
+
+namespace Grand.Web.AdminShared.Services;
+
+public class StoreDeliveryDateDataScope(IContextAccessor contextAccessor) : IAdminDataScope<DeliveryDate>
+{
+ public Task<bool> HasAccess(DeliveryDate entity) =>
+ Task.FromResult(entity is not null &&
+ entity.StoreId == contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+
+ public string? DefaultStoreId => contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ public string ResourceKeyPrefix => "Admin";
+ public bool ShowStoreSelector => true;
+ public string? DefaultVendorId => null;
+ public bool CanFeatureOnHomepage => true;
+}
diff --git a/src/Web/Grand.Web.AdminShared/Services/StorePickupPointDataScope.cs b/src/Web/Grand.Web.AdminShared/Services/StorePickupPointDataScope.cs
new file mode 100644
index 000000000..262d28c71
--- /dev/null
+++ b/src/Web/Grand.Web.AdminShared/Services/StorePickupPointDataScope.cs
@@ -0,0 +1,20 @@
+#nullable enable
+
+using Grand.Domain.Shipping;
+using Grand.Infrastructure;
+using Grand.Web.AdminShared.Interfaces;
+
+namespace Grand.Web.AdminShared.Services;
+
+public class StorePickupPointDataScope(IContextAccessor contextAccessor) : IAdminDataScope<PickupPoint>
+{
+ public Task<bool> HasAccess(PickupPoint entity) =>
+ Task.FromResult(entity is not null &&
+ entity.StoreId == contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+
+ public string? DefaultStoreId => contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ public string ResourceKeyPrefix => "Admin";
+ public bool ShowStoreSelector => true;
+ public string? DefaultVendorId => null;
+ public bool CanFeatureOnHomepage => true;
+}
diff --git a/src/Web/Grand.Web.AdminShared/Services/StoreShippingMethodDataScope.cs b/src/Web/Grand.Web.AdminShared/Services/StoreShippingMethodDataScope.cs
new file mode 100644
index 000000000..882467c12
--- /dev/null
+++ b/src/Web/Grand.Web.AdminShared/Services/StoreShippingMethodDataScope.cs
@@ -0,0 +1,27 @@
+#nullable enable
+
+using Grand.Domain.Shipping;
+using Grand.Infrastructure;
+using Grand.Web.AdminShared.Interfaces;
+
+namespace Grand.Web.AdminShared.Services;
+
+/// <summary>
+/// Store's <see cref="IAdminDataScope{ShippingMethod}" />. Bespoke, not the generic
+/// <see cref="StoreAdminDataScope{TEntity}" />: <c>ShippingMethod</c> is a plain
+/// <see cref="Grand.Domain.BaseEntity" /> with a single <c>StoreId</c> field, not
+/// <c>IStoreLinkEntity</c>. Mirrors Store's original <c>ShippingController</c>'s
+/// <c>sm.StoreId != CurrentStoreId</c> check.
+/// </summary>
+public class StoreShippingMethodDataScope(IContextAccessor contextAccessor) : IAdminDataScope<ShippingMethod>
+{
+ public Task<bool> HasAccess(ShippingMethod entity) =>
+ Task.FromResult(entity is not null &&
+ entity.StoreId == contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+
+ public string? DefaultStoreId => contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ public string ResourceKeyPrefix => "Admin";
+ public bool ShowStoreSelector => true;
+ public string? DefaultVendorId => null;
+ public bool CanFeatureOnHomepage => true;
+}
diff --git a/src/Web/Grand.Web.AdminShared/Services/StoreWarehouseDataScope.cs b/src/Web/Grand.Web.AdminShared/Services/StoreWarehouseDataScope.cs
new file mode 100644
index 000000000..57c9a7fae
--- /dev/null
+++ b/src/Web/Grand.Web.AdminShared/Services/StoreWarehouseDataScope.cs
@@ -0,0 +1,27 @@
+#nullable enable
+
+using Grand.Domain.Shipping;
+using Grand.Infrastructure;
+using Grand.Web.AdminShared.Interfaces;
+
+namespace Grand.Web.AdminShared.Services;
+
+/// <summary>
+/// Store's <see cref="IAdminDataScope{Warehouse}" />. Bespoke, not the generic
+/// <see cref="StoreAdminDataScope{TEntity}" />: <c>Warehouse</c> is a plain <see cref="Grand.Domain.BaseEntity" />
+/// with a single <c>StoreId</c> field, not <c>IStoreLinkEntity</c>. Mirrors Store's original
+/// <c>ShippingController</c>'s <c>warehouse.StoreId != CurrentStoreId</c> check, repeated at every
+/// Warehouse action site in that file.
+/// </summary>
+public class StoreWarehouseDataScope(IContextAccessor contextAccessor) : IAdminDataScope<Warehouse>
+{
+ public Task<bool> HasAccess(Warehouse entity) =>
+ Task.FromResult(entity is not null &&
+ entity.StoreId == contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);
+
+ public string? DefaultStoreId => contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+ public string ResourceKeyPrefix => "Admin";
+ public bool ShowStoreSelector => true;
+ public string? DefaultVendorId => null;
+ public bool CanFeatureOnHomepage => true;
+}
diff --git a/src/Web/Grand.Web.AdminShared/Startup/StartupApplication.cs b/src/Web/Grand.Web.AdminShared/Startup/StartupApplication.cs
index 4557caf05..935e76a61 100644
--- a/src/Web/Grand.Web.AdminShared/Startup/StartupApplication.cs
+++ b/src/Web/Grand.Web.AdminShared/Startup/StartupApplication.cs
@@ -174,6 +174,29 @@ public class StartupApplication : IStartupApplication
services.AddScoped<StoreEmailAccountDataScope>();
services.AddScoped<IAdminDataScope<EmailAccount>, RoutedEmailAccountDataScope>();
+ // IAdminDataScope<Warehouse>: registered once here for the same reason as Category/
+ // EmailAccount above — see RoutedWarehouseDataScope's doc comment. No Vendor scope:
+ // Shipping has no Vendor screen.
+ services.AddScoped<GlobalAdminDataScope<Warehouse>>();
+ services.AddScoped<StoreWarehouseDataScope>();
+ services.AddScoped<IAdminDataScope<Warehouse>, RoutedWarehouseDataScope>();
+
+ // IAdminDataScope<ShippingMethod>: registered once here, same reason as Warehouse above.
+ services.AddScoped<GlobalAdminDataScope<ShippingMethod>>();
+ services.AddScoped<StoreShippingMethodDataScope>();
+ services.AddScoped<IAdminDataScope<ShippingMethod>, RoutedShippingMethodDataScope>();
+
+ // IAdminDataScope<DeliveryDate>: registered once here, same reason as Warehouse/ShippingMethod above.
+ services.AddScoped<GlobalAdminDataScope<DeliveryDate>>();
+ services.AddScoped<StoreDeliveryDateDataScope>();
+ services.AddScoped<IAdminDataScope<DeliveryDate>, RoutedDeliveryDateDataScope>();
+
+ // IAdminDataScope<PickupPoint>: registered once here, same reason as the other three
+ // Shipping sub-entities above. WarehouseId is a plain FK, not a scope concern.
+ services.AddScoped<GlobalAdminDataScope<PickupPoint>>();
+ services.AddScoped<StorePickupPointDataScope>();
+ services.AddScoped<IAdminDataScope<PickupPoint>, RoutedPickupPointDataScope>();
+
// IAdminDataScope<TaxCategory>: registered once here for the same reason as EmailAccount
// above — see RoutedTaxCategoryDataScope's doc comment. No Vendor scope: Tax has no
// Vendor screen.
diff --git a/src/Web/Grand.Web.Common/Controllers/SharedViewFolderAttribute.cs b/src/Web/Grand.Web.Common/Controllers/SharedViewFolderAttribute.cs
new file mode 100644
index 000000000..8b62ede59
--- /dev/null
+++ b/src/Web/Grand.Web.Common/Controllers/SharedViewFolderAttribute.cs
@@ -0,0 +1,17 @@
+namespace Grand.Web.Common.Controllers;
+
+/// <summary>
+/// Applied to an abstract base controller (in Grand.Web.AdminShared) whose concrete per-host
+/// subclasses are named differently than the view folder their .cshtml files still live under —
+/// needed when one host's original controller file is split into several entity-specific base-
+/// controller-derived classes that each keep the original controller's view folder via routing
+/// but not via C# class naming. Inherited (default), so applying this once on the abstract base
+/// covers every concrete subclass in every host without repeating it.
+/// </summary>
+[AttributeUsage(AttributeTargets.Class, Inherited = true)]
+public class SharedViewFolderAttribute(string controllerName) : Attribute
+{
+ /// <summary>The view-folder name Razor should search under (e.g. "Shipping"), NOT the
+ /// controller's own C# class-derived name.</summary>
+ public string ControllerName { get; } = controllerName;
+}
diff --git a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
index ec9cda3e8..effe5dba8 100644
--- a/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
+++ b/src/Web/Grand.Web.Common/Infrastructure/ServiceCollectionExtensions.cs
@@ -206,6 +206,9 @@ public static class ServiceCollectionExtensions
options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
});
+ mvcBuilder.AddMvcOptions(options =>
+ options.Conventions.Add(new SharedViewFolderControllerNameConvention()));
+
//add view localization
mvcBuilder.AddViewLocalization();
diff --git a/src/Web/Grand.Web.Common/Infrastructure/SharedViewFolderControllerNameConvention.cs b/src/Web/Grand.Web.Common/Infrastructure/SharedViewFolderControllerNameConvention.cs
new file mode 100644
index 000000000..b5bed64a3
--- /dev/null
+++ b/src/Web/Grand.Web.Common/Infrastructure/SharedViewFolderControllerNameConvention.cs
@@ -0,0 +1,22 @@
+using Grand.Web.Common.Controllers;
+using Microsoft.AspNetCore.Mvc.ApplicationModels;
+
+namespace Grand.Web.Common.Infrastructure;
+
+/// <summary>
+/// Renames a controller's MVC <c>ControllerName</c> (which Razor's default view-location
+/// convention uses to pick the view-search folder) to whatever <see cref="SharedViewFolderAttribute"/>
+/// declares, for any controller type carrying that attribute. URL routing is unaffected — this
+/// only changes where the view engine looks for a view when an action calls <c>View()</c>.
+/// </summary>
+public class SharedViewFolderControllerNameConvention : IControllerModelConvention
+{
+ public void Apply(ControllerModel controller)
+ {
+ var attr = controller.ControllerType.GetCustomAttributes(typeof(SharedViewFolderAttribute), true)
+ .OfType<SharedViewFolderAttribute>()
+ .FirstOrDefault();
+ if (attr is not null)
+ controller.ControllerName = attr.ControllerName;
+ }
+}
diff --git a/src/Web/Grand.Web.Store/Controllers/DeliveryDateController.cs b/src/Web/Grand.Web.Store/Controllers/DeliveryDateController.cs
new file mode 100644
index 000000000..3dab6066f
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Controllers/DeliveryDateController.cs
@@ -0,0 +1,60 @@
+using Grand.Business.Core.Interfaces.Checkout.Shipping;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Permissions;
+using Grand.Web.AdminShared.Controllers;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Models.Shipping;
+using Grand.Web.Common.Filters;
+using Grand.Web.Common.Security.Authorization;
+using Grand.Web.Store.Extensions;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Grand.Web.Store.Controllers;
+
+[Area(Constants.AreaStore)]
+[AuthorizeStore]
+[AutoValidateAntiforgeryToken]
+[AuthorizeMenu]
+[PermissionAuthorize(PermissionSystemName.ShippingSettings)]
+[Route("[area]/Shipping/[action]")]
+public class DeliveryDateController(
+ IDeliveryDateService deliveryDateService,
+ ILanguageService languageService,
+ IStoreService storeService,
+ ITranslationService translationService,
+ IAdminDataScope<Grand.Domain.Shipping.DeliveryDate> scope)
+ : BaseDeliveryDateController(deliveryDateService, languageService, storeService, translationService, scope)
+{
+ [HttpGet]
+ [PermissionAuthorizeAction(PermissionActionName.List)]
+ public IActionResult DeliveryDates() => View();
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.List)]
+ public Task<IActionResult> DeliveryDatesListData() => DeliveryDateListCore();
+
+ [HttpGet]
+ [PermissionAuthorizeAction(PermissionActionName.Create)]
+ public Task<IActionResult> CreateDeliveryDate() => DeliveryDateCreateGetCore();
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.Create)]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public Task<IActionResult> CreateDeliveryDate(DeliveryDateModel model, bool continueEditing) =>
+ DeliveryDateCreatePostCore(model, continueEditing);
+
+ [HttpGet]
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ public Task<IActionResult> EditDeliveryDate(string id) => DeliveryDateEditGetCore(id);
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public Task<IActionResult> EditDeliveryDate(DeliveryDateModel model, bool continueEditing) =>
+ DeliveryDateEditPostCore(model, continueEditing);
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.Delete)]
+ public Task<IActionResult> DeleteDeliveryDate(string id) => DeliveryDateDeleteCore(id);
+}
diff --git a/src/Web/Grand.Web.Store/Controllers/PickupPointController.cs b/src/Web/Grand.Web.Store/Controllers/PickupPointController.cs
new file mode 100644
index 000000000..970894cea
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Controllers/PickupPointController.cs
@@ -0,0 +1,62 @@
+using Grand.Business.Core.Interfaces.Checkout.Shipping;
+using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Permissions;
+using Grand.Web.AdminShared.Controllers;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Models.Shipping;
+using Grand.Web.Common.Filters;
+using Grand.Web.Common.Security.Authorization;
+using Grand.Web.Store.Extensions;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Grand.Web.Store.Controllers;
+
+[Area(Constants.AreaStore)]
+[AuthorizeStore]
+[AutoValidateAntiforgeryToken]
+[AuthorizeMenu]
+[PermissionAuthorize(PermissionSystemName.ShippingSettings)]
+[Route("[area]/Shipping/[action]")]
+public class PickupPointController(
+ IPickupPointService pickupPointService,
+ IWarehouseService warehouseService,
+ ICountryService countryService,
+ IStoreService storeService,
+ ITranslationService translationService,
+ IAdminDataScope<Grand.Domain.Shipping.PickupPoint> scope)
+ : BasePickupPointController(pickupPointService, warehouseService, countryService, storeService, translationService, scope)
+{
+ [HttpGet]
+ [PermissionAuthorizeAction(PermissionActionName.List)]
+ public IActionResult PickupPoints() => View();
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.List)]
+ public Task<IActionResult> PickupPointsListData() => PickupPointListCore();
+
+ [HttpGet]
+ [PermissionAuthorizeAction(PermissionActionName.Create)]
+ public Task<IActionResult> CreatePickupPoint() => PickupPointCreateGetCore();
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.Create)]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public Task<IActionResult> CreatePickupPoint(PickupPointModel model, bool continueEditing) =>
+ PickupPointCreatePostCore(model, continueEditing);
+
+ [HttpGet]
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ public Task<IActionResult> EditPickupPoint(string id) => PickupPointEditGetCore(id);
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public Task<IActionResult> EditPickupPoint(PickupPointModel model, bool continueEditing) =>
+ PickupPointEditPostCore(model, continueEditing);
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.Delete)]
+ public Task<IActionResult> DeletePickupPoint(string id) => PickupPointDeleteCore(id);
+}
diff --git a/src/Web/Grand.Web.Store/Controllers/ShippingController.cs b/src/Web/Grand.Web.Store/Controllers/ShippingController.cs
index 515692fa5..017c2e5a6 100644
--- a/src/Web/Grand.Web.Store/Controllers/ShippingController.cs
+++ b/src/Web/Grand.Web.Store/Controllers/ShippingController.cs
@@ -26,60 +26,14 @@ namespace Grand.Web.Store.Controllers;
public class ShippingController(
IShippingService shippingService,
IShippingMethodService shippingMethodService,
- IDeliveryDateService deliveryDateService,
- IWarehouseService warehouseService,
- IPickupPointService pickupPointService,
ICountryService countryService,
IGroupService groupService,
- ILanguageService languageService,
ITranslationService translationService,
ISettingService settingService,
IContextAccessor contextAccessor) : BaseStoreController
{
private string CurrentStoreId => contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
- #region Utilities
-
- private async Task PrepareAddressModel(AddressModel model, string selectedCountryId)
- {
- model.AvailableCountries.Add(new SelectListItem { Text = translationService.GetResource("Admin.Address.SelectCountry"), Value = "" });
- foreach (var c in await countryService.GetAllCountries(showHidden: true))
- model.AvailableCountries.Add(new SelectListItem { Text = c.Name, Value = c.Id, Selected = c.Id == selectedCountryId });
-
- var states = !string.IsNullOrEmpty(selectedCountryId)
- ? (await countryService.GetCountryById(selectedCountryId))?.StateProvinces
- : new List<StateProvince>();
- if (states?.Count > 0)
- foreach (var s in states)
- model.AvailableStates.Add(new SelectListItem { Text = s.Name, Value = s.Id, Selected = s.Id == model.StateProvinceId });
-
- model.CountryEnabled = true;
- model.StateProvinceEnabled = true;
- model.CityEnabled = true;
- model.StreetAddressEnabled = true;
- model.ZipPostalCodeEnabled = true;
- model.ZipPostalCodeRequired = true;
- model.PhoneEnabled = true;
- model.FaxEnabled = true;
- model.CompanyEnabled = true;
- }
-
- private async Task PrepareWarehouseModel(WarehouseModel model)
- {
- await PrepareAddressModel(model.Address, model.Address.CountryId);
- }
-
- private async Task PreparePickupPointModel(PickupPointModel model)
- {
- await PrepareAddressModel(model.Address, model.Address.CountryId);
-
- model.AvailableWarehouses.Add(new SelectListItem { Text = translationService.GetResource("Admin.Configuration.Shipping.PickupPoint.SelectWarehouse"), Value = "" });
- foreach (var w in await warehouseService.GetAllWarehouses(CurrentStoreId))
- model.AvailableWarehouses.Add(new SelectListItem { Text = w.Name, Value = w.Id, Selected = w.Id == model.WarehouseId });
- }
-
- #endregion
-
#region Providers
public IActionResult Providers()
@@ -189,400 +143,6 @@ public class ShippingController(
#endregion
- #region Shipping methods
-
- public IActionResult Methods()
- {
- return View();
- }
-
- [HttpPost]
- [PermissionAuthorizeAction(PermissionActionName.List)]
- public async Task<IActionResult> MethodsListData()
- {
- var methods = (await shippingMethodService.GetAllShippingMethods(storeId: CurrentStoreId))
- .ToList();
- var gridModel = new DataSourceResult {
- Data = methods.Select(m => m.ToModel()),
- Total = methods.Count
- };
- return Json(gridModel);
- }
-
- [PermissionAuthorizeAction(PermissionActionName.Create)]
- public async Task<IActionResult> CreateMethod()
- {
- var model = new ShippingMethodModel();
- await AddLocales(languageService, model.Locales);
- return View(model);
- }
-
- [HttpPost]
- [PermissionAuthorizeAction(PermissionActionName.Create)]
- [Grand.Web.Common.Filters.ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
- public async Task<IActionResult> CreateMethod(ShippingMethodModel model, bool continueEditing)
- {
- if (ModelState.IsValid)
- {
- var sm = model.ToEntity();
- sm.StoreId = CurrentStoreId;
- await shippingMethodService.InsertShippingMethod(sm);
- Success(translationService.GetResource("Admin.Configuration.Shipping.Methods.Added"));
- return continueEditing
- ? RedirectToAction("EditMethod", new { id = sm.Id })
- : RedirectToAction("Methods");
- }
- return View(model);
- }
-
- [PermissionAuthorizeAction(PermissionActionName.Edit)]
- public async Task<IActionResult> EditMethod(string id)
- {
- var sm = await shippingMethodService.GetShippingMethodById(id);
- if (sm == null || sm.StoreId != CurrentStoreId)
- return RedirectToAction("Methods");
-
- var model = sm.ToModel();
- await AddLocales(languageService, model.Locales, (locale, languageId) => {
- locale.Name = sm.GetTranslation(x => x.Name, languageId, false);
- locale.Description = sm.GetTranslation(x => x.Description, languageId, false);
- });
- return View(model);
- }
-
- [HttpPost]
- [PermissionAuthorizeAction(PermissionActionName.Edit)]
- [Grand.Web.Common.Filters.ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
- public async Task<IActionResult> EditMethod(ShippingMethodModel model, bool continueEditing)
- {
- var sm = await shippingMethodService.GetShippingMethodById(model.Id);
- if (sm == null || sm.StoreId != CurrentStoreId)
- return RedirectToAction("Methods");
-
- if (ModelState.IsValid)
- {
- sm = model.ToEntity(sm);
- sm.StoreId = CurrentStoreId;
- await shippingMethodService.UpdateShippingMethod(sm);
- Success(translationService.GetResource("Admin.Configuration.Shipping.Methods.Updated"));
- return continueEditing
- ? RedirectToAction("EditMethod", new { id = sm.Id })
- : RedirectToAction("Methods");
- }
- return View(model);
- }
-
- [HttpPost]
- [PermissionAuthorizeAction(PermissionActionName.Delete)]
- public async Task<IActionResult> DeleteMethod(string id)
- {
- var sm = await shippingMethodService.GetShippingMethodById(id);
- if (sm == null || sm.StoreId != CurrentStoreId)
- return RedirectToAction("Methods");
-
- await shippingMethodService.DeleteShippingMethod(sm);
- Success(translationService.GetResource("Admin.Configuration.Shipping.Methods.Deleted"));
- return RedirectToAction("Methods");
- }
-
- #endregion
-
- #region Delivery dates
-
- public IActionResult DeliveryDates()
- {
- return View();
- }
-
- [HttpPost]
- [PermissionAuthorizeAction(PermissionActionName.List)]
- public async Task<IActionResult> DeliveryDatesListData()
- {
- var deliveryDates = (await deliveryDateService.GetAllDeliveryDates(CurrentStoreId))
- .ToList();
- var gridModel = new DataSourceResult {
- Data = deliveryDates.Select(d => d.ToModel()),
- Total = deliveryDates.Count
- };
- return Json(gridModel);
- }
-
- [PermissionAuthorizeAction(PermissionActionName.Create)]
- public async Task<IActionResult> CreateDeliveryDate()
- {
- var model = new DeliveryDateModel { ColorSquaresRgb = "#000000" };
- await AddLocales(languageService, model.Locales);
- return View(model);
- }
-
- [HttpPost]
- [PermissionAuthorizeAction(PermissionActionName.Create)]
- [Grand.Web.Common.Filters.ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
- public async Task<IActionResult> CreateDeliveryDate(DeliveryDateModel model, bool continueEditing)
- {
- if (ModelState.IsValid)
- {
- var deliveryDate = model.ToEntity();
- deliveryDate.StoreId = CurrentStoreId;
- await deliveryDateService.InsertDeliveryDate(deliveryDate);
- Success(translationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.Added"));
- return continueEditing
- ? RedirectToAction("EditDeliveryDate", new { id = deliveryDate.Id })
- : RedirectToAction("DeliveryDates");
- }
- return View(model);
- }
-
- [PermissionAuthorizeAction(PermissionActionName.Edit)]
- public async Task<IActionResult> EditDeliveryDate(string id)
- {
- var deliveryDate = await deliveryDateService.GetDeliveryDateById(id);
- if (deliveryDate == null || deliveryDate.StoreId != CurrentStoreId)
- return RedirectToAction("DeliveryDates");
-
- var model = deliveryDate.ToModel();
- if (string.IsNullOrEmpty(model.ColorSquaresRgb)) model.ColorSquaresRgb = "#000000";
- await AddLocales(languageService, model.Locales, (locale, languageId) => {
- locale.Name = deliveryDate.GetTranslation(x => x.Name, languageId, false);
- });
- return View(model);
- }
-
- [HttpPost]
- [PermissionAuthorizeAction(PermissionActionName.Edit)]
- [Grand.Web.Common.Filters.ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
- public async Task<IActionResult> EditDeliveryDate(DeliveryDateModel model, bool continueEditing)
- {
- var deliveryDate = await deliveryDateService.GetDeliveryDateById(model.Id);
- if (deliveryDate == null || deliveryDate.StoreId != CurrentStoreId)
- return RedirectToAction("DeliveryDates");
-
- if (ModelState.IsValid)
- {
- deliveryDate = model.ToEntity(deliveryDate);
- deliveryDate.StoreId = CurrentStoreId;
- await deliveryDateService.UpdateDeliveryDate(deliveryDate);
- Success(translationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.Updated"));
- return continueEditing
- ? RedirectToAction("EditDeliveryDate", new { id = deliveryDate.Id })
- : RedirectToAction("DeliveryDates");
- }
- return View(model);
- }
-
- [HttpPost]
- [PermissionAuthorizeAction(PermissionActionName.Delete)]
- public async Task<IActionResult> DeleteDeliveryDate(string id)
- {
- var deliveryDate = await deliveryDateService.GetDeliveryDateById(id);
- if (deliveryDate == null || deliveryDate.StoreId != CurrentStoreId)
- return RedirectToAction("DeliveryDates");
-
- await deliveryDateService.DeleteDeliveryDate(deliveryDate);
- Success(translationService.GetResource("Admin.Configuration.Shipping.DeliveryDates.Deleted"));
- return RedirectToAction("DeliveryDates");
- }
-
- #endregion
-
- #region Warehouses
-
- public IActionResult Warehouses()
- {
- return View();
- }
-
- [HttpPost]
- [PermissionAuthorizeAction(PermissionActionName.List)]
- public async Task<IActionResult> WarehousesListData()
- {
- var warehouses = (await warehouseService.GetAllWarehouses(CurrentStoreId))
- .ToList();
-
- var gridModel = new DataSourceResult {
- Data = warehouses.Select(w => w.ToModel()),
- Total = warehouses.Count
- };
- return Json(gridModel);
- }
-
- [PermissionAuthorizeAction(PermissionActionName.Create)]
- public async Task<IActionResult> CreateWarehouse()
- {
- var model = new WarehouseModel();
- await PrepareWarehouseModel(model);
- return View(model);
- }
-
- [HttpPost]
- [PermissionAuthorizeAction(PermissionActionName.Create)]
- [Grand.Web.Common.Filters.ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
- public async Task<IActionResult> CreateWarehouse(WarehouseModel model, bool continueEditing)
- {
- if (ModelState.IsValid)
- {
- var warehouse = model.ToEntity();
- warehouse.Address = model.Address.ToEntity();
- warehouse.StoreId = CurrentStoreId;
- await warehouseService.InsertWarehouse(warehouse);
- Success(translationService.GetResource("Admin.Configuration.Shipping.Warehouses.Added"));
- return continueEditing
- ? RedirectToAction("EditWarehouse", new { id = warehouse.Id })
- : RedirectToAction("Warehouses");
- }
- await PrepareWarehouseModel(model);
- return View(model);
- }
-
- [PermissionAuthorizeAction(PermissionActionName.Edit)]
- public async Task<IActionResult> EditWarehouse(string id)
- {
- var warehouse = await warehouseService.GetWarehouseById(id);
- if (warehouse == null || warehouse.StoreId != CurrentStoreId)
- return RedirectToAction("Warehouses");
-
- var model = warehouse.ToModel();
- await PrepareWarehouseModel(model);
- return View(model);
- }
-
- [HttpPost]
- [PermissionAuthorizeAction(PermissionActionName.Edit)]
- [Grand.Web.Common.Filters.ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
- public async Task<IActionResult> EditWarehouse(WarehouseModel model, bool continueEditing)
- {
- var warehouse = await warehouseService.GetWarehouseById(model.Id);
- if (warehouse == null || warehouse.StoreId != CurrentStoreId)
- return RedirectToAction("Warehouses");
-
- if (ModelState.IsValid)
- {
- warehouse = model.ToEntity(warehouse);
- warehouse.Address = model.Address.ToEntity();
- warehouse.StoreId = CurrentStoreId;
- await warehouseService.UpdateWarehouse(warehouse);
- Success(translationService.GetResource("Admin.Configuration.Shipping.Warehouses.Updated"));
- return continueEditing
- ? RedirectToAction("EditWarehouse", new { id = warehouse.Id })
- : RedirectToAction("Warehouses");
- }
- await PrepareWarehouseModel(model);
- return View(model);
- }
-
- [HttpPost]
- [PermissionAuthorizeAction(PermissionActionName.Delete)]
- public async Task<IActionResult> DeleteWarehouse(string id)
- {
- var warehouse = await warehouseService.GetWarehouseById(id);
- if (warehouse == null || warehouse.StoreId != CurrentStoreId)
- return RedirectToAction("Warehouses");
-
- await warehouseService.DeleteWarehouse(warehouse);
- Success(translationService.GetResource("Admin.Configuration.Shipping.Warehouses.Deleted"));
- return RedirectToAction("Warehouses");
- }
-
- #endregion
-
- #region Pickup points
-
- public IActionResult PickupPoints()
- {
- return View();
- }
-
- [HttpPost]
- [PermissionAuthorizeAction(PermissionActionName.List)]
- public async Task<IActionResult> PickupPointsListData()
- {
- var pickupPoints = (await pickupPointService.GetAllPickupPoints(CurrentStoreId))
- .ToList();
-
- var gridModel = new DataSourceResult {
- Data = pickupPoints.Select(p => p.ToModel()),
- Total = pickupPoints.Count
- };
- return Json(gridModel);
- }
-
- [PermissionAuthorizeAction(PermissionActionName.Create)]
- public async Task<IActionResult> CreatePickupPoint()
- {
- var model = new PickupPointModel();
- await PreparePickupPointModel(model);
- return View(model);
- }
-
- [HttpPost]
- [PermissionAuthorizeAction(PermissionActionName.Create)]
- [Grand.Web.Common.Filters.ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
- public async Task<IActionResult> CreatePickupPoint(PickupPointModel model, bool continueEditing)
- {
- if (ModelState.IsValid)
- {
- var pickupPoint = model.ToEntity();
- pickupPoint.StoreId = CurrentStoreId;
- await pickupPointService.InsertPickupPoint(pickupPoint);
- Success(translationService.GetResource("Admin.Configuration.Shipping.PickupPoints.Added"));
- return continueEditing
- ? RedirectToAction("EditPickupPoint", new { id = pickupPoint.Id })
- : RedirectToAction("PickupPoints");
- }
- await PreparePickupPointModel(model);
- return View(model);
- }
-
- [PermissionAuthorizeAction(PermissionActionName.Edit)]
- public async Task<IActionResult> EditPickupPoint(string id)
- {
- var pickupPoint = await pickupPointService.GetPickupPointById(id);
- if (pickupPoint == null || pickupPoint.StoreId != CurrentStoreId)
- return RedirectToAction("PickupPoints");
-
- var model = pickupPoint.ToModel();
- await PreparePickupPointModel(model);
- return View(model);
- }
-
- [HttpPost]
- [PermissionAuthorizeAction(PermissionActionName.Edit)]
- [Grand.Web.Common.Filters.ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
- public async Task<IActionResult> EditPickupPoint(PickupPointModel model, bool continueEditing)
- {
- var pickupPoint = await pickupPointService.GetPickupPointById(model.Id);
- if (pickupPoint == null || pickupPoint.StoreId != CurrentStoreId)
- return RedirectToAction("PickupPoints");
-
- if (ModelState.IsValid)
- {
- pickupPoint = model.ToEntity(pickupPoint);
- pickupPoint.StoreId = CurrentStoreId;
- await pickupPointService.UpdatePickupPoint(pickupPoint);
- Success(translationService.GetResource("Admin.Configuration.Shipping.PickupPoints.Updated"));
- return continueEditing
- ? RedirectToAction("EditPickupPoint", new { id = pickupPoint.Id })
- : RedirectToAction("PickupPoints");
- }
- await PreparePickupPointModel(model);
- return View(model);
- }
-
- [HttpPost]
- [PermissionAuthorizeAction(PermissionActionName.Delete)]
- public async Task<IActionResult> DeletePickupPoint(string id)
- {
- var pickupPoint = await pickupPointService.GetPickupPointById(id);
- if (pickupPoint == null || pickupPoint.StoreId != CurrentStoreId)
- return RedirectToAction("PickupPoints");
-
- await pickupPointService.DeletePickupPoint(pickupPoint);
- Success(translationService.GetResource("Admin.Configuration.Shipping.PickupPoints.Deleted"));
- return RedirectToAction("PickupPoints");
- }
-
- #endregion
-
#region Restrictions
[PermissionAuthorizeAction(PermissionActionName.Preview)]
diff --git a/src/Web/Grand.Web.Store/Controllers/ShippingMethodController.cs b/src/Web/Grand.Web.Store/Controllers/ShippingMethodController.cs
new file mode 100644
index 000000000..7f42d3631
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Controllers/ShippingMethodController.cs
@@ -0,0 +1,60 @@
+using Grand.Business.Core.Interfaces.Checkout.Shipping;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Permissions;
+using Grand.Web.AdminShared.Controllers;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Models.Shipping;
+using Grand.Web.Common.Filters;
+using Grand.Web.Common.Security.Authorization;
+using Grand.Web.Store.Extensions;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Grand.Web.Store.Controllers;
+
+[Area(Constants.AreaStore)]
+[AuthorizeStore]
+[AutoValidateAntiforgeryToken]
+[AuthorizeMenu]
+[PermissionAuthorize(PermissionSystemName.ShippingSettings)]
+[Route("[area]/Shipping/[action]")]
+public class ShippingMethodController(
+ IShippingMethodService shippingMethodService,
+ ILanguageService languageService,
+ IStoreService storeService,
+ ITranslationService translationService,
+ IAdminDataScope<Grand.Domain.Shipping.ShippingMethod> scope)
+ : BaseShippingMethodController(shippingMethodService, languageService, storeService, translationService, scope)
+{
+ [HttpGet]
+ [PermissionAuthorizeAction(PermissionActionName.List)]
+ public IActionResult Methods() => View();
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.List)]
+ public Task<IActionResult> MethodsListData() => ShippingMethodListCore();
+
+ [HttpGet]
+ [PermissionAuthorizeAction(PermissionActionName.Create)]
+ public Task<IActionResult> CreateMethod() => ShippingMethodCreateGetCore();
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.Create)]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public Task<IActionResult> CreateMethod(ShippingMethodModel model, bool continueEditing) =>
+ ShippingMethodCreatePostCore(model, continueEditing);
+
+ [HttpGet]
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ public Task<IActionResult> EditMethod(string id) => ShippingMethodEditGetCore(id);
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public Task<IActionResult> EditMethod(ShippingMethodModel model, bool continueEditing) =>
+ ShippingMethodEditPostCore(model, continueEditing);
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.Delete)]
+ public Task<IActionResult> DeleteMethod(string id) => ShippingMethodDeleteCore(id);
+}
diff --git a/src/Web/Grand.Web.Store/Controllers/WarehouseController.cs b/src/Web/Grand.Web.Store/Controllers/WarehouseController.cs
new file mode 100644
index 000000000..d733e56fa
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Controllers/WarehouseController.cs
@@ -0,0 +1,61 @@
+using Grand.Business.Core.Interfaces.Checkout.Shipping;
+using Grand.Business.Core.Interfaces.Common.Directory;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Domain.Permissions;
+using Grand.Web.AdminShared.Controllers;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Models.Shipping;
+using Grand.Web.Common.Filters;
+using Grand.Web.Common.Security.Authorization;
+using Grand.Web.Store.Extensions;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Grand.Web.Store.Controllers;
+
+[Area(Constants.AreaStore)]
+[AuthorizeStore]
+[AutoValidateAntiforgeryToken]
+[AuthorizeMenu]
+[PermissionAuthorize(PermissionSystemName.ShippingSettings)]
+[Route("[area]/Shipping/[action]")]
+public class WarehouseController(
+ IWarehouseService warehouseService,
+ ICountryService countryService,
+ IStoreService storeService,
+ ITranslationService translationService,
+ IAdminDataScope<Grand.Domain.Shipping.Warehouse> scope)
+ : BaseWarehouseController(warehouseService, countryService, storeService, translationService, scope)
+{
+ [HttpGet]
+ [PermissionAuthorizeAction(PermissionActionName.List)]
+ public IActionResult Warehouses() => View();
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.List)]
+ public Task<IActionResult> WarehousesListData() => WarehouseListCore();
+
+ [HttpGet]
+ [PermissionAuthorizeAction(PermissionActionName.Create)]
+ public Task<IActionResult> CreateWarehouse() => WarehouseCreateGetCore();
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.Create)]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public Task<IActionResult> CreateWarehouse(WarehouseModel model, bool continueEditing) =>
+ WarehouseCreatePostCore(model, continueEditing);
+
+ [HttpGet]
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ public Task<IActionResult> EditWarehouse(string id) => WarehouseEditGetCore(id);
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ public Task<IActionResult> EditWarehouse(WarehouseModel model, bool continueEditing) =>
+ WarehouseEditPostCore(model, continueEditing);
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.Delete)]
+ public Task<IActionResult> DeleteWarehouse(string id) => WarehouseDeleteCore(id);
+}