Skip to content

Commit 801c121

Browse files
committed
Removed private _validate method.
Public validation method of address instance should be used instead.
1 parent d40ab32 commit 801c121

File tree

1 file changed

+6
-66
lines changed

1 file changed

+6
-66
lines changed

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
*

0 commit comments

Comments
 (0)