Skip to content

Commit 6227c9a

Browse files
authored
Merge pull request #114 from JerrySmidt/master
3.6.1
2 parents 7858258 + 567b07b commit 6227c9a

File tree

8 files changed

+76
-17
lines changed

8 files changed

+76
-17
lines changed

Helper/ApiClientHelper.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,20 @@ public function getNlAddress(string $zipCode, string $houseNumber): array
339339
];
340340
}
341341

342+
$streetParts = [
343+
$address['street'],
344+
$address['houseNumber'],
345+
$address['houseNumberAddition'] ?? '',
346+
];
347+
348+
if ($this->_storeConfigHelper->isSetFlag('split_street_values')) {
349+
$lastLineIndex = $this->_addressHelper->getStreetLines() - 1;
350+
$address['streetLines'] = array_slice($streetParts, 0, $lastLineIndex);
351+
$address['streetLines'][] = implode(' ', array_slice($streetParts, $lastLineIndex));
352+
} else {
353+
$address['streetLines'] = [rtrim(implode(' ', $streetParts))];
354+
}
355+
342356
$result = ['address' => $address, 'status' => $status];
343357

344358
return $this->_prepareResponse($result, $client);

Model/Validator/City.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Flekto\Postcode\Model\Validator;
4+
5+
/**
6+
* Customer city fields validator.
7+
*/
8+
class City extends \Magento\Customer\Model\Validator\City
9+
{
10+
/**
11+
* Validate city fields.
12+
*
13+
* Adopt pattern from Magento release 2.4.9-alpha3 to fix city validation.
14+
* @see https://github.com/magento/magento2/issues/39854
15+
*
16+
* @param Customer $customer
17+
* @return bool
18+
*/
19+
public function isValid($customer): bool
20+
{
21+
$city = $customer->getCity();
22+
if ($city === null) {
23+
return true;
24+
}
25+
26+
if (preg_match( '/^[\p{L}\p{M}\d\s\-_\'’\.,&\(\)]{1,100}$/u', $city, $matches)) {
27+
if ($matches[0] === $city) {
28+
return true;
29+
}
30+
}
31+
32+
parent::_addMessages([[
33+
'city' => "Invalid City. Please use letters, numbers, spaces,
34+
and the following characters: - _ ' ’ . , & ( )"
35+
]]);
36+
37+
return false;
38+
}
39+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcode-nl/api-magento2-module",
3-
"version": "3.6.0",
3+
"version": "3.6.1",
44
"description": "Postcode.eu International Address API module for Magento 2. Adds autocompletion for addresses in multiple countries using official postal data.",
55
"require": {
66
"php": "^7.4 || ^8.0 || ^8.1 || ^8.2 || ^8.3 || ^8.4",

etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<default>
44
<postcodenl_api>
55
<status>
6-
<module_version>3.6.0</module_version>
6+
<module_version>3.6.1</module_version>
77
<account_status>new</account_status>
88
</status>
99
<general>

etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<preference for="Flekto\Postcode\Api\UpdateNotificationRepositoryInterface" type="Flekto\Postcode\Model\UpdateNotificationRepository" />
66
<preference for="Magento\Framework\Filesystem\DriverInterface" type="Magento\Framework\Filesystem\Driver\File" />
77
<preference for="Magento\Checkout\Block\Checkout\AttributeMerger" type="Flekto\Postcode\Block\Checkout\AttributeMerger" />
8+
<preference for="Magento\Customer\Model\Validator\City" type="Flekto\Postcode\Model\Validator\City" />
89

910
<type name="Magento\Framework\App\AreaList">
1011
<arguments>

view/frontend/web/js/form/components/checkout/address-autofill-nl.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,22 @@ define([
6464
setInputAddress: function (address) {
6565
const addressParts = this.getAddressParts(address);
6666

67-
if (this.settings.split_street_values) {
68-
// Street children may not yet be available at this point, so value needs to be set asynchronously.
69-
this.street().asyncSetValues(
67+
// Result could be an old address from localStorage, without streetLines.
68+
if (typeof addressParts.streetLines === 'undefined') {
69+
addressParts.streetLines = [
7070
addressParts.street,
7171
addressParts.houseNumber,
72-
addressParts.houseNumberAddition
73-
);
74-
} else {
75-
this.street().asyncSetValues(`${addressParts.street} ${addressParts.house}`);
72+
addressParts.houseNumberAddition,
73+
];
74+
75+
if (!this.settings.split_street_values) {
76+
addressParts.streetLines = [addressParts.streetLines.join(' ')];
77+
}
7678
}
7779

80+
// Street children may not yet be available at this point, so value needs to be set asynchronously.
81+
this.street().asyncSetValues(...addressParts.streetLines);
82+
7883
this.city().value(addressParts.city);
7984
this.postcode().value(addressParts.postcode);
8085

view/frontend/web/js/form/components/customer/address/address-autofill-nl.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ define([
123123
setInputAddress: function (address) {
124124
const addressParts = this.getAddressParts(address);
125125

126-
this.inputs.street[0].value = addressParts.street + ' ' + addressParts.house;
126+
for (let i = 0; i < address.streetLines.length; i++) {
127+
this.inputs.street[i].value = address.streetLines[i];
128+
}
129+
127130
this.inputs.city.value = addressParts.city;
128131
this.inputs.postcode.value = addressParts.postcode;
129132

view/frontend/web/js/form/element/checkout/address-autofill-intl.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,13 @@ define([
9292
switch (this.settings.show_hide_address_fields) {
9393
case 'disable':
9494
for (const field of ['street', 'city', 'postcode', 'regionId', 'regionIdInput']) {
95-
this[field](component => component.disabled(!state));
95+
this[field](component => component.disabled(!state)); // eslint-disable-line no-loop-func
9696
}
9797
break;
9898
case 'format':
99-
if (!force) {
100-
for (const field of ['street', 'city', 'postcode']) {
101-
this[field](component => component.visible(false));
102-
}
103-
}
104-
break;
99+
state = force && state; // Always hide fields unless forced otherwise.
100+
101+
/* falls through */
105102
case 'hide':
106103
for (const field of ['street', 'city', 'postcode']) {
107104
this[field](component => component.visible(state));

0 commit comments

Comments
 (0)