webform_civicrm
webform_civicrm copied to clipboard
Support for participant count
Overview
In event price sets, a price option can have a "participant count". E.g. purchasing a "table for 10" ticket will increment the participant count by 10 despite buying one ticket. This PR adds support for participant counts in WFC.
Before
All tickets purchased count as one participant.
After
A "participant count" field exists This can be a numeric input, Computed Twig, etc.
The "Fee Amount" is not affected by the count. If you want the fee amount to be "per participant", you'll use Twig.
Technical Details
Participant count requires a line item with a non-NULL price_field_value_id
). WFC has line items for paid events only. We never populate price_field_value_id
.
So:
- We introduce a new field "Participant Count" (in
AdminHelp.php
andFields.php
). - We create a hidden price field exclusively for use by WFC events. The
Utils.php
function returns that price field value, and will create it if it doesn't exist. - When recording a contribution's line items, we now include the count. We make changes to
qty
andunit_price
to be count-aware (if used). We include the requiredline_total
andprice_field_value_id
so participant count is calculated correctly. - When recording events, we check if it's a paid event. If not, we create a line item tied to the participant record.
Comments
When testing, note that API4's "remaining participants" calculated field is inaccurate for multiple reasons. To view an accurate count, call Api3 event.get
and return underdocumented value is_full
(see screenshot).
I'll address these failures tomorrow.
test this please
I just kicked off the test by pushing a trivial commit to your participant-count-deux
branch.
I'll resolve the conflict here soon. This should pass existing tests, but I have new tests that aren't all passing. Event line items have always been a little inconsistent in WFC and I need to figure out how consistent they need to be made to support this.
Ah cool on the test! If needed we can bring this over the finish line in Montreal!
OK - this is now updated to create line items correctly in both "register all for same event" and "register each contact separately".
Previously - line items were created correctly only when "register each contact separately" was selected. When "register all for same event" was selected, one line item was created for the entire transaction. This threw off participant count calculations, which assume if there's a missing line item, the count is 1. So registering 3 people for 4 seats each would take up 14 places, not 12 (since contact 1 would have a line item for 12 places, contacts 2 and 3 would have no line items).
My latest changes ensure that separate line items are created for each participant record.