Ejemplo n.º 1
0
 /**
  * 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 ($customerAddressModel->getCountryModel()->getRegionCollection()->getSize() && !\Zend_Validate::is($customerAddressModel->getRegionId(), 'NotEmpty') && $this->directoryData->isRegionRequired($customerAddressModel->getCountryId())) {
         $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'regionId']));
     }
     return $exception;
 }