You are here

protected function USPSShipmentBase::setWeight in Commerce USPS 8

Sets the package weight.

2 calls to USPSShipmentBase::setWeight()
USPSShipment::buildPackage in src/USPSShipment.php
Returns an initialized rate package object.
USPSShipmentInternational::buildPackage in src/USPSShipmentInternational.php
Returns an initialized rate package object.

File

src/USPSShipmentBase.php, line 124

Class

USPSShipmentBase
Class that sets the shipment details needed for the USPS request.

Namespace

Drupal\commerce_usps

Code

protected function setWeight() {
  $weight = $this->commerceShipment
    ->getWeight();
  if ($weight
    ->getNumber() > 0) {
    $ounces = ceil($weight
      ->convert('oz')
      ->getNumber());
    $this->uspsPackage
      ->setPounds(floor($ounces / 16));
    $this->uspsPackage
      ->setOunces($ounces % 16);
  }
}