Upcoming Events

San Francisco CiviCRM Meetup - March 2010
March 24th, 2010
Come meet others from the Bay Area who are interested in, using or developing (more...)

Campaigning Camp in Oxford, UK
March 25th, 2010
Free (with lunch and tea break included!) CiviCRM/Drupal and Plone two-track (more...)

CiviCRM Seminar - Dublin
March 25th, 2010
MTL Software Solutions are hosting a free seminar at The IBOA, Stephen St (more...)

CiviCRM User Training - Atlanta (pre NTC)
April 7th, 2010
This full-day hands-on training session is aimed at non-profit staff and (more...)

Configuring, Customizing and Extending CiviCRM - San Francisco (before DrupalCon SF)
April 18th, 2010
This hands-on 1-day training session is targeted at administrators, integrators (more...)

CiviCRM User Training - San Francisco (before DrupalCon SF)
April 18th, 2010

This full-day hands-on training session is aimed at non-profit staff and (more...)

CiviCon San Francisco 2010
April 22nd, 2010
Join us for the first ever CiviCon in San Francisco this April! CiviCon brings (more...)

CiviCRM Components

Tools for engaging your supporters...

CiviContribute


CiviEvent


CiviMail


CiviMember


CiviReport


New in 2.2: State-Country widget, customizing event registration amounts for members

Not Just a Contact Database

These optional components give you more power to connect and engage your supporters.

  • civiEVENT

  • Online event registration and participant tracking.

  • civiMEMBER

  • Online signup and membership management.

  • civiMAIL

  • Personalized email blasts and newsletters.

  • civiREPORT

  • Report generation and template management.

November 13, 2008 - 13:47 — lobo

Our global meeting resulted in some new features being added to 2.2. Our team worked on a new jQuery based country/state selector and incorporating hook(s) to the "amount" functionality of online contribution and event registration pages. I'll give a brief description of the feature set and functionality of these projects

New jQuery based State Country widget

Our previous widget was a dojo based combo box widget. Both the country and the state were ajax based combo boxes. The state combo box was dependent on the value chosen in the country combo box. This implementation was quite complex and not easily replicated (hence u did not see the widget in many places). For 2.2 we took a slightly different approach: The country field is a simple html select box (the values are restricted by the countries configured in the admin area). The state selector is now dynamic and refreshed with new values whenever the country is changed. We took inspiration and borrowed a fair part of the code from: Simple chained combobox plugin for jQuery.

This model is much easier to replicate and we've introduced it in a more places including profiles, contribution pages and event registration pages. It was kinda nice to see the number of lines of js code being deleted with this new scheme. We felt quite bad that we did not think of doing it this way to begin with, but you learn as you grow :)

Extending the "amounts" field in transaction pages

One request that we hear quite often is: How do we make prices for an event dynamic, so our members get a 10% discount (or $10 off). Trying to add this logic via the UI did not seem easy since different folks had different requirements. We also wanted to make similar changes to the contribution pages, so an org could tailor the amounts displayed to a logged in user based on their past giving history (i.e. increase the donation amounts displayed if the donor has given significant amounts in the recent past).

We've been incorporating hooks into many places in CiviCRM, and this seemed another good place to use hooks. Deepak and I spent an afternoon reworking the code to facilitate this along with a sample hook implementation. The good news was the code was in pretty good shape that we wrapped the project up quite quickly. We standardized on the amount structure across contributions and events. An example hook implementation which gives a discount to all Student members is as follows:

function civitest_civicrm_buildAmount( $pageType,
                                      &$form,
                                      &$amount ) {

    // lets add an arbitrary amount here, just to show folks                                                                                                   
    // the power of a hook :)                                                                                                                                  
    $amount[1000] = array( 'value'    => 400,
                           'label'     => 'Hook',
                           'amount_id' => 1000 );


    // now lets get a bit more ambitious                                                                                                                       
    // *GOAL*: lets plan to give 20% discount to students                                                                                                      
    $membershipType  = 'Student';
    $discountPercent = 20;

    // get the membership-type-id for the membership-type                                                                                                      
    $membershipTypeId = CRM_Core_DAO::getFieldValue( 'CRM_Member_DAO_MembershipType',
                                                     $membershipType,
                                                     'id',
                                                     'name' );

    // get the logged in user id                                                                                                                               
    $session =& CRM_Core_Session::singleton();
    $userID  = $session->get( 'userID' );

    if ( $userID ) {
        // check if logged in user has 'Student' membership                                                                                                    
        require_once 'CRM/Member/BAO/Membership.php';
        $membership = CRM_Member_BAO_Membership::getContactMembership( $userID, $membershipTypeId, null );

        // If logged in contact is a member as on today, modify the amount                                                                                     
        // to reflect the discount.                                                                                                                            
        if ( CRM_Utils_Array::value( 'is_current_member', $membership ) ) {
            foreach ( $amount as $amountId => $amountInfo ) {
                    $amount[$amountId]['value'] = $amount[$amountId]['value'] -
                        ceil($amount[$amountId]['value'] * $discountPercent / 100);
                    $amount[$amountId]['label'] = $amount[$amountId]['label'] .
                        "\t - with {$discountPercent}% discount (for $membershipType)";
            }
        }
    }
}
( categories: )

Comments

can $membershipType be an array?

we'd like to extend a discount to multiple membership types