Skip to content

Commit e4c3147

Browse files
authored
Merge pull request #115 from JerrySmidt/master
3.6.2
2 parents 6227c9a + 38121d0 commit e4c3147

File tree

5 files changed

+62
-5
lines changed

5 files changed

+62
-5
lines changed

Model/Validator/City.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22

33
namespace Flekto\Postcode\Model\Validator;
44

5+
use Magento\Customer\Model\Customer;
6+
use Magento\Framework\Validator\AbstractValidator;
7+
58
/**
69
* Customer city fields validator.
710
*/
8-
class City extends \Magento\Customer\Model\Validator\City
11+
class City extends AbstractValidator
912
{
1013
/**
1114
* Validate city fields.
1215
*
1316
* Adopt pattern from Magento release 2.4.9-alpha3 to fix city validation.
17+
*
1418
* @see https://github.com/magento/magento2/issues/39854
1519
*
1620
* @param Customer $customer
@@ -23,7 +27,7 @@ public function isValid($customer): bool
2327
return true;
2428
}
2529

26-
if (preg_match( '/^[\p{L}\p{M}\d\s\-_\'’\.,&\(\)]{1,100}$/u', $city, $matches)) {
30+
if (preg_match('/^[\p{L}\p{M}\d\s\-_\'’\.,&\(\)]{1,100}$/u', $city, $matches)) {
2731
if ($matches[0] === $city) {
2832
return true;
2933
}

Plugin/ValidatorPlugin.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Flekto\Postcode\Plugin;
4+
5+
use Magento\Framework\Validator;
6+
use Magento\Framework\Validator\ValidatorInterface;
7+
use Magento\Framework\App\ProductMetadataInterface;
8+
9+
/**
10+
* Validator plugin to fix city validation in Magento 2.4.8.
11+
*/
12+
class ValidatorPlugin
13+
{
14+
private $_productMetadata;
15+
16+
/**
17+
* Constructor
18+
*
19+
* @param ProductMetadataInterface $productMetadata
20+
*/
21+
public function __construct(ProductMetadataInterface $productMetadata)
22+
{
23+
$this->_productMetadata = $productMetadata;
24+
}
25+
26+
/**
27+
* Before plugin for the addValidator method
28+
*
29+
* @param Validator $subject
30+
* @param ValidatorInterface $validator
31+
* @param boolean $breakChainOnFailure
32+
* @return array|null
33+
*/
34+
public function beforeAddValidator(
35+
Validator $subject,
36+
ValidatorInterface $validator,
37+
bool $breakChainOnFailure = false
38+
): ?array {
39+
if (substr($this->_productMetadata->getVersion(), 0, 5) === '2.4.8'
40+
&& method_exists($validator, 'getAlias')
41+
&& $validator->getAlias() === 'city_validator'
42+
) {
43+
return [new \Flekto\Postcode\Model\Validator\City(), $breakChainOnFailure];
44+
}
45+
46+
// Return null if not changing arguments, see
47+
// https://developer.adobe.com/commerce/php/development/components/plugins/#before-methods
48+
return null;
49+
}
50+
}

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.1",
3+
"version": "3.6.2",
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.1</module_version>
6+
<module_version>3.6.2</module_version>
77
<account_status>new</account_status>
88
</status>
99
<general>

etc/di.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
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" />
8+
9+
<type name="Magento\Framework\Validator">
10+
<plugin name="flekto_postcode_city_validation" type="Flekto\Postcode\Plugin\ValidatorPlugin"/>
11+
</type>
912

1013
<type name="Magento\Framework\App\AreaList">
1114
<arguments>

0 commit comments

Comments
 (0)