Skip to content

gpnf-override-parent-merge-tag-on-submission.php: reprocess calculations on submission based on changed parent form values #508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ function gpnf_override_parent_merge_tags( $entry, $form ) {
gpnf_override_child_entry_input_value( $entry, $field, $child_field->id, $child_field->defaultValue );
}
}

// Reprocess calculations based off of the potentially changed parent value.
$child_entry_ids = explode( ',', rgar( $entry, $field->id ) );

foreach ( $child_entry_ids as $child_entry_id ) {
foreach ( $child_form['fields'] as $child_field ) {
if ( in_array( $child_field->id, $exclude_field_ids ) ) {
continue;
}

if ( ! $child_field->has_calculation() ) {
continue;
}

// @todo do calculated product fields need to be accounted for differently?
$child_entry = GFAPI::get_entry( $child_entry_id );
$calculated_value = $child_field->get_value_save_entry( null, $child_form, $child_field->id, $child_entry_id, $child_entry );
GFAPI::update_entry_field( $child_entry_id, $child_field->id, $calculated_value );
}
}
}
}

Expand Down