You are here

public function UPSShipment::setDimensions in Commerce UPS 8.3

Package dimension setter.

Parameters

\Ups\Entity\Package $ups_package: A Ups API package object.

1 call to UPSShipment::setDimensions()
UPSShipment::setPackage in src/UPSShipment.php
Sets the package for a given shipment.

File

src/UPSShipment.php, line 132

Class

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

Namespace

Drupal\commerce_ups

Code

public function setDimensions(UPSPackage $ups_package) {
  $dimensions = new Dimensions();
  $valid_unit = $this
    ->getValidDimensionsUnit();

  // Rounding dimensions since decimals are not allowed by the UPS API.
  $dimensions
    ->setHeight(ceil($this
    ->getPackageType()
    ->getHeight()
    ->convert($valid_unit)
    ->getNumber()));
  $dimensions
    ->setWidth(ceil($this
    ->getPackageType()
    ->getWidth()
    ->convert($valid_unit)
    ->getNumber()));
  $dimensions
    ->setLength(ceil($this
    ->getPackageType()
    ->getLength()
    ->convert($valid_unit)
    ->getNumber()));
  $dimensions
    ->setUnitOfMeasurement($this
    ->setUnitOfMeasurement($this
    ->getUnitOfMeasure($valid_unit)));
  $ups_package
    ->setDimensions($dimensions);
}