I am currently trying to figure out how to set a minimum value to a computed field using an if, else statement. I basically want the field to check the value of other fields and if their calculated value is less than 150, set the value to 150. Here's what I'm trying to use unsuccessfully:

if (!$node->nid) {
node_save($node);
}

$min_install = '150';

if ( ($node->field_sf_total[0]['value'] * 10) * $node->field_fab[0]['value'] ) < $min_install {
$node_field[0]['value'] = $min_install;
}
else {
$node_field[0]['value'] = ($node->field_sf_total[0]['value'] * 10) * $node->field_fab[0]['value'];
}

I get syntax errors when using it, so any help pointing out my errors would be greatly appreciated! Thanks!

Comments

fmesco’s picture

Figured it out:

if (!$node->nid) node_save($node);

$installfee = ($node->field_sf_total[0]['value'] * 10) * $node->field_fab[0]['value'];
$check_install = 149;
$min_install = 150;

if ($installfee <= $check_install){
$node_field[0]['value'] = $min_install;}
else {
$node_field[0]['value'] = $installfee;}
mmjvb’s picture

Issue summary: View changes
Status: Active » Closed (outdated)