/**
  * Validate address attribute for customer creation
  *
  * @return bool|array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  *
  * @param Address $address
  */
 public function validateForCustomer(Address $address)
 {
     if ($address->getShouldIgnoreValidation()) {
         return true;
     }
     $errors = [];
     if ($this->isEmpty($address->getFirstname())) {
         $errors[] = __('Please enter the first name.');
     }
     if ($this->isEmpty($address->getLastname())) {
         $errors[] = __('Please enter the last name.');
     }
     if ($this->isEmpty($address->getStreetLine(1))) {
         $errors[] = __('Please enter the street.');
     }
     if ($this->isEmpty($address->getCity())) {
         $errors[] = __('Please enter the city.');
     }
     if ($this->isEmpty($address->getTelephone())) {
         $errors[] = __('Please enter the phone number.');
     }
     $countryId = $address->getCountryId();
     if ($this->isZipRequired($countryId) && $this->isEmpty($address->getPostcode())) {
         $errors[] = __('Please enter the zip/postal code.');
     }
     if ($this->isEmpty($countryId)) {
         $errors[] = __('Please enter the country.');
     }
     if ($this->isStateRequired($countryId) && $this->isEmpty($address->getRegionId())) {
         $errors[] = __('Please enter the state/province.');
     }
     return empty($errors) ? true : $errors;
 }
Example #2
0
 /**
  * Set recipient details into request
  * @param \Magento\Shipping\Model\Shipment\Request $request
  * @param \Magento\Sales\Model\Order\Address $address
  * @return void
  */
 protected function setRecipientDetails(Request $request, Address $address)
 {
     $request->setRecipientContactPersonName(trim($address->getFirstname() . ' ' . $address->getLastname()));
     $request->setRecipientContactPersonFirstName($address->getFirstname());
     $request->setRecipientContactPersonLastName($address->getLastname());
     $request->setRecipientContactCompanyName($address->getCompany());
     $request->setRecipientContactPhoneNumber($address->getTelephone());
     $request->setRecipientEmail($address->getEmail());
     $request->setRecipientAddressStreet(trim($address->getStreetLine(1) . ' ' . $address->getStreetLine(2)));
     $request->setRecipientAddressStreet1($address->getStreetLine(1));
     $request->setRecipientAddressStreet2($address->getStreetLine(2));
     $request->setRecipientAddressCity($address->getCity());
     $request->setRecipientAddressStateOrProvinceCode($address->getRegionCode() ?: $address->getRegion());
     $request->setRecipientAddressRegionCode($address->getRegionCode());
     $request->setRecipientAddressPostalCode($address->getPostcode());
     $request->setRecipientAddressCountryCode($address->getCountryId());
 }