Skip to content

Commit

Permalink
Admin panel - Product Tier price cannot be deleted once start date an…
Browse files Browse the repository at this point in the history
…d end date is associated #433
  • Loading branch information
support committed Nov 26, 2023
1 parent 7c7545a commit e003984
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion src/Web/Grand.Web.Admin/Controllers/ProductController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,7 @@ public async Task<IActionResult> TierPriceEditPopup(string productId, ProductMod

[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
public async Task<IActionResult> TierPriceDelete(ProductModel.TierPriceModel model)
public async Task<IActionResult> TierPriceDelete(ProductModel.TierPriceDeleteModel model)
{
if (ModelState.IsValid)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Web/Grand.Web.Admin/Models/Catalog/ProductModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,8 @@ public TierPriceModel()

}

public record TierPriceDeleteModel(string Id, string ProductId);

public class ProductWarehouseInventoryModel : BaseModel
{
[GrandResourceDisplayName("Admin.Catalog.Products.ProductWarehouseInventory.Fields.Warehouse")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,25 @@ public TierPriceModelValidator(
}
}
}
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"));
}
}
}
}

0 comments on commit e003984

Please sign in to comment.