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) »
  • Discovering if a contribution is a new or renewed membership
Pages: [1]

Author Topic: Discovering if a contribution is a new or renewed membership  (Read 556 times)

routinet

  • I’m new here
  • *
  • Posts: 7
  • Karma: 0
  • CiviCRM version: Generally up-to-date
  • CMS version: Joomla
  • MySQL version: MySQL 5+
  • PHP version: PHP 5+
Discovering if a contribution is a new or renewed membership
October 17, 2013, 08:01:16 am
I'm working on adding prorated memberships to a particular Civi install.  In hook_civicrm_buildAmount, I'd like to detect if the current contribution page is for a new membership or renewal.  Is there an existing data point available on the $form object?  If not, how else could I expose this information to my code?


routinet

  • I’m new here
  • *
  • Posts: 7
  • Karma: 0
  • CiviCRM version: Generally up-to-date
  • CMS version: Joomla
  • MySQL version: MySQL 5+
  • PHP version: PHP 5+
Re: Discovering if a contribution is a new or renewed membership
October 17, 2013, 01:10:46 pm
This is how I did it:
Code: [Select]
    // access the smarty object
    $this->smarty = CRM_Core_Smarty::singleton();
    // renewal_mode only exists if a renewal membership has been detected
    $renew_mode=$this->smarty->get_template_vars('renewal_mode');
    if ($renew_mode) {
        // membershipTypes appears to be an array of all types available.  If a current membership exists,
        // then that item will have the key 'current_membership', which is YYYY-MM-DD for expiration
    $current_memberships = $this->smarty->get_template_vars('membershipTypes');
    if (count($current_memberships) && array_key_exists('current_membership',$current_memberships[0])) {
    $currentdate=strtotime($current_memberships[0]['current_membership']);
    }
    }

Thanks to dgg and dlobo for pointing me in the right direction.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Discovering if a contribution is a new or renewed membership

This forum was archived on 2017-11-26.