function commerce_usps_get_order_weight in Commerce USPS 7.2
Determine the weight of the order.
3 calls to commerce_usps_get_order_weight()
- commerce_usps_intl_rate_v2_request in includes/
commerce_usps.xml.inc - Builds an international USPS rate request.
- commerce_usps_rate_v4_request in includes/
commerce_usps.xml.inc - Builds a domestics USPS rate request.
- commerce_usps_validate_order in ./
commerce_usps.module - Validate that the order can return a successful rate request.
File
- ./
commerce_usps.module, line 248 - Defines the USPS shipping method and services for Drupal Commerce.
Code
function commerce_usps_get_order_weight($order) {
// Use commerce physical to determine the order weight.
$weight = commerce_physical_order_weight($order, 'lb');
// If order contains no weight skip sending request to usps.
if (!is_array($weight) || $weight['weight'] == NULL) {
return FALSE;
}
// Calculate the weight in ounces and pounds.
$ounces = number_format(16 * ($weight['weight'] - floor($weight['weight'])), 1);
$pounds = floor($weight['weight']);
return array(
'pounds' => $pounds,
'ounces' => $ounces,
);
}