1

I have a parent account which can possess multiple memberships. There can be multiple children which inherit one of these membership. I want to be able to choose which child inherits which membership. I know it's possible via the GUI, but is there a way of doing this programmatically? I tried looking at the API browser, but couldn't find anything.

Thank you!

4
  • I can't see how you can do this but also perhaps you could flesh out the workflow a bit more. A more common scenario is that a parent would pay for a membership and the amount they would pay would depend on the number of children they have who also have the assigned Relationship Type to the parent. Ie all the children maybe 'children of', but if you build the Memb Type to use a relationship of 'Child member of' then it would only be the kids with that latter relationship who would inherit
    – petednz - fuzion
    Feb 11 at 20:49
  • HI! Thank you for your response. I think this would work for our workflow, but how would the price of the membership reflect the amount of relationships. Currently, with our workflow, the user gets put in a pending membership on signup and then are sent the contribution form to pay when they are approved. I was thinking of a price set, but how would I lock in the price to reflect the correct amount of relations? If I used a hook, would the contribution form break if two people tried accessing that form at the same time?
    – user15536
    Feb 17 at 1:18
  • if the pricing is per child then yes it gets trickier. if i was doing this, and since i use Drupal mostly, i would do this via Webform_CiviCRM which can handle that side of things. not sure what other CMS can offer
    – petednz - fuzion
    Feb 17 at 19:58
  • Unfortunately, I am using WordPress. I guess the only way is to create a custom contribution form then maybe?
    – user15536
    Feb 17 at 22:51

1 Answer 1

1

I think you're talking about the feature whereby you can limit the number of contacts that inherit a relationship, and then create/delete the related memberships when viewing the owner membership:

enter image description here

The code behind 'create' is https://github.com/civicrm/civicrm-core/blob/5.71/CRM/Member/Form/MembershipView.php#L109-L128 which basically copies a load of parameters from the owner (parent) membership and creates a new one including the owner_membership_id. APIv4 Membership.create() lets you specify owner_membership_id so it looks like you should be able to do what you want.

So far as I know, this feature is not used much so test your create and delete code carefully.

Since it involves a lot of copying from the owner membership it would be nicer to wrap those up as API actions with their own tests to protect their functionality. I don't know what happens if for example the owner and inherited memberships have different start and end dates. If you create via the UI, the code sets those to be the same but if you do different things via the API you could run into strange effects.

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.