Skip to content

Commit c80da47

Browse files
author
Mohan Ahuja
committed
ACP2E-1001: Customer Zip Code input validation rule not working
- Fixing build failures.
1 parent b33aab9 commit c80da47

File tree

3 files changed

+7
-78
lines changed

3 files changed

+7
-78
lines changed

app/code/Magento/Customer/Model/Metadata/Form/Postcode.php

Lines changed: 5 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
namespace Magento\Customer\Model\Metadata\Form;
77

88
use Magento\Customer\Api\Data\AttributeMetadataInterface;
9-
use Magento\Customer\Model\Metadata\ElementFactory;
109
use Magento\Directory\Helper\Data as DirectoryHelper;
11-
use Magento\Framework\Api\ArrayObjectSearch;
1210
use Magento\Framework\Stdlib\StringUtils;
1311
use Magento\Framework\Locale\ResolverInterface;
1412
use Psr\Log\LoggerInterface as PsrLogger;
@@ -17,12 +15,12 @@
1715
/**
1816
* Customer Address Postal/Zip Code Attribute Data Model
1917
*/
20-
class Postcode extends AbstractData
18+
class Postcode extends Text
2119
{
2220
/**
2321
* @var DirectoryHelper
2422
*/
25-
protected $directoryHelper;
23+
protected DirectoryHelper $directoryHelper;
2624

2725
/**
2826
* @var StringUtils
@@ -52,7 +50,7 @@ public function __construct(
5250
StringUtils $stringHelper = null
5351
) {
5452
$this->directoryHelper = $directoryHelper;
55-
if (is_null($stringHelper)) {
53+
if ($stringHelper === null) {
5654
$stringHelper = \Magento\Framework\App\ObjectManager::getInstance()->get(StringUtils::class);
5755
}
5856
$this->_string = $stringHelper;
@@ -63,7 +61,8 @@ public function __construct(
6361
$localeResolver,
6462
$value,
6563
$entityTypeCode,
66-
$isAjax
64+
$isAjax,
65+
$stringHelper
6766
);
6867
}
6968

@@ -102,74 +101,4 @@ public function validateValue($value)
102101
}
103102
return $errors;
104103
}
105-
106-
/**
107-
* @inheritdoc
108-
*/
109-
public function extractValue(\Magento\Framework\App\RequestInterface $request)
110-
{
111-
return $this->_applyInputFilter($this->_getRequestValue($request));
112-
}
113-
114-
/**
115-
* @inheritdoc
116-
*/
117-
public function compactValue($value)
118-
{
119-
return $value;
120-
}
121-
122-
/**
123-
* @inheritdoc
124-
*/
125-
public function restoreValue($value)
126-
{
127-
return $this->compactValue($value);
128-
}
129-
130-
/**
131-
* @inheritdoc
132-
*/
133-
public function outputValue($format = ElementFactory::OUTPUT_FORMAT_TEXT)
134-
{
135-
return $this->_applyOutputFilter($this->_value);
136-
}
137-
138-
/**
139-
* Length validation
140-
*
141-
* @param mixed $value
142-
* @param AttributeMetadataInterface $attribute
143-
* @param array $errors
144-
* @return array
145-
*/
146-
private function validateLength($value, AttributeMetadataInterface $attribute, array $errors): array
147-
{
148-
// validate length
149-
$label = __($attribute->getStoreLabel());
150-
151-
$length = $value ? $this->_string->strlen(trim($value)) : 0;
152-
153-
$validateRules = $attribute->getValidationRules();
154-
155-
if (!empty(ArrayObjectSearch::getArrayElementByName($validateRules, 'input_validation'))) {
156-
$minTextLength = ArrayObjectSearch::getArrayElementByName(
157-
$validateRules,
158-
'min_text_length'
159-
);
160-
if ($minTextLength !== null && $length < $minTextLength) {
161-
$errors[] = __('"%1" length must be equal or greater than %2 characters.', $label, $minTextLength);
162-
}
163-
164-
$maxTextLength = ArrayObjectSearch::getArrayElementByName(
165-
$validateRules,
166-
'max_text_length'
167-
);
168-
if ($maxTextLength !== null && $length > $maxTextLength) {
169-
$errors[] = __('"%1" length must be equal or less than %2 characters.', $label, $maxTextLength);
170-
}
171-
}
172-
173-
return $errors;
174-
}
175104
}

app/code/Magento/Customer/Model/Metadata/Form/Text.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function outputValue($format = \Magento\Customer\Model\Metadata\ElementFa
119119
* @param array $errors
120120
* @return array
121121
*/
122-
private function validateLength($value, AttributeMetadataInterface $attribute, array $errors): array
122+
protected function validateLength($value, AttributeMetadataInterface $attribute, array $errors): array
123123
{
124124
// validate length
125125
$label = __($attribute->getStoreLabel());

app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/PostcodeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected function getClass($value)
5858
public function testValidateValue($value, $expected, $countryId, $isOptional)
5959
{
6060
$storeLabel = 'Zip/Postal Code';
61-
$this->attributeMetadataMock->expects($this->once())
61+
$this->attributeMetadataMock->expects($this->exactly(2))
6262
->method('getStoreLabel')
6363
->willReturn($storeLabel);
6464

0 commit comments

Comments
 (0)