You are here

function uc_order_condition_products_weight in Ubercart 8.4

Same name and namespace in other branches
  1. 5 uc_order/uc_order_workflow.inc \uc_order_condition_products_weight()
  2. 6.2 uc_order/uc_order.ca.inc \uc_order_condition_products_weight()
  3. 7.3 uc_order/uc_order.rules.inc \uc_order_condition_products_weight()

Checks the weight of the order's products.

See also

uc_order_condition_products_weight_form()

File

uc_order/uc_order.rules.inc, line 351
Rules integration for order-related entity events, conditions, and actions.

Code

function uc_order_condition_products_weight($order, $products, $weight_units, $weight_value, $op) {
  $totals = [
    'all' => 0,
  ];
  $total = 0;
  foreach ($order->products as $product) {
    $unit_conversion = uc_weight_conversion($product->weight_units, $weight_units);
    $totals['all'] += $product->qty * $product->weight * $unit_conversion;
    $totals[$product->nid] = $product->qty * $product->weight * $unit_conversion;
  }
  if (in_array('all', $products)) {
    $total = $totals['all'];
  }
  else {
    foreach ($products as $product) {
      if (isset($totals[$product])) {
        $total += $totals[$product];
      }
    }
  }
  return uc_order_condition_value_operator_comparison($total, $op, $weight_value);
}