Skip to content

Commit 8529906

Browse files
author
Aleksandr Osadchyi
committed
Merge remote-tracking branch 'origin/MAGETWO-61725' into BUGS
2 parents 15ca98f + 8f47b35 commit 8529906

File tree

4 files changed

+39
-237
lines changed

4 files changed

+39
-237
lines changed

app/code/Magento/Customer/Model/Address/AbstractAddress.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ public function getDataModel($defaultBillingAddressId = null, $defaultShippingAd
554554
/**
555555
* Validate address attribute values
556556
*
557+
*
558+
*
557559
* @return bool|array
558560
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
559561
* @SuppressWarnings(PHPMD.NPathComplexity)
@@ -562,23 +564,24 @@ public function validate()
562564
{
563565
$errors = [];
564566
if (!\Zend_Validate::is($this->getFirstname(), 'NotEmpty')) {
565-
$errors[] = __('Please enter the first name.');
567+
$errors[] = __('%fieldName is a required field.', ['fieldName' => 'firstname']);
566568
}
567569

568570
if (!\Zend_Validate::is($this->getLastname(), 'NotEmpty')) {
569-
$errors[] = __('Please enter the last name.');
571+
$errors[] = __('%fieldName is a required field.', ['fieldName' => 'lastname']);
570572
}
571573

572574
if (!\Zend_Validate::is($this->getStreetLine(1), 'NotEmpty')) {
573-
$errors[] = __('Please enter the street.');
575+
$errors[] = __('%fieldName is a required field.', ['fieldName' => 'street']);
574576
}
575577

576578
if (!\Zend_Validate::is($this->getCity(), 'NotEmpty')) {
577-
$errors[] = __('Please enter the city.');
579+
$errors[] = __('%fieldName is a required field.', ['fieldName' => 'city']);
578580
}
579581

580582
if (!\Zend_Validate::is($this->getTelephone(), 'NotEmpty')) {
581-
$errors[] = __('Please enter the phone number.');
583+
$errors[] = __('%fieldName is a required field.', ['fieldName' => 'telephone']);
584+
582585
}
583586

584587
$_havingOptionalZip = $this->_directoryData->getCountriesWithOptionalZip();
@@ -590,11 +593,11 @@ public function validate()
590593
'NotEmpty'
591594
)
592595
) {
593-
$errors[] = __('Please enter the zip/postal code.');
596+
$errors[] = __('%fieldName is a required field.', ['fieldName' => 'postcode']);
594597
}
595598

596599
if (!\Zend_Validate::is($this->getCountryId(), 'NotEmpty')) {
597-
$errors[] = __('Please enter the country.');
600+
$errors[] = __('%fieldName is a required field.', ['fieldName' => 'countryId']);
598601
}
599602

600603
if ($this->getCountryModel()->getRegionCollection()->getSize() && !\Zend_Validate::is(
@@ -604,7 +607,7 @@ public function validate()
604607
$this->getCountryId()
605608
)
606609
) {
607-
$errors[] = __('Please enter the state/province.');
610+
$errors[] = __('%fieldName is a required field.', ['fieldName' => 'regionId']);
608611
}
609612

610613
if (empty($errors) || $this->getShouldIgnoreValidation()) {

app/code/Magento/Customer/Model/ResourceModel/AddressRepository.php

Lines changed: 6 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,12 @@ public function save(\Magento\Customer\Api\Data\AddressInterface $address)
124124
$addressModel->updateData($address);
125125
}
126126

127-
$inputException = $this->_validate($addressModel);
128-
if ($inputException->wasErrorAdded()) {
127+
$errors = $addressModel->validate();
128+
if ($errors !== true) {
129+
$inputException = new InputException();
130+
foreach ($errors as $error) {
131+
$inputException->addError($error);
132+
}
129133
throw $inputException;
130134
}
131135
$addressModel->save();
@@ -255,70 +259,6 @@ public function deleteById($addressId)
255259
return true;
256260
}
257261

258-
/**
259-
* Validate Customer Addresses attribute values.
260-
*
261-
* @param CustomerAddressModel $customerAddressModel the model to validate
262-
* @return InputException
263-
*
264-
* @SuppressWarnings(PHPMD.NPathComplexity)
265-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
266-
*/
267-
private function _validate(CustomerAddressModel $customerAddressModel)
268-
{
269-
$exception = new InputException();
270-
if ($customerAddressModel->getShouldIgnoreValidation()) {
271-
return $exception;
272-
}
273-
274-
if (!\Zend_Validate::is($customerAddressModel->getFirstname(), 'NotEmpty')) {
275-
$exception->addError(__('%fieldName is a required field.', ['fieldName' => 'firstname']));
276-
}
277-
278-
if (!\Zend_Validate::is($customerAddressModel->getLastname(), 'NotEmpty')) {
279-
$exception->addError(__('%fieldName is a required field.', ['fieldName' => 'lastname']));
280-
}
281-
282-
if (!\Zend_Validate::is($customerAddressModel->getStreetLine(1), 'NotEmpty')) {
283-
$exception->addError(__('%fieldName is a required field.', ['fieldName' => 'street']));
284-
}
285-
286-
if (!\Zend_Validate::is($customerAddressModel->getCity(), 'NotEmpty')) {
287-
$exception->addError(__('%fieldName is a required field.', ['fieldName' => 'city']));
288-
}
289-
290-
if (!\Zend_Validate::is($customerAddressModel->getTelephone(), 'NotEmpty')) {
291-
$exception->addError(__('%fieldName is a required field.', ['fieldName' => 'telephone']));
292-
}
293-
294-
$havingOptionalZip = $this->directoryData->getCountriesWithOptionalZip();
295-
if (!in_array($customerAddressModel->getCountryId(), $havingOptionalZip)
296-
&& !\Zend_Validate::is($customerAddressModel->getPostcode(), 'NotEmpty')
297-
) {
298-
$exception->addError(__('%fieldName is a required field.', ['fieldName' => 'postcode']));
299-
}
300-
301-
if (!\Zend_Validate::is($customerAddressModel->getCountryId(), 'NotEmpty')) {
302-
$exception->addError(__('%fieldName is a required field.', ['fieldName' => 'countryId']));
303-
}
304-
305-
if ($this->directoryData->isRegionRequired($customerAddressModel->getCountryId())) {
306-
$regionCollection = $customerAddressModel->getCountryModel()->getRegionCollection();
307-
if (!$regionCollection->count() && empty($customerAddressModel->getRegion())) {
308-
$exception->addError(__('%fieldName is a required field.', ['fieldName' => 'region']));
309-
} elseif (
310-
$regionCollection->count()
311-
&& !in_array(
312-
$customerAddressModel->getRegionId(),
313-
array_column($regionCollection->getData(), 'region_id')
314-
)
315-
) {
316-
$exception->addError(__('%fieldName is a required field.', ['fieldName' => 'regionId']));
317-
}
318-
}
319-
return $exception;
320-
}
321-
322262
/**
323263
* Retrieve collection processor
324264
*

app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -336,31 +336,31 @@ public function validateDataProvider()
336336
return [
337337
'firstname' => [
338338
array_merge(array_diff_key($data, ['firstname' => '']), ['country_id' => $countryId++]),
339-
['Please enter the first name.'],
339+
['firstname is a required field.'],
340340
],
341341
'lastname' => [
342342
array_merge(array_diff_key($data, ['lastname' => '']), ['country_id' => $countryId++]),
343-
['Please enter the last name.'],
343+
['lastname is a required field.'],
344344
],
345345
'street' => [
346346
array_merge(array_diff_key($data, ['street' => '']), ['country_id' => $countryId++]),
347-
['Please enter the street.'],
347+
['street is a required field.'],
348348
],
349349
'city' => [
350350
array_merge(array_diff_key($data, ['city' => '']), ['country_id' => $countryId++]),
351-
['Please enter the city.'],
351+
['city is a required field.'],
352352
],
353353
'telephone' => [
354354
array_merge(array_diff_key($data, ['telephone' => '']), ['country_id' => $countryId++]),
355-
['Please enter the phone number.'],
355+
['telephone is a required field.'],
356356
],
357357
'postcode' => [
358358
array_merge(array_diff_key($data, ['postcode' => '']), ['country_id' => $countryId++]),
359-
['Please enter the zip/postal code.'],
359+
['postcode is a required field.'],
360360
],
361361
'country_id' => [
362362
array_diff_key($data, ['country_id' => '']),
363-
['Please enter the country.'],
363+
['countryId is a required field.'],
364364
],
365365
'validated' => [array_merge($data, ['country_id' => $countryId++]), true],
366366
];

0 commit comments

Comments
 (0)