protected function USPSShipment::setShipTo in Commerce USPS 8
Sets the ship to for a given shipment.
1 call to USPSShipment::setShipTo()
- USPSShipment::buildPackage in src/
USPSShipment.php - Returns an initialized rate package object.
File
- src/
USPSShipment.php, line 39
Class
- USPSShipment
- Class that sets the shipment details needed for the USPS request.
Namespace
Drupal\commerce_uspsCode
protected function setShipTo() {
/** @var \CommerceGuys\Addressing\Address $address */
$address = $this->commerceShipment
->getShippingProfile()
->get('address')
->first();
$to_address = new Address();
$to_address
->setAddress($address
->getAddressLine1());
$to_address
->setApt($address
->getAddressLine2());
$to_address
->setCity($address
->getLocality());
$to_address
->setState($address
->getAdministrativeArea());
// Due to API limitations, only accept the first 5 digits of the Zip Code.
$this->uspsPackage
->setZipDestination(substr($address
->getPostalCode(), 0, 5));
}