Decimal Validation Issue in nopCommerce 4.70

3 weeks ago
Hello,

I am experiencing an issue with decimal validation in nopCommerce 4.70. Specifically, when trying to add or modify store pickup points with latitude and longitude values, the validation fails with both dot and comma as decimal separators.

My environment:
- nopCommerce version: 4.70
- SQL collation: SQL_Hungarian_CP1250_CI_AS
- Culture settings: en-US and hu-HU

Here is a snippet of the validator I am using:

```csharp
using FluentValidation;
using Nop.Plugin.Pickup.PickupInStore.Models;
using Nop.Services.Localization;
using Nop.Web.Framework.Validators;

namespace Nop.Plugin.Pickup.PickupInStore.Validators
{
    public class StorePickupPointValidator : BaseNopValidator<StorePickupPointModel>
    {
        public StorePickupPointValidator(ILocalizationService localizationService)
        {
            // Latitude
            RuleFor(model => model.Latitude)
                .InclusiveBetween(-90, 90)
                .WithMessageAwait(localizationService.GetResourceAsync("Plugins.Pickup.PickupInStore.Fields.Latitude.InvalidRange"))
                .When(model => model.Latitude.HasValue);
            RuleFor(model => model.Latitude)
                .Must(latitude => latitude.HasValue)
                .WithMessageAwait(localizationService.GetResourceAsync("Plugins.Pickup.PickupInStore.Fields.Latitude.IsNullWhenLongitudeHasValue"))
                .When(model => model.Longitude.HasValue);
            RuleFor(model => model.Latitude)
                .ScalePrecision(8, 18)
                .WithMessageAwait(localizationService.GetResourceAsync("Plugins.Pickup.PickupInStore.Fields.Latitude.InvalidPrecision"));

            // Longitude
            RuleFor(model => model.Longitude)
                .InclusiveBetween(-180, 180)
                .WithMessageAwait(localizationService.GetResourceAsync("Plugins.Pickup.PickupInStore.Fields.Longitude.InvalidRange"))
                .When(model => model.Longitude.HasValue);
            RuleFor(model => model.Longitude)
                .Must(longitude => longitude.HasValue)
                .WithMessageAwait(localizationService.GetResourceAsync("Plugins.Pickup.PickupInStore.Fields.Longitude.IsNullWhenLatitudeHasValue"))
                .When(model => model.Latitude.HasValue);
            RuleFor(model => model.Longitude)
                .ScalePrecision(8, 18)
                .WithMessageAwait(localizationService.GetResourceAsync("Plugins.Pickup.PickupInStore.Fields.Longitude.InvalidPrecision"));
        }
    }
}

Has anyone else encountered this issue? Any help would be appreciated!

Thank you.
3 weeks ago
I couldn't reproduce the issue. Even when I try to change the browser locale everything works fine.
But due to the server side implementation these fields are rendered as text and validation works with server locale (it's . for en-us in my case).
3 weeks ago
Hello Alexey,

Thank you for your response and for attempting to reproduce the issue.

The problem I am experiencing is specifically related to the PickupInStore module, particularly with the Latitude and Longitude fields. Here are the details:

    Locale Settings:
        My server locale is set to SQL_Hungarian_CP1250_CI_AS.
        The application locale is set to Hungarian (hu-HU).

    Issue Specifics:
        When using the Hungarian language, the Latitude and Longitude fields in the PickupInStore module do not accept decimal values correctly.
        The decimal separator in Hungarian locale is a comma (,), but the validation expects a period (.), which causes validation failures specifically for these fields.

    Behavior:
        Switching the application language to English (en-US) resolves the issue, and the Latitude and Longitude inputs validate as expected.
        Switching back to Hungarian reintroduces the problem only for these specific fields.

    Reproduction Steps:
        Set the application language to Hungarian.
        Navigate to the PickupInStore configuration.
        Attempt to input decimal values for Latitude and Longitude.
        Observe that the validation fails due to the expected decimal separator being a period instead of a comma.

    Additional Context:
        This issue did not occur in version 4.60.5 with the same server settings.
        The problem started appearing from version 4.70.0 onwards.
        Other decimal fields in different parts of the application do not exhibit this issue; it seems to be isolated to the PickupInStore Latitude and Longitude fields.

Given these details, it seems like the validation for these specific fields might still be using the server locale (en-us) rather than the application locale (hu-HU) when rendering and validating these fields. This discrepancy might be causing the validation issues with decimal inputs in the Hungarian language.

Could you please provide guidance on how to ensure that the PickupInStore module respects the Hungarian locale settings for decimal input validation without modifying the core nopCommerce settings? Any advice or direction would be greatly appreciated.

Thank you for your assistance.

Best regards,
Richard
2 weeks ago
Hi! We've created a task. This fix will be provided in the next minor release. Thanks!
2 weeks ago
Hi!
I greatly appreciate your help and quick feedback! Thank you for working on the solution, and I look forward to the next minor release.

Regards, Richard