Participant's fee amount changes when saving the associated contribution
When someone registers multiple participants for an event, saving the contribution will change the participant's fee_amount
for the last participant.
Replication Steps
- Create a new paid event with online registration (let's say tickets are $5).
- Allow registering multiple participants.
- Register for the event with at least one additional registrant (let's assume one additional person, so $10 total).
- Look at both contact's participant records - their fee amount (on the "Events" tab) will show $5.
- Click Edit for the contribution record on the primary registrant and then Save with no changes.
Expected Result
The fee amount on both participant records remains at $5.
Actual Result
The fee amount on the second participant records changes to $10.
Analysis
This happens at CRM_Contribute_Form_Contribution::submit()
line 1580.
We call CRM_Contribute_BAO_Contribution::getComponentDetails()
which claims it "Returns all contribution related object ids" but assumes that there is only one participant (and membership) record tied to a contribution. So it returns the participant ID of the last person registered, and then at line 1611-1614, resaves the participant record with the total amount of the contribution.
Next Steps
Line 1602 claims we are "updating the line items for participants", and I understand updating the fee_amount
if the price changes. However, lines 1610-1614 are better out than in - they're more liable to give a wrong answer than a right one. Alternatively, we can limit it to only work on single line item contributions.
The next step would be to deprecate CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id)
since it can't handle multiple membership/participant records, and replace it with a function that does. Then we can fix the code that calls the deprecated function.
I realize none of this code should be at the form layer - but that's a much larger job.