I'm using computed field in drupal, which uses just straight up PHP, only problem is I don't know php well.
The 3 scripts below, work individually. When I try to combine them, using different syntax of course, they all fail. What I'm trying to do is add up 3 fields, from 3 different field sets or field collections.
1st
$price = 0;
$wrapper = entity_metadata_wrapper($entity_type, $entity);
foreach($wrapper->field_venue_sites_simple as $collection) {
$price += $collection->field_site_fee->value();
}
$entity_field[0]['value'] = $price;
2nd
$price = 0;
$wrapper = entity_metadata_wrapper($entity_type, $entity);
foreach($wrapper->field_venue_sites_w_catering as $collection) {
$price += $collection->field_site_fee->value();
}
$entity_field[0]['value'] = $price;
3rd
$price = 0;
$wrapper = entity_metadata_wrapper($entity_type, $entity);
foreach($wrapper->field_venue_site as $collection) {
$price += $collection->field_peak_pricing->field_peak_price_saturday->value();
}
$entity_field[0]['value'] = $price;
I've tried this to combine them, but it doesn't work:
$price = 0;
$wrapper = entity_metadata_wrapper($entity_type, $entity);
$price =
$wrapper->field_venue_sites_simple->field_site_fee->value() +
$wrapper->field_venue_site->field_peak_pricing->field_peak_price_saturday->value() +
$wrapper->field_venue_sites_w_catering->field_site_fee->value();
$entity_field[0]['value'] = $price;
I've aware the foreach loops through arrays. I don't need it to loop, so I can take that out. They are all multiple value fields, but I only need it to pull one value.
I've also tried this, and it didn't not work either:
$wrapper = entity_metadata_wrapper($entity_type, $entity);
$collection1 = $wrapper->field_venue_sites_simple;
$collection2 = $wrapper->field_venue_site;
$collection3 = $wrapper->field_venue_sites_w_catering;
$entity_field[0]['value'] =
$collection1->field_site_fee->value()+
$collection2->field_peak_pricing->field_peak_price_saturday->value()+
$collection3->field_site_fee->value();
Any help greatly appreciated! Been messing with this all day.