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) »
  • Which Form when using a payment on Event Registration
Pages: [1]

Author Topic: Which Form when using a payment on Event Registration  (Read 715 times)

zesgar

  • I post occasionally
  • **
  • Posts: 107
  • Karma: 2
  • CiviCRM version: 4.3.4
  • CMS version: Joomla 2.5
Which Form when using a payment on Event Registration
February 26, 2011, 04:44:12 pm
I am using a parent/child type of event registration and hooks.  I have the following code which works great if the participant selects pay later.  If the participant chooses to pay online through our payment processor:paypal, It doesn't add the  child to any of the groups or relationships. It adds the parent as a contact.  It is getting hung up on finding the submitters ID I believe. Which it has no problem doing if it is on the register form and not confirm...w/payment

--> 

Before we added the payment option everything worked great if the post process form was set to
Code: [Select]
CRM_Event_Form_Registration_RegisterWe added the payment which added the confirm page
Code: [Select]
CRM_Event_Form_Registration_Confirmbut now i am trying to figure out how to get everything to work again.  I know the code works with no payment options.  It is adding the custom data into the contact custom fields in the child record but is not getting to the insert parent contact or anything past  that...I'm hoping it is as simple as just changing the Registration_$Form.....

Code: [Select]
<?php

/*
 * When Contribution Confirm form is submitted
 * 
 * When the contribution page is submitted we want to add a parent contact 
 * we add them to groups and register the camper for the event. 
 * Then we create a relationship between the parent and camper.
 */

function joomla_civicrm_postProcess ( $class, &$form ) {

if ( ! 
is_a($form, 'CRM_Event_Form_Registration_Confirm') ) {
return;
}

//CRM_Core_Error::debug( $form );


require_once 'CRM/Core/Config.php';
$config =& CRM_Core_Config::singleton( );

require_once 
"api/v2/Contact.php";
require_once 
"api/v2/Relationship.php";
require_once 
"api/v2/GroupContact.php";




$params = $form->controller->exportValues( $form->getName( ) );
// get contact of the submitter - it doesn't show up in the $form if it's an anon user
$indivParams = array ( 
'email' => $params['email-5'],
'contact_type' => 'Individual',
);
$indivResult = civicrm_contact_search( $indivParams );

if ( 
civicrm_error ($indivResult )) { return $indivResult['error_message']; } 
else {

foreach ($indivResult as $indiv) {
foreach ($indiv as $ind) {
$submitterID = $indiv['contact_id'];
}
}
}



// create contacts for parent
$contactParams2 = array(
                    
'first_name'    => $params['custom_5'],
                    
'last_name'     => $params['custom_6'],
                    
'email'         => $params['custom_7'],
'contact_sub_type' => 'Parent',
                    
'contact_type'  => 'Individual',
                    
'dupe_check'    => True,
                    );
$contact2 = &civicrm_contact_create( $contactParams2 ); // returns contact id, is_error

$homePhone = array('phone'         => $params['custom_8'],
                           
'phone_type_id' => 1,
                           
'location_type_id' => 1
                           
);
$mobilePhone = array('phone'         => $params['custom_5'],
                           
'phone_type_id' => 2,
                           
'location_type_id' => 1
                           
);
 $address = array( 1 => array( 'location_type_id'       => 1,
                                      
'is_primary'             => 1,
                                      
'city'                   => $params['city-1'],
                                      
'state_province'         => $params['state_province-1'],
                                      
'street_address'         => $params['street_address-1'],
                                      
'postal_code_suffix'     => $params['postal_code-1'],
                                      
'country_id'             => 1228
                                     
)
                        );
 
  // Put them in an array and then add to $params array
        
$phones = array( $homePhone, $mobilePhone);
        
$paramsContact = array('version'    => '3.0',
                        
'contact_id' => $contact2['contact_id'],
                        
'phone'      => $phones,
                        
'address'    => $address
                        
);
        require_once 
'api/v2/Location.php';
        
$newLocation =& civicrm_location_add($paramsContact);
        if( 
civicrm_error( $newLocation ) ) {
            echo 
'Error occured while creating Location';
        } else {
            echo 
'Location Created';
        }

print_r($contact2['contact_id']);
print_r($submitterID);
if ( civicrm_error ( $contact2)) { return $contact2['error_message']; }


// add parent to parents group
add_to_group(1,$contact2['contact_id']);


// add camper to the camper group
add_to_group(2,$submitterID);

//CRM_Core_Error::debug($form);

if ($params['is_online_registration'] == 0) {
$contactbID = $relatedOrgID;
$reltype = 4; // DOC company membership
} else {
// if no org was set we still want to create a relationship
$contactbID = $submitterID;
$reltype = 1; // child
}







// we want to set the default relationships for each contact as set above
add_relationship($submitterID,$contact2['contact_id'],1);








} 
//end associated_members_civicrm_postProcess()

function add_to_group($groupID, $contactID) {

$groupParams = array(
                    
'contact_id' => $contactID,
                    
'group_id'     => $groupID
                    
);
$groupResult = civicrm_group_contact_add( $groupParams );
print_r($groupResult);
print_r($groupID);
print_r($contactID);
}

function 
add_relationship($contactaID,$contactbID,$relationshipType) {

$relationshipParams = array(
                    
'contact_id_a'         => $contactaID,
                    
'contact_id_b'         => $contactbID,
                    
'relationship_type_id' => $relationshipType,
                    
'is_active'            => 1
                    
);
$relationshipCreate = &civicrm_relationship_create( $relationshipParams );
if ( civicrm_error ( $relationshipCreate )) { 
return $relationshipCreate['error_message']; 
}
}
?>

here is the live website.... we are taking registrations with and just manually adding the parent for now....  http://foundationretreat.com/camp-info/sign-up
« Last Edit: February 26, 2011, 05:17:52 pm by zesgar »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Which Form when using a payment on Event Registration

This forum was archived on 2017-11-26.