function commerce_price_rules_compare_price in Commerce Core 7
Condition callback: compares two price values.
1 string reference to 'commerce_price_rules_compare_price'
- commerce_price_rules_condition_info in modules/
price/ commerce_price.rules.inc - Implements hook_rules_condition_info().
File
- modules/
price/ commerce_price.rules.inc, line 172 - Rules integration for the Price module.
Code
function commerce_price_rules_compare_price($first_price, $operator, $second_price) {
$value1 = $first_price['amount'];
$value2 = $second_price['amount'];
// Convert amount of second price to match currency code of first price.
if ($first_price['currency_code'] != $second_price['currency_code']) {
$value2 = commerce_currency_convert($second_price['amount'], $second_price['currency_code'], $first_price['currency_code']);
}
// Make a quantity comparison based on the operator.
switch ($operator) {
case '<':
return $value1 < $value2;
case '<=':
return $value1 <= $value2;
case '=':
return $value1 == $value2;
case '>=':
return $value1 >= $value2;
case '>':
return $value1 > $value2;
}
return FALSE;
}