CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • hook_civicrm_membershipTypeValues() not always called
Pages: [1]

Author Topic: hook_civicrm_membershipTypeValues() not always called  (Read 758 times)

wellebee

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
  • CiviCRM version: 4.4
  • CMS version: Drupal 6/7
  • MySQL version: 5.1
  • PHP version: 5.3
hook_civicrm_membershipTypeValues() not always called
October 10, 2012, 04:05:19 pm
I'm trying to get the cividiscount extension working and I'm having a problem with getting access to pricing for membership purchases. We have overridden hook_civicrm_membershipTypeValues() to modify the price and label of memberships when a discount code is entered. Unfortunately, the hook isn't always called when a membership is purchased.

Using the main contribution form 'Membership and Renewal' in a standard test site calls the hook, with a flow something like:

civicrm/contribute/transact?reset=1&id=2 ->
CRM_Event_Form_Registration_Register ->
CRM_Member_BAO_Membership::buildMembershipTypeValues() ->
CRM_Utils_Hook::membershipTypeValues()


But when I submit a credit card membership using the contact tab form, the hook isn't called. The data flow is something like:

civicrm/contact/view [submit credit card membership] ->
civicrm/contact/view/membership?reset=1&action=add&cid=69&context=membership&mode=live
CRM_Member_Form_Membership ->
buildCustomData() [ajax call]->
civicrm/ajax/memType ->
CRM_Member_Page_AJAX::getMemberTypeDefaults()

Unfortunately this last call directly injects the price onto the form with no hook called.

Looking for suggestions for how to proceed. Thanks.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: hook_civicrm_membershipTypeValues() not always called
October 10, 2012, 05:20:16 pm

hey wellebee:

can you file an issue and submit a patch which ensures that the hook is called even via ajax

Should be fairly easy to do and we can commit it to v4.2 fairly quickly

lobo

A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

wellebee

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
  • CiviCRM version: 4.4
  • CMS version: Drupal 6/7
  • MySQL version: 5.1
  • PHP version: 5.3
Re: hook_civicrm_membershipTypeValues() not always called
October 10, 2012, 06:30:32 pm
Thanks for your reply.

Opened as http://issues.civicrm.org/jira/browse/CRM-11028
« Last Edit: October 10, 2012, 07:15:55 pm by wellebee »

wellebee

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
  • CiviCRM version: 4.4
  • CMS version: Drupal 6/7
  • MySQL version: 5.1
  • PHP version: 5.3
Re: hook_civicrm_membershipTypeValues() not always called
October 11, 2012, 03:31:40 pm
Hey lobo:

It looks like there is more to it than that and I haven't been able to sort it out.

CRM_Utils_Hook::membershipTypeValues(&$form, &$membershipTypeValues) has to pass the form which is later submitted, and I haven't been able to figure out if that is even possible from CRM_Member_Page_AJAX::getMemberTypeDefaults(). [I suspect it is not possible.]

The most natural place to integrate CRM_Utils_Hook::membershipTypeValues() might be in CRM_Member_Form_Membership but I spent some time looking at it, and it's not clear to me how to do it.

If I'm making this too complicated, kindly give me a hint.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: hook_civicrm_membershipTypeValues() not always called
October 11, 2012, 08:38:21 pm

so seems like the backend form does things in a very very different way than the front end form and hence does not make it as hook friendly as the frontend form :(

In the first form, we process all values at once (and hence send it to the hook), in the backend form we do this via ajax, one membership at a time

wanna get on irc tomorrow and maybe we can chat and figure out a solution

thanx

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • hook_civicrm_membershipTypeValues() not always called

This forum was archived on 2017-11-26.