Developer forum

Forum » Development » AddInParameter reads double value wrong in our CustomShippingProvider

AddInParameter reads double value wrong in our CustomShippingProvider

Hans Kloppenborg
Reply

Hi,

We have a Custom shipping provider, with AddInParameters of type double, using the FloatingPointNumberParameterEditor.

As long as the inpunt in these fields is a nice round number, everything works fine. But now our client changed the value 6.00 to 6.95, and depending on the chosen language of the frontend we get either 6.95 (correct) in English, or 695.00 in the dutch language. 

It looks like the value of the addinparameter gets deserialized from the xml field in the database using the number format of the culture of the site language the visitor is viewing. 

We will try to find a work around/hack to fix this, but I would think this should work correctly indepent of the chosen frontend layer.

Greets Hans


Replies

 
Hans Kloppenborg
Reply

Okay,

Issue is even worse as I thought, seems the French language does not use a decimal point at all in their numbers, and for that language numbers with a decimal point in them are returned as a zero value. 

Was hoping to get away with a hack checking if the value of the shipping costs was higher as normally possible and dividing by 100, but for zero values that is no solution.

Greets Hans

 
Hans Kloppenborg
Reply

For those having the same issue, we solved/hacked it by setting invariantculture in the before observer, and restoring the correct culture using the order language at the end of the shipping provider. 

using Dynamicweb.Ecommerce.Notifications;
using Dynamicweb.Extensibility.Notifications;
using NLog;
 
namespace Application.CustomCode.Observers
{
    [Subscribe(Ecommerce.Order.BeforeShippingFeeCalculation)]
    public class BeforeShippingFeeCalculation : NotificationSubscriber
    {
        private static readonly Logger _logger = LogManager.GetLogger("Application.CustomCode.Observers.BeforeShippingFeeCalculation");
 
        public override void OnNotify(string notificationNotificationArgs args)
        {
            if (!Dynamicweb.Environment.ExecutingContext.IsFrontEnd()) return;
 
            var beforeArgs = args as Ecommerce.Order.BeforeShippingFeeCalculationArgs;
 
            var order = beforeArgs.Order;
 
            if (order.Complete) return//do not check/change completed orders
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
        }
    }
}

 

You must be logged in to post in the forum