Postcode validation rules - different per country?

  • Posts: 15
  • Thank you received: 2
6 years 4 months ago #281448

Hi,

We have added a postcode validation regex rule to help ensure postcodes are entered correctly, but the occasional order from users outside our country encounter issues with this as their postcodes follow a different format.

Is there a way to define different postcode validation rules per country? Alternatively could we limit the postcode regex to a single country and allow all other countries to enter without validation?

Thanks!

Please Log in or Create an account to join the conversation.

  • Posts: 81378
  • Thank you received: 13037
  • MODERATOR
6 years 4 months ago #281452

Hi,

There is no such mechanism. I would recommend not restricting the post code to any ruler as a simple solution because it can vary greatly from one country to the other.
If you really need to add custom rules varying based on the country, I would recommend developing a small HikaShop plugin implementing the "onBeforeAddressCreate" and "onBeforeAddressUpdate" triggers where you'll be able to check for the validity of the post code based on the country selected.
www.hikashop.com/support/documentation/6...ntation.html#address
If you're a developer, it should not be a problem. Otherwise, you can always contact our partners for such development.
www.hikashop.com/home/our-partners.html

Please Log in or Create an account to join the conversation.

  • Posts: 15
  • Thank you received: 2
5 years 11 months ago #291258

This was really useful and we successfully implemented this approach (using `onBeforeAddressUpdate` and `onBeforeAddressCreate` to capture the country and postcode on form submit, to apply country specific postcode validation). We were using legacy checkout and used `JError::raiseWarning` to return an error to the user if the postcode didn’t pass validation. All worked well.

We are now in the process of moving away from the legacy checkout to the newer code, and are struggling to output our custom postcode validation error messages.

Looking at the documentation we can't see a way to do this in the address API. However, the shipping API (for example) looks like it has a `$messages` variable available to send info back. Is there something like this for the address API which we have somehow missed?

FYI we are currently using Hikashop 3.2 Business Edition, but are looking to upgrade to 3.4 soon.

Thanks again.

Please Log in or Create an account to join the conversation.

  • Posts: 81378
  • Thank you received: 13037
  • MODERATOR
5 years 11 months ago #291260

Hi,

There were issues with error messages not displaying properly in some cases with the new checkout.
So upgrading is a good idea.
But I'm not sure it will help.
I've looked a the code of the new checkout for that particular area, and I think it's missing some code if we want to handle the display of messages added by 3rd party plugins.
For that, we'll need to add that code:
monosnap.com/file/tUNMX47HcLj9Q7XIuBqA4V8lfFVpx5
in the file administrator/components/com_hikashop/helpers/checkout/address.php
Let us know how that goes for you with these modifications so that we can push that for the next version of HikaShop.

Please Log in or Create an account to join the conversation.

  • Posts: 15
  • Thank you received: 2
5 years 11 months ago #291318

Hi Nicolas,

Thanks for your kind reply. The change you gave for file administrator/components/com_hikashop/helpers/checkout/address.php has worked well.

It would be great these changes were included in next version of Hikashop as you suggested.

Thanks again for your support!

Please Log in or Create an account to join the conversation.

  • Posts: 81378
  • Thank you received: 13037
  • MODERATOR
5 years 11 months ago #291319

Hi,

Thanks, we'll do that !

Please Log in or Create an account to join the conversation.

Time to create page: 0.068 seconds
Powered by Kunena Forum