You are here

function uc_order_condition_count_products in Ubercart 7.3

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

Checks that the order has the selected number of products.

See also

uc_order_condition_count_products_form()

1 string reference to 'uc_order_condition_count_products'
uc_order_rules_condition_info in uc_order/uc_order.rules.inc
Implements hook_rules_condition_info().

File

uc_order/uc_order.rules.inc, line 578
Hooks and functions for uc_order Rules integration.

Code

function uc_order_condition_count_products($order, $products, $count, $op) {
  $totals = array(
    'all' => 0,
  );
  $total = 0;
  foreach ($order->products as $product) {
    $totals['all'] += $product->qty;
    if (isset($totals[$product->nid])) {
      $totals[$product->nid] += $product->qty;
    }
    else {
      $totals[$product->nid] = $product->qty;
    }
  }
  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, $count);
}