Fix stale membership_type_id overriding price set selections on membership form#35145
Open
erawat wants to merge 1 commit intocivicrm:masterfrom
Open
Fix stale membership_type_id overriding price set selections on membership form#35145erawat wants to merge 1 commit intocivicrm:masterfrom
erawat wants to merge 1 commit intocivicrm:masterfrom
Conversation
|
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
Quick links for reviewers...
|
erawat
added a commit
to compucorp/civicrm-core
that referenced
this pull request
Mar 19, 2026
…ons on membership form PR: civicrm#35145
erawat
added a commit
to compucorp/civicrm-core
that referenced
this pull request
Mar 19, 2026
…ons on membership form PR: civicrm#35145
…rship form When a non-quick-config price set is selected on the back-office membership form, the membership_type_id field from the org/type selector may retain a stale value. getSelectedMemberships() checks membership_type_id[1] first and if set, uses it as the sole selected membership type — ignoring all price set selections entirely. This causes membership creation to fail with a DB constraint violation because getMembershipParameters() only sets membership_type_id for the types in _memTypeSelected, while the form tries to create memberships for all types from the price set line items. The fix adds a check for price_set_id so that when a price set is active, membership types are always derived from the price field selections.
3a9051d to
eb24de4
Compare
Contributor
|
I wonder if it makes sense to guard against the form submitting conflicting values like this instead of fixing the form so it doesn't submit conflicting values? It looks like if you cleared |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
When a non-quick-config price set is selected on the back-office membership form, creating a membership fails with
DB Error: constraint violationbecausemembership_type_idis missing from the INSERT. This happens because a stalemembership_type_idvalue from the org/type selector overrides the price set selections.Before
DB Error: constraint violation— membership is not createdAfter
The same steps now correctly create memberships for all selected price set options.
Technical Details
The membership form has two selection modes: an org/type dropdown (
membership_type_id[0]/membership_type_id[1]) and a price set selector. When switching to a price set, JavaScript setsmembership_type_id[1]to0, but a stale value can remain if the user previously browsed membership types.getSelectedMemberships()checksmembership_type_id[1]first:When
membership_type_id[1]has a stale value (e.g.52), only that single type is returned — all price set selections are ignored.getMembershipParameters()then only setsmembership_type_idfor type 52, but the form tries to create memberships for all types from the price set line items, resulting in INSERTs withoutmembership_type_id.The fix adds
&& empty($params['price_set_id'])so that when a price set is active, membership types are always derived from the price field selections instead.Comments
Tested on a site with a non-quick-config membership price set containing 9 fields (Select and CheckBox types) covering 60+ membership types. Verified that all combinations work correctly after the fix.