Having trouble with memberships created on behalf of an organization that need a different relationship type than Employee of/Employer. I have a suspicion I'm simply approaching it the wrong way.
We have Individual and Institutional membership types. For Institutional memberships, there is a relationship type set of Designate of/Designator. The contribution form for purchasing Institutional memberships uses its own price set and price options set correctly to create that membership.
Included in this contribution form are the 'On Behalf of Organization' profile and the WordPress user account form.
When a new user purchases an Institutional membership the following get created:
- New Individual contact (Contact A).
- New Organization contact (Contact B).
- A new Institutional membership for the Organization.
- A relationship of Employee of/Employer between Contact A and Contact B.
Missing from these is the Designate relationship so that Contact A also inherits the membership. I'm not sure why this relationship isn't created despite the membership type requiring it.
The solution I'm pursuing now relies on implementing
hook_civicrm_post in a plugin and doing some lookups with the API based on the membership object to create this relationship after the fact.
However it seems to be that nothing about Contact A (individual) who made the contribution on behalf of Contact B is available beyond the employee/employer relationship - which might exist for any number of other employees that are not the designate. I especially want to avoid this potential issue.
My expectation would be to find this in that particular Contribution object but no dice. Right now I'm thinking either getting Contact A's contact_id from the pre hook or from the form submission itself.
Is this behaviour a bug or am I missing an obvious setting? If not, surely there is a better way via the API?