function commerce_physical_order_dimensions in Commerce Physical Product 7
Determines the dimensions of each product in an entire order.
Other code can then use this data to figure out things like what the maximum dimensions of any product in the order is, or what size shipping container everything will fit into.
Parameters
commerce_order $order: The order object whose dimensions should be returned.
string $unit: The unit of measurement to use for the returned dimensions.
Return value
array An array of dimension arrays. One per product in the order. weight field value array representing the total weight of the order using the specified unit of measurement or NULL if no weight could be determined.
1 call to commerce_physical_order_dimensions()
- commerce_physical_rules_order_max_dimension_comparison in ./
commerce_physical.rules.inc - Fetches the max. dimension in the order and compares it with a given value.
File
- ./
commerce_physical.module, line 280 - API for working with physical product types in Drupal Commerce.
Code
function commerce_physical_order_dimensions($order, $unit = 'cm') {
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$order_dimensions = array();
// Loop over each line item on the order.
foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
// Get the weight value of product line items.
if (in_array($line_item_wrapper->type
->value(), commerce_product_line_item_types())) {
$line_item_dimensions = commerce_physical_product_line_item_dimensions($line_item_wrapper
->value());
$order_dimensions = array_merge($order_dimensions, $line_item_dimensions);
}
}
// Now ensure that all dimensions supplied are in the requested units.
foreach ($order_dimensions as $key => $dimensions) {
$order_dimensions[$key] = physical_dimensions_convert($dimensions, $unit);
}
// Allow other modules to alter the weight if necessary.
drupal_alter('commerce_physical_order_dimensions', $order_dimensions, $order, $unit);
return $order_dimensions;
}