function uc_order_condition_count_products in Ubercart 8.4
Same name and namespace in other branches
- 5 uc_order/uc_order_workflow.inc \uc_order_condition_count_products()
- 6.2 uc_order/uc_order.ca.inc \uc_order_condition_count_products()
- 7.3 uc_order/uc_order.rules.inc \uc_order_condition_count_products()
Checks that the order has the selected number of products.
See also
uc_order_condition_count_products_form()
File
- uc_order/
uc_order.rules.inc, line 298 - Rules integration for order-related entity events, conditions, and actions.
Code
function uc_order_condition_count_products($order, $products, $count, $op) {
$totals = [
'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);
}