I have an entity with a field colleciton (fc_details), and in that field collection I have fields amount(field_amount) and Type (field_type)
There are several examples to sum up field colleciton values in computed field like:
$sum = 0;
$wrapper = entity_metadata_wrapper($entity_type, $entity);
foreach($wrapper->field_fc_details as $collection) {
$sum += $collection->field_amount->value();
}
$entity_field[0]['value'] = $sum;
But I want to sum up values, where field_type values = "Z".
I tried variations of "if($wrapper->field_type->value()='Z' " inside foreach, but then site gives 500 error.
Any ideas ? Thanks in advance.