/** * Validate Customer Addresses attribute values. * * @param CustomerAddressModel $customerAddressModel the model to validate * @return InputException * * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ private function _validate(CustomerAddressModel $customerAddressModel) { $exception = new InputException(); if ($customerAddressModel->getShouldIgnoreValidation()) { return $exception; } if (!\Zend_Validate::is($customerAddressModel->getFirstname(), 'NotEmpty')) { $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'firstname'])); } if (!\Zend_Validate::is($customerAddressModel->getLastname(), 'NotEmpty')) { $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'lastname'])); } if (!\Zend_Validate::is($customerAddressModel->getStreetLine(1), 'NotEmpty')) { $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'street'])); } if (!\Zend_Validate::is($customerAddressModel->getCity(), 'NotEmpty')) { $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'city'])); } if (!\Zend_Validate::is($customerAddressModel->getTelephone(), 'NotEmpty')) { $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'telephone'])); } $havingOptionalZip = $this->directoryData->getCountriesWithOptionalZip(); if (!in_array($customerAddressModel->getCountryId(), $havingOptionalZip) && !\Zend_Validate::is($customerAddressModel->getPostcode(), 'NotEmpty')) { $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'postcode'])); } if (!\Zend_Validate::is($customerAddressModel->getCountryId(), 'NotEmpty')) { $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'countryId'])); } if ($this->directoryData->isRegionRequired($customerAddressModel->getCountryId())) { $regionCollection = $customerAddressModel->getCountryModel()->getRegionCollection(); if (!$regionCollection->count() && empty($customerAddressModel->getRegion())) { $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'region'])); } elseif ($regionCollection->count() && !in_array($customerAddressModel->getRegionId(), array_column($regionCollection->getData(), 'region_id'))) { $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'regionId'])); } } return $exception; }