You are here

public static function FedEx::calculatePackageCount in Commerce FedEx 8

Determines a package count given package and item volumes.

Parameters

\NicholasCreativeMedia\FedExPHP\Structs\RequestedPackageLineItem $requested_package_line_item: The package line item containing the fedex package dimensions.

array $shipment_items: The array of shipment items.

Return value

bool|float The number of needed packages, or False on error.

1 call to FedEx::calculatePackageCount()
FedEx::getRequestedPackageLineItemsCalculate in src/Plugin/Commerce/ShippingMethod/FedEx.php
Gets package line items for PACKAGE_CALCULATE strategy.

File

src/Plugin/Commerce/ShippingMethod/FedEx.php, line 1214

Class

FedEx
Provides the FedEx shipping method.

Namespace

Drupal\commerce_fedex\Plugin\Commerce\ShippingMethod

Code

public static function calculatePackageCount(RequestedPackageLineItem $requested_package_line_item, array $shipment_items) {
  $package_volume = static::getFedexPackageVolume($requested_package_line_item
    ->getDimensions());
  $items_volume = static::getPackageTotalVolume($shipment_items, $package_volume
    ->getUnit());
  if ($package_volume
    ->getNumber() != 0) {
    return ceil($items_volume
      ->getNumber() / $package_volume
      ->getNumber());
  }
  return FALSE;
}