Пример #1
0
 /**
  * @param string $value
  * @return true|string[]
  */
 public function validateValue($value)
 {
     $countryId = $this->getExtractedData('country_id');
     $optionalZip = $this->_directoryData->getCountriesWithOptionalZip();
     if (!in_array($countryId, $optionalZip)) {
         return parent::validateValue($value);
     }
     return true;
 }
Пример #2
0
 /**
  * Validate address attribute values
  *
  * @return bool|array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function validate()
 {
     $errors = [];
     if (!\Zend_Validate::is($this->getFirstname(), 'NotEmpty')) {
         $errors[] = __('Please enter the first name.');
     }
     if (!\Zend_Validate::is($this->getLastname(), 'NotEmpty')) {
         $errors[] = __('Please enter the last name.');
     }
     if (!\Zend_Validate::is($this->getStreetLine(1), 'NotEmpty')) {
         $errors[] = __('Please enter the street.');
     }
     if (!\Zend_Validate::is($this->getCity(), 'NotEmpty')) {
         $errors[] = __('Please enter the city.');
     }
     if (!\Zend_Validate::is($this->getTelephone(), 'NotEmpty')) {
         $errors[] = __('Please enter the phone number.');
     }
     $_havingOptionalZip = $this->_directoryData->getCountriesWithOptionalZip();
     if (!in_array($this->getCountryId(), $_havingOptionalZip) && !\Zend_Validate::is($this->getPostcode(), 'NotEmpty')) {
         $errors[] = __('Please enter the zip/postal code.');
     }
     if (!\Zend_Validate::is($this->getCountryId(), 'NotEmpty')) {
         $errors[] = __('Please enter the country.');
     }
     if ($this->getCountryModel()->getRegionCollection()->getSize() && !\Zend_Validate::is($this->getRegionId(), 'NotEmpty') && $this->_directoryData->isRegionRequired($this->getCountryId())) {
         $errors[] = __('Please enter the state/province.');
     }
     if (empty($errors) || $this->getShouldIgnoreValidation()) {
         return true;
     }
     return $errors;
 }
Пример #3
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;
 }
Пример #4
0
 /**
  * @param string $configValue
  * @param mixed $expected
  * @dataProvider countriesCommaListDataProvider
  */
 public function testGetCountriesWithOptionalZip($configValue, $expected)
 {
     $this->_config->expects($this->once())->method('getValue')->with('general/country/optional_zip_countries')->will($this->returnValue($configValue));
     $result = $this->_object->getCountriesWithOptionalZip();
     $this->assertEquals($expected, $result);
 }
Пример #5
0
 /**
  * Return ISO2 country codes, which have optional Zip/Postal pre-configured
  *
  * @return array|string
  */
 public function getOptionalZipCountries()
 {
     return $this->_directoryHelper->getCountriesWithOptionalZip();
 }
Пример #6
0
 /**
  * Checks if zip for current country id is required
  *
  * @param string $countryId
  * @return bool
  */
 protected function isZipRequired($countryId)
 {
     return !in_array($countryId, $this->directoryHelper->getCountriesWithOptionalZip());
 }