/**
  * Add success message for valid VAT ID
  *
  * @param Address $customerAddress
  * @param DataObject $validationResult
  * @return $this
  */
 protected function addValidMessage($customerAddress, $validationResult)
 {
     $message = [(string) __('Your VAT ID was successfully validated.')];
     $customer = $customerAddress->getCustomer();
     if (!$this->scopeConfig->isSetFlag(HelperAddress::XML_PATH_VIV_DISABLE_AUTO_ASSIGN_DEFAULT) && !$customer->getDisableAutoGroupChange()) {
         $customerVatClass = $this->_customerVat->getCustomerVatClass($customerAddress->getCountryId(), $validationResult);
         $message[] = $customerVatClass == Vat::VAT_CLASS_DOMESTIC ? (string) __('You will be charged tax.') : (string) __('You will not be charged tax.');
     }
     $this->messageManager->addSuccess(implode(' ', $message));
     return $this;
 }
Example #2
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;
 }