Skip to content

Commit 4619db8

Browse files
committed
Feature #53438: fix street line formatting
1 parent 9e6aacd commit 4619db8

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

assets/js/postcode-eu-autofill.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,20 +484,33 @@
484484
{
485485
province = PostcodeNlStateToValueMapping.CHE[result.details.cheCanton.name];
486486
}
487+
487488
fillAddressFields(addressFields, new Map([
488489
[PostcodeNlAddressFieldMapping.street, address.street],
489490
[PostcodeNlAddressFieldMapping.houseNumber, address.buildingNumber || ''],
490491
[PostcodeNlAddressFieldMapping.houseNumberAddition, address.buildingNumberAddition || ''],
491492
[PostcodeNlAddressFieldMapping.postcode, address.postcode],
492493
[PostcodeNlAddressFieldMapping.city, address.locality],
493-
[PostcodeNlAddressFieldMapping.streetAndHouseNumber, (address.street + ' ' + address.building).trim()],
494+
[
495+
PostcodeNlAddressFieldMapping.streetAndHouseNumber,
496+
formatStreetLine(result.country.iso2Code, address.street, address.building)
497+
],
494498
[PostcodeNlAddressFieldMapping.houseNumberAndAddition, address.building],
495499
[PostcodeNlAddressFieldMapping.province, province],
496500
]));
497501

498502
$(document.body).trigger('update_checkout');
499503
}
500504

505+
// Correctly format street and building line for countries that use reversed order.
506+
const formatStreetLine = (countryIso2, street, building) => {
507+
let a = street, b = building;
508+
if (settings.reverseStreetLineCountries.includes(countryIso2))
509+
[a, b] = [b, a];
510+
511+
return `${a} ${b}`.trim();
512+
}
513+
501514
// Get a prefilled address value from the intl field.
502515
// If missing, try to construct a value from the address fields.
503516
const getPrefilledAddressValue = () => {

src/PostcodeNl/AddressAutocomplete/Main.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ public function getSettings(): array
279279
'houseNumberPlaceholder' => '123 A',
280280
'autofillIntlBypassLinkText' => esc_html__('Enter an address', 'postcode-eu-address-validation'),
281281
'allowAutofillIntlBypass' => $this->_options->allowAutofillIntlBypass,
282+
'reverseStreetLineCountries' => ['LU', 'FR', 'GB', 'IE', 'IT', 'PT'],
282283
];
283284
}
284285

src/components/address-autocomplete-intl/autocomplete-input.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ const settings = getSetting('postcode-eu-address-validation_data');
99

1010
const isSupportedCountry = (countryIso2) => typeof settings.enabledCountries[countryIso2] !== 'undefined';
1111

12+
// Correctly format street and building line for countries that use reversed order.
13+
const formatStreetLine = (countryIso2, street, building) => {
14+
let a = street, b = building;
15+
if (settings.reverseStreetLineCountries.includes(countryIso2))
16+
[a, b] = [b, a];
17+
18+
return `${a} ${b}`.trim();
19+
}
20+
1221
PostcodeNl.addressDetailsCache ??= new Map();
1322

1423
function initAutocomplete (inputElement, countryIso3)
@@ -112,7 +121,7 @@ const AutocompleteInput = ({id, addressType, address, setAddress, setAddressDeta
112121
const { locality, street, postcode, building } = result.address;
113122
setAddress({
114123
...addressRef.current,
115-
address_1: `${street} ${building}`,
124+
address_1: formatStreetLine(result.country.iso2Code, street, building),
116125
city: locality,
117126
postcode: postcode,
118127
});

0 commit comments

Comments
 (0)