Skip to content

Commit bd7eecf

Browse files
author
Aleksandr Osadchyi
committed
MAGETWO-61725: [GITHUB] Improve address save flow to allow to use custom validators #7552
1 parent 227a26d commit bd7eecf

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
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()) {

dev/tests/api-functional/testsuite/Magento/Customer/Api/CustomerRepositoryTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ public function testCreateCustomerWithoutAddressRequiresException()
432432
$expectedException = new InputException();
433433
$expectedException->addError(
434434
__(
435-
'Please enter the first name.'
435+
'%fieldName is a required field.',
436+
['fieldName' => Address::FIRSTNAME]
436437
)
437438
);
438439
$this->assertInstanceOf('SoapFault', $e);
@@ -446,7 +447,8 @@ public function testCreateCustomerWithoutAddressRequiresException()
446447
$this->assertEquals(HTTPExceptionCodes::HTTP_BAD_REQUEST, $e->getCode());
447448
$exceptionData = $this->processRestExceptionResult($e);
448449
$expectedExceptionData = [
449-
'message' => 'Please enter the first name.',
450+
'message' => '%fieldName is a required field.',
451+
'parameters' => ['fieldName' => Address::FIRSTNAME],
450452
];
451453
$this->assertEquals($expectedExceptionData, $exceptionData);
452454
}

dev/tests/integration/testsuite/Magento/Customer/Api/AddressRepositoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ public function testSaveNewInvalidAddress()
207207
$this->assertEquals('One or more input exceptions have occurred.', $exception->getMessage());
208208
$errors = $exception->getErrors();
209209
$this->assertCount(2, $errors);
210-
$this->assertEquals('Please enter the first name.', $errors[0]->getLogMessage());
211-
$this->assertEquals('Please enter the last name.', $errors[1]->getLogMessage());
210+
$this->assertEquals('firstname is a required field.', $errors[0]->getLogMessage());
211+
$this->assertEquals('lastname is a required field.', $errors[1]->getLogMessage());
212212
}
213213
}
214214

dev/tests/integration/testsuite/Magento/Customer/Controller/AddressTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ public function testFailedFormPostAction()
150150
$this->equalTo(
151151
[
152152
'One or more input exceptions have occurred.',
153-
'Please enter the street.',
154-
'Please enter the city.',
153+
'street is a required field.',
154+
'city is a required field.',
155155
]
156156
),
157157
\Magento\Framework\Message\MessageInterface::TYPE_ERROR

dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/AddressRepositoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ public function testSaveNewInvalidAddress()
213213
$this->assertEquals('One or more input exceptions have occurred.', $exception->getMessage());
214214
$errors = $exception->getErrors();
215215
$this->assertCount(2, $errors);
216-
$this->assertEquals('Please enter the first name.', $errors[0]->getLogMessage());
217-
$this->assertEquals('Please enter the last name.', $errors[1]->getLogMessage());
216+
$this->assertEquals('firstname is a required field.', $errors[0]->getLogMessage());
217+
$this->assertEquals('lastname is a required field.', $errors[1]->getLogMessage());
218218
}
219219
}
220220

0 commit comments

Comments
 (0)