/**
  * @param $prefix
  * @param $data
  * @return Address
  */
 private function createAddress($prefix, $data)
 {
     $data = (array) $data;
     if ($prefix) {
         $prefix .= '_';
     }
     if (!empty($data[$prefix . 'name'])) {
         $name = $this->getValue($data, $prefix . 'name', '');
     } else {
         $name = $this->getValue($data, $prefix . 'alias', '');
     }
     $address = new Address($name, $this->getValue($data, $prefix . 'address', ''), $this->getValue($data, $prefix . 'city', ''), $this->getValue($data, $prefix . 'zip_code', ''), $this->getValue($data, $prefix . 'country_code', ''), $this->getValue($data, $prefix . 'phone', ''));
     $address->setAddress($this->getValue($data, $prefix . 'address', ''));
     $address->setNif($this->getValue($data, $prefix . 'nif', ''));
     $address->setAttn($this->getValue($data, $prefix . 'attn', ''));
     $address->setEmail($this->getValue($data, $prefix . 'email', ''));
     $address->setObservations($this->getValue($data, $prefix . 'observations', ''));
     return $address;
 }
 public function __construct(Shipment $shipment, Address $from, Address $to)
 {
     foreach (get_object_vars($shipment) as $key => $value) {
         $this->{$key} = $value;
     }
     $this->from_name = $from->getName();
     $this->from_address = $from->getAddress();
     $this->from_city = $from->getCity();
     $this->from_zip_code = $from->getZipCode();
     $this->from_country_code = $from->getCountryCode();
     $this->from_phone = $from->getPhone();
     $this->to_nif = $to->getNif();
     $this->to_name = $to->getName();
     $this->to_attn = $to->getAttn();
     $this->to_address = $to->getAddress();
     $this->to_city = $to->getCity();
     $this->to_zip_code = $to->getZipCode();
     $this->to_country_code = $to->getCountryCode();
     $this->to_phone = $to->getPhone();
     $this->to_email = $to->getEmail();
     $this->to_observations = $to->getObservations();
 }