function uc_order_condition_products_weight in Ubercart 6.2
Same name and namespace in other branches
- 8.4 uc_order/uc_order.rules.inc \uc_order_condition_products_weight()
- 5 uc_order/uc_order_workflow.inc \uc_order_condition_products_weight()
- 7.3 uc_order/uc_order.rules.inc \uc_order_condition_products_weight()
Checkt the weight of the order's products.
See also
uc_order_condition_products_weight_form()
1 string reference to 'uc_order_condition_products_weight'
- uc_order_ca_condition in uc_order/
uc_order.ca.inc - Implements hook_ca_condition().
File
- uc_order/
uc_order.ca.inc, line 784 - This file contains the Conditional Actions hooks and functions necessary to make the order related entity, conditions, events, and actions work.
Code
function uc_order_condition_products_weight($order, $settings) {
$totals = array(
'all' => 0,
);
$total = 0;
foreach ($order->products as $product) {
$unit_conversion = uc_weight_conversion($product->weight_units, $settings['weight_units']);
$totals['all'] += $product->qty * $product->weight * $unit_conversion;
$totals[$product->model] = $product->qty * $product->weight * $unit_conversion;
}
if (in_array('all', $settings['products'])) {
$total = $totals['all'];
}
else {
foreach ($settings['products'] as $product) {
$total += $totals[$product];
}
}
switch ($settings['product_weight_comparison']) {
case 'less':
return $total < $settings['product_weight_value'];
case 'less_equal':
return $total <= $settings['product_weight_value'];
case 'equal':
return $total == $settings['product_weight_value'];
case 'greater_equal':
return $total >= $settings['product_weight_value'];
case 'greater':
return $total > $settings['product_weight_value'];
}
}