Separate house number and house number extension from address

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
Hi,

In The Netherlands and maybe also other countries there are about 20 houses per zippostalcode. The streetnames are known by zippostalcode and housenumber combination. Secondly, credit checks go on zippostalcode and housenumber.'

It would be nice to have streetname, housenumber and housenumber extension in separate fields instead in address1. This allows the usage of a webservice to lookup the streetname and fill it in once the user enters the zipcode and the housenumber. This will fasten the checkout and avoid errors. In a later stage the separated fields can also easier be used to do a credit check.

For the moment I have implemented to circumvent this problem:


[NonAction]
        public void PrepareAddress(LeaseCustomer leaseCustomer, string streetName)
        {

            if (!string.IsNullOrEmpty(streetName))
            {
                Match m = Regex.Match(streetName, @"(.*)?[ ](\d+)(.*)?");
                if (m.Success)
                {
                    leaseCustomer.StreetName = m.Groups[1].Value.Trim();
                    leaseCustomer.HouseNumber = m.Groups[2].Value.Trim();
                    leaseCustomer.HouseNumberExtension = m.Groups[3].Value.Trim();

                    return;
                }
            }

            leaseCustomer.StreetName = streetName;
            leaseCustomer.HouseNumber = string.Empty;
            leaseCustomer.HouseNumberExtension = string.Empty;
        }


J.
9 years ago
Hi,

Is it possible to add a separate housenumber field and housenumber extension field to NOP? I can do customize it, but I believe it is a generic issue.

In particular if you want an online web service to validate the address you first have to extract what can be a valid street, housenumber and extension...

J.
9 years ago
Hi,

Thanks for info. These fields won't be added to the core solution. But as you may know we already have "Custom customer attributes" supported (demo here) I've just created a work item to support the same for address fields. Please vote here. This way you can easily ANY custom fields
9 years ago
a.m. wrote:
Hi,

Thanks for info. These fields won't be added to the core solution. But as you may know we already have "Custom customer attributes" supported (demo here) I've just created a work item to support the same for address fields. Please vote here. This way you can easily ANY custom fields

One think that is missing is how the display order of the attributes will intermix with default fiedls ('Gender', 'Date of Birth', 'Company', etc.)
9 years ago
Hi,
With customized fields you will miss the integration of address information in emails, pdf's etc. It is not only data storage, the fields also have a particular function.
J.
9 years ago
Quantis001 wrote:
Hi,
With customized fields you will miss the integration of address information in emails, pdf's etc. It is not only data storage, the fields also have a particular function.
J.

Hi J.,

It also can be done with custom address fields. Why not?
9 years ago
Hi,

A separate field will help query out the database for marketing purposes and not require validation logic like next.

Work around created with next code on validators in common and in customer. Admin has also some validation logic.


if (customerSettings.StreetAddressRequired && customerSettings.StreetAddressEnabled)
            {
                RuleFor(x => x.StreetAddress).NotEmpty().WithMessage(localizationService.GetResource("Account.Fields.StreetAddress.Required"));
                //BEGIN QE: 20141008: Workitem 854
                RuleFor(x => x.StreetAddress).Must(Nop.Web.Framework.QE.Validators.AddressValidatorQE.MustContainHouseNumber).WithMessage(localizationService.GetResource("Nop.Web.Framework.QE.Validators.Account.Fields.HouseNumber.Required"));
                //END QE: 20141008: Workitem 854
            }


Code for validators:

namespace Nop.Web.Framework.QE.Validators
{
    public static class AddressValidatorQE
    {
        public static bool MustContainHouseNumber(string value)
        {
            return MustMatchPattern(value, @"\d+$");
        }
        public static bool MustMatchPattern(string value, string pattern)
        {
            if (string.IsNullOrEmpty(value))
                return false;

            Regex regex = new Regex(pattern);

            return regex.IsMatch(value);

        }
    }
}


Language resource which can be loaded through Language Import functionality.


<?xml version="1.0" encoding="utf-8"?>
<Language Name="Nederlands">
  <LocaleResource Name="Nop.Web.Framework.QE.Validators.Account.Fields.HouseNumber.Required">
    <Value>Huisnummer ontbreekt</Value>
  </LocaleResource>
</Language>


Tests (with VS unit test)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Nop.Core.Domain.Common;
using Nop.Web.Models.Common;
using Nop.Web.MVC.Tests.Public.Validators;
using Nop.Web.Validators.Common;
using FluentValidation.TestHelper;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Nop.Web.Framework.QE.Tests.Public.Validators.Common
{
    [TestClass]    
    public class AddressValidatorTests : BaseValidatorTests
    {
        [TestMethod]
        public void Should_have_error_when_streetaddress_has_no_housenumber()
        {
            var model = new AddressModel();

            //required
            var validator = new AddressValidator(_localizationService,
                new AddressSettings()
                {
                    StreetAddressEnabled = true,
                    StreetAddressRequired = true
                });
            model.Address1 = "Street address";
            validator.ShouldHaveValidationErrorFor(x => x.Address1, model);

            //not required
            validator = new AddressValidator(_localizationService,
                new AddressSettings()
                {
                    StreetAddressEnabled = true,
                    StreetAddressRequired = false
                });
            model.Address1 = "Street address";
            validator.ShouldNotHaveValidationErrorFor(x => x.Address1, model);
        }
        [TestMethod]
        public void Should_not_have_error_when_streetaddress_has_housenumber()
        {
            var validator = new AddressValidator(_localizationService,
                new AddressSettings()
                {
                    StreetAddressEnabled = true
                });

            var model = new AddressModel();
            model.Address1 = "Street address 41";
            validator.ShouldNotHaveValidationErrorFor(x => x.Address1, model);
        }
    }
}
9 years ago
a.m. wrote:
Hi,

Thanks for info. These fields won't be added to the core solution. But as you may know we already have "Custom customer attributes" supported (demo here). I've just created a work item to support the same for address fields. Please vote here. This way you can easily ANY custom fields

And here we go. Done. Please see changeset 51b168e5e129
9 years ago
a.m. wrote:
Hi,
And here we go. Done. Please see changeset 51b168e5e129


This feature addition is great Andrei. I am sure this will be useful to a lot of store owners!!!
9 years ago
a.m. wrote:
And here we go. Done. Please see changeset 51b168e5e129


Thanks Andrei.
Can we have a work item to make custom fields configurable as to whether they are only visible in admin?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.