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 (Moderator: Donald Lobo) »
  • Only allowing current membership type on renewal
Pages: [1]

Author Topic: Only allowing current membership type on renewal  (Read 1273 times)

IamPersistent

  • Guest
Only allowing current membership type on renewal
May 05, 2009, 10:45:44 pm
I'm looking to restrict the user to only renew their current membership type.  It would be okay if on their membership type is displayed in the radio button list, but it would be better to just remind the user of the membership type.  Any thoughts on how to do this?

Richard

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Only allowing current membership type on renewal
May 06, 2009, 04:12:51 pm
Richard:

You might want to use buildForm hook for this. We also did minor code fixes for this check: http://fisheye.civicrm.org/changelog/CiviCRM/?cs=21042

Hook implementation:
Quote
/**
 * buildForm hook that would allow contacts to renew only existing memberships.
 */
function civitest_civicrm_buildForm( $formName, &$form ) {
    if ( $formName == 'CRM_Contribute_Form_Contribution_Main' ) {
        if ( is_array( $form->_membershipBlock ) ) {
            //get logged in contact
            $session   = & CRM_Core_Session::singleton();
            $contactID = $session->get('userID');
           
            //check for existing membership
            $query = "SELECT membership_type_id
                      FROM civicrm_membership
                      WHERE membership_type_id IN ( {$form->_membershipBlock['membership_types']} )
                         AND civicrm_membership.contact_id = {$contactID}";
            $dao = CRM_Core_DAO::executeQuery( $query );

            $membershipTypeID = null;
            while ( $dao->fetch( ) ) {
                $membershipTypeID = $dao->membership_type_id;
            }

            if ( $membershipTypeID ) {
                $form->freeze(array('selectMembership'));   
                $defaults['selectMembership'] = $membershipTypeID;
                $form->setDefaults( $defaults );
            }   
        }
    }
}

HTh

Kurund
« Last Edit: May 06, 2009, 04:23:28 pm by Kurund Jalmi »
Found this reply helpful? Support CiviCRM

IamPersistent

  • Guest
Re: Only allowing current membership type on renewal
May 13, 2009, 04:18:31 am
I hate to show my ignorance, but do I put that function into /civicrm/drupal/civicrm.module?  If so, it doesn't seem to be working.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Only allowing current membership type on renewal

This forum was archived on 2017-11-26.