Custom Rounding of Order Total
Tags:
A new method has been added to the API V7, IOperationService.RegisterCustomRoundingHandler, which allows you to register a handler for applying rounding to the order on the front end.
Example usage:
var toDispose = PluginContext.Operations.RegisterCustomRoundingHandler(order =>
{
// You can come up with some other rounding, for example, to round to the nearest ten cents, or to ensure the total is always a multiple of 5.
// https://docs.microsoft.com/en-us/dotnet/api/system.math.round?view=netframework-4.7.2
// Always discard the cent.
int roundedResultSum = (int)order.ResultSum;
decimal roundSum = roundedResultSum - order.ResultSum;
return roundSum;
});
If the returned rounding amount is 0, no rounding should be applied.
If any exception is thrown in the handler, the rounding configured in the back end will be applied.