2

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?

1
  • A note for others attempting this, you'll need a condition to check that your hook function isn't also run for the second membership created by this new relationship.
    – schatz
    Commented Sep 21, 2015 at 22:31

1 Answer 1

3

I can think of two approaches.

One - instead of hook_civicrm_post, use use hook_civicrm_postProcess, like you describe, to grab the Contact A id.

Two - use hook_civicrm_post on the Membership object rather than the Contribution object. This should get you Contact B's id. You can then use an API get to look up the most recently created Relationship for Contact B, which should be Contact A. Then use an API create to create your new Relationship.

I'd probably go with option two, personally.

1
  • 2
    Thanks a ton, Jon, option two is exactly what I needed to determine Contact A. Appreciate the help!
    – schatz
    Commented Sep 21, 2015 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.