I have created a custom Shipping rate provider.
The localization is coming through just fine and I can see and edit my ranges in the BO.
In the BO it looks like this:
The class that defines the behaviour has this definition:
[ShippingRateProvider("OrderShipCategoryShippingRate",
EditorUiAlias = "Umb.PropertyEditorUi.Toggle",
ViewUiAlias = "My.PropertyEditorUi.OrderShipCategoryShippingRateProviderLabel"
)]
public class OrderShipCategoryShippingRateProvider : ShippingRateProvider<int> {
/// initialisation here
public override async Task<Attempt<Price>> TryGetRateAsync(ShippingRateCalculationContext<int> ctx)
{
// the default is zero, meaning free shipping
Price priceAmount = new(0, 0, ctx.Currency);
// stuff happens here
return Attempt<Price>.Succeed(priceAmount);
}
I was immensely impressed that the EditorUIAlias get me define this toggle and it even saves to the shipping method. It displays my message into the range list as well, via my *.element.js script.
All good so far.
But when I modify the order by adding a line such that this rate should be used, all I get is a scripting error in the browser. The adjustment of the order is made by a direct api call to the StorefrontAPI via a POST method that just adds the product to the order.
/umbraco/commerce/storefront/api/v1/order/c4d2xxxxxxb69
with body
{"productReference":"9417xxxxxx1afb42","quantity":1}
This call fails with a 500 response code that is also visible in the log viewer.
An unhandled exception has occurred while executing the request.
System.Text.Json.JsonException: The JSON value could not be converted to System.Int32. Path: $ | LineNumber: 0 | BytePositionInLine: 4.
---> System.InvalidOperationException: Cannot get the value of a token type 'True' as a number.
* some json paths here *
at Umbraco.Commerce.Extensions.OrderStateExtensions.RecalculateWithRepairAsync(OrderState orderState, IOrderCalculator orderCalculator, ILogger`1 logger, OrderReadOnly originalOrder, CancellationToken cancellationToken)
* Lots more lines here *
At the back end it does not reach my custom code for the rate calculation in my custom rate provider.
The code path is starting with the Storefront method AddProductToOrderStorefrontApiController() and eventually gets to the OrderStateExtensions.RecalculateWithRepairAsync()
where it fails with this Json error.
From what I read, my custom provider does not need to be registered as it has the right attribute.
And my Godmode tool shows that it is indeed registered.
The fault lies somewhere in the Calculation but I don’t know where to look now.
Any hints please?
AJ
