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) »
  • Dicount for Members in Event registration
Pages: [1]

Author Topic: Dicount for Members in Event registration  (Read 1218 times)

jeevajoy

  • I’m new here
  • *
  • Posts: 18
  • Karma: 0
  • CiviCRM version: 4
  • CMS version: joomal 1.6
  • MySQL version: 5
  • PHP version: 5
Dicount for Members in Event registration
December 08, 2011, 07:36:12 am
Hello there,

I'm trying to give discount for current members for event registration. i used builAmount hook. And it shows discounted amount in the register page but not in the confirm page. any idea??

here is my code

function civicrm_event_discount_civicrm_buildAmount($pageType, &$form,&$amount) {   
   
    if($pageType == 'event'  )   {
      require_once 'api/api.php';
      require_once 'api/v3/Contact.php';
        require_once 'api/v3/Membership.php';
   
      $email= $_GET["email"];
      //$email="smithchris@redimail.org"; //currrent_membership=0
      //$email="patelmonica@indiatimes.edu.in";   //currrent_membership=1 
     
      $contacts=civicrm_api("Contact","get", array ('q' =>'civicrm/ajax/rest', 'version' =>'3', 'email' =>$email));
         
        foreach($contacts['values'] as $key=>$value){     
        $contactId= $key;
         }
         
        //print_r($form);exit;
        $membership=civicrm_api("Membership","get", array ('q' =>'civicrm/ajax/rest', 'version' =>'3', 'contact_id' =>$contactId));
         
        foreach($membership['values'] as $k=>$v){         
        $memId=$k;       
        $statusid = $membership['values'][$memId]['status_id'];               
                                                                           

        $results=civicrm_api("MembershipStatus","get", array ('q' =>'civicrm/ajax/rest', 'version' =>'3', 'id' =>$statusid ));
       
       
        $current=$results['values'][$statusid]['is_current_member'];
        }
         
          $defaults['email-5'] = $email;             
          $form->setDefaults( $defaults );
        if($current == 1)  {
        $discountPercent = 20;
        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 Current Memberships)";
            }
            //print_r($amount);exit;
           }
        else{
        $msg="Sorry! No Discount. You are not a Member";
        $form->assign('Not',$msg); 
        return;
        }
       
    }
   }

Anyone pls help..

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: Dicount for Members in Event registration
December 08, 2011, 09:52:58 am

please take a look at the code here:

http://drupal.org/project/civievent_discount

It has the code you need for this and u'll need to understand and adapt it

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

jeevajoy

  • I’m new here
  • *
  • Posts: 18
  • Karma: 0
  • CiviCRM version: 4
  • CMS version: joomal 1.6
  • MySQL version: 5
  • PHP version: 5
Re: Dicount for Members in Event registration
December 09, 2011, 02:44:49 am
Thank you.


Jeeva

cognoscento

  • I post occasionally
  • **
  • Posts: 44
  • Karma: 1
  • CiviCRM version: 4.2
  • CMS version: Drupal 7.17
  • MySQL version: 5.1.65
  • PHP version: 5.3.17
Re: Dicount for Members in Event registration
January 18, 2012, 05:42:51 pm
Jeevajoy--

Would you be willing to share your finished code? I'd like to do the exact same thing...

C.

Jag

  • I’m new here
  • *
  • Posts: 12
  • Karma: 0
  • CiviCRM version: 4.0
  • CMS version: Drupal 7.8
  • MySQL version: 5.5.8
  • PHP version: 5.3.5
Re: Dicount for Members in Event registration
February 14, 2012, 09:01:46 am
Yes. can i have your email Id so that i can forward the module.

Sorry for the late reply.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Dicount for Members in Event registration

This forum was archived on 2017-11-26.