function commerce_physical_rules_order_max_dimension_comparison in Commerce Physical Product 7
Fetches the max. dimension in the order and compares it with a given value.
Calculates the maximum single dimension of any product in the order and performs a comparison on it.
File
- ./
commerce_physical.rules.inc, line 104 - Rules integration for commerce physical.
Code
function commerce_physical_rules_order_max_dimension_comparison($order, $operator, $value, $unit) {
$max_dimension = 0;
$dimension_keys = array(
'length',
'width',
'height',
);
// Get the dimensions of every product in the order.
foreach (commerce_physical_order_dimensions($order, $unit) as $dimension) {
// Check each of length / width / height.
foreach ($dimension_keys as $dimension_key) {
// If this dimension's bigger than the current max, it's the new max.
if ($dimension[$dimension_key] > $max_dimension) {
$max_dimension = $dimension[$dimension_key];
}
}
}
switch ($operator) {
case '<':
return $max_dimension < $value;
case '<=':
return $max_dimension <= $value;
case '==':
return $max_dimension == $value;
case '>=':
return $max_dimension >= $value;
case '>':
return $max_dimension > $value;
}
return FALSE;
}