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.

Admin panel - Product Tier price cannot be deleted once start date and end date is associated #433

supporte003984379d4
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/Partials/CreateOrUpdate.Prices.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/Partials/CreateOrUpdate.Prices.cshtml
index 4fbcb1515..e9c71e447 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/Partials/CreateOrUpdate.Prices.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/Partials/CreateOrUpdate.Prices.cshtml
@@ -240,6 +240,17 @@
type: "POST",
dataType: "json",
data: addAntiForgeryToken
+ },
+ parameterMap: function (data, operation) {
+ if (operation === "destroy")
+ {
+ return {
+ id: data.Id,
+ productId: data.ProductId,
+ __RequestVerificationToken: data.__RequestVerificationToken
+ };
+ }
+ return data;
}
},
schema: {
diff --git a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs b/src/Web/Grand.Web.Admin/Controllers/ProductController.cs
index bbb414ca9..3ba27e78d 100644
--- a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/ProductController.cs
@@ -1800,7 +1800,7 @@ namespace Grand.Web.Admin.Controllers
[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
- public async Task<IActionResult> TierPriceDelete(ProductModel.TierPriceModel model)
+ public async Task<IActionResult> TierPriceDelete(ProductModel.TierPriceDeleteModel model)
{
if (ModelState.IsValid)
{
diff --git a/src/Web/Grand.Web.Admin/Models/Catalog/ProductModel.cs b/src/Web/Grand.Web.Admin/Models/Catalog/ProductModel.cs
index 4090cb33c..691e4c542 100644
--- a/src/Web/Grand.Web.Admin/Models/Catalog/ProductModel.cs
+++ b/src/Web/Grand.Web.Admin/Models/Catalog/ProductModel.cs
@@ -714,6 +714,8 @@ namespace Grand.Web.Admin.Models.Catalog
}
+ public record TierPriceDeleteModel(string Id, string ProductId);
+
public class ProductWarehouseInventoryModel : BaseModel
{
[GrandResourceDisplayName("Admin.Catalog.Products.ProductWarehouseInventory.Fields.Warehouse")]
diff --git a/src/Web/Grand.Web.Admin/Validators/Catalog/TierPriceModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Catalog/TierPriceModelValidator.cs
index 11ccefe05..d8fb2a6ff 100644
--- a/src/Web/Grand.Web.Admin/Validators/Catalog/TierPriceModelValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Catalog/TierPriceModelValidator.cs
@@ -29,4 +29,25 @@ namespace Grand.Web.Admin.Validators.Catalog
}
}
}
+ public class TierPriceDeleteModelValidator : BaseGrandValidator<ProductModel.TierPriceDeleteModel>
+ {
+ public TierPriceDeleteModelValidator(
+ IEnumerable<IValidatorConsumer<ProductModel.TierPriceDeleteModel>> validators,
+ ITranslationService translationService, IProductService productService, IWorkContext workContext)
+ : base(validators)
+ {
+ if (!string.IsNullOrEmpty(workContext.CurrentCustomer.StaffStoreId))
+ {
+ RuleFor(x => x).MustAsync(async (x, _, _) =>
+ {
+ var product = await productService.GetProductById(x.ProductId);
+ if (product != null)
+ if (!product.AccessToEntityByStore(workContext.CurrentCustomer.StaffStoreId))
+ return false;
+
+ return true;
+ }).WithMessage(translationService.GetResource("Admin.Catalog.Products.Permissions"));
+ }
+ }
+ }
}
\ No newline at end of file