function commerce_registration_order_registration_count_comparison in Commerce Registration 7.3
Condition callback. Compare the total number of registrations on the order.
Related topics
File
- ./
commerce_registration.rules.inc, line 146 - Commerce Registration rules file.
Code
function commerce_registration_order_registration_count_comparison($order, $operator, $amount) {
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$total = 0;
foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
if (!in_array($line_item_wrapper->type
->value(), commerce_product_line_item_types())) {
continue;
}
$line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
$registrations = $line_item_wrapper->registrations
->value();
if (!is_array($registrations)) {
continue;
}
// Get the total registration count. There is at most a depth of 2.
foreach ($registrations as $registration) {
if (is_array($registration)) {
$total += count($registration);
}
else {
$total++;
}
}
}
switch ($operator) {
case '=':
return $total == $amount;
case '>=':
return $total >= $amount;
case '>':
return $total > $amount;
case '<':
return $total < $amount;
case '<=':
return $total <= $amount;
case '!=':
return $total != $amount;
}
return FALSE;
}