I need to add more validations to the addresses, I don't want to change the original code.
Is there a way to do this with a plugin?
I tried to implement this but only the rules that are translated to the client side work.
If I try to create a custom validation, the validation is ignored.
public class AddressValidator : BaseNopValidator<AddressModel>
{
public AddressValidator(ILocalizationService localizationService,
IStateProvinceService stateProvinceService,
AddressSettings addressSettings,
CustomerSettings customerSettings)
{
//This Works
RuleFor(model => model.Address2)
.NotEmpty()
.WithMessage("Error");
//This Works
RuleFor(model => model.Address2).MinimumLength(2)
.WithMessage("Error");
//This does not work
RuleFor(model => model.Address2).Custom((x, context) =>
{
if (x == "Test")
{
context.AddFailure("Error");
}
});
}
}