You are here

public function UPSShipment::setShipTo in Commerce UPS 8.3

Sets the ship to for a given shipment.

Parameters

\Ups\Entity\Shipment $api_shipment: A Ups API shipment object.

Throws

\Drupal\Core\TypedData\Exception\MissingDataException

1 call to UPSShipment::setShipTo()
UPSShipment::getShipment in src/UPSShipment.php
Creates and returns a UPS API shipment object.

File

src/UPSShipment.php, line 71

Class

UPSShipment
Class to create and return a UPS API shipment object.

Namespace

Drupal\commerce_ups

Code

public function setShipTo(APIShipment $api_shipment) {

  /** @var \CommerceGuys\Addressing\AddressInterface $address */
  $address = $this->shipment
    ->getShippingProfile()
    ->get('address')
    ->first();
  $to_address = new Address();
  $to_address
    ->setAddressLine1($address
    ->getAddressLine1());
  $to_address
    ->setAddressLine2($address
    ->getAddressLine2());
  $to_address
    ->setCity($address
    ->getLocality());
  $to_address
    ->setCountryCode($address
    ->getCountryCode());
  $to_address
    ->setStateProvinceCode($address
    ->getAdministrativeArea());
  $to_address
    ->setPostalCode($address
    ->getPostalCode());
  $api_shipment
    ->getShipTo()
    ->setAddress($to_address);
}