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) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Contact lookup in Honoree Section
Pages: [1]

Author Topic: Contact lookup in Honoree Section  (Read 2490 times)

civijim

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
Contact lookup in Honoree Section
February 20, 2009, 12:35:22 pm
Hi all, I'm new to Civicrm and have been enjoying getting to know it. I have a scenario where I have an event, participants register, all's good. The participants need to raise a minimum dollar amount prior to the event. I love the new PCP pages which will enable participants to create their personal fundraising pages. I believe I will need to set the link manually in the event registration Thank you page since it only seems to be part of Civicontribute. The majority of donors can get pushed through the users PCP page and I think that should be ok.

However, what about when donors come in to the main Civicontribute page and are looking to contribute for a specific individual who has registered for the event? Or a participant didn't set up a personal PCP page. I can enable the honoree section. There they could type in the name of the event participant but it wouldn't necessarily be a one-to-one match. I would prefer if they can look up and select a participant at that point. It seems to me that this shouldn't be too difficult. I'm thinking maybe I could hack the honoree section to do a custom lookup though I'm not too comfortable doing that.

Any thoughts on what might be the best practice here?

Thank you.
Jim

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Contact lookup in Honoree Section
February 20, 2009, 06:34:09 pm
Jim - It seems like you want to use the "Soft Credit" feature which is associated with PCP's to track the money "raised by participants" - regardless of whether the donor actually came in via a PCP or not. Or, in other words, you want donors who come directly to the main CiviContribute page to be able to select a "participant" (contact) and then have a soft credit for that contribution added for that participant.

There is a new hook in 2.2 which allows you to populate the option values for a custom field from a query (customFieldOptions hook). This could solve part of the problem - since you could add a custom field for the contribution record to expose the participants and store the selected participant's contact id. Then you'd need to trigger a soft credit insert (using the custom field value) - which I think you could do w/ the "post" hook on the contribution record.

This is a bit theoretical - but the nice thing is that you can potentially do it with an external custom module and without hacking an Civi code.

(Other folks should chime in if they can think of better or easier ways to do this ....)

Protect your investment in CiviCRM by  becoming a Member!

civijim

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
Re: Contact lookup in Honoree Section
February 25, 2009, 08:42:03 pm
Dave - thanks for your reply. I have successfully implemented the customfieldoptions hook and am working on the civicrm_post hook which does an insert into civicrm_contribution_soft table. However, my test implementation of the hook gives a white screen on q=civicrm/contribute/transact page. There is nothing in the log file. I'm basically just using the test version to make sure it's "hooking" but it doesn't seem to be..any additional help would be very appreciated. I feel I'm very close! Below is the function call.
Thank you.
Jim

<?php



function swimsoft_civicrm_post( $op, $objectName, $objectId, &$objectRef ) {
    // only interested in the profile object and create operation for now
      // send an email to the user and cc administrator
    // with a welcome message
    civicrm_initialize( true );

    require_once 'CRM/Utils/Mail.php';

    $fromName  = 'My Org Administrator';
    $fromEmail = 'from@myorg.org';
    $from      = CRM_Utils_Mail::encodeAddressHeader( $fromName, $fromEmail );
   
    $toEmail   = $objectRef['email-1'];
    $toName    = "{$objectRef['first_name']} {$objectRef['last_name']}";

    $params    = print_r( $objectRef, true );
    $subject   = "Thank you for supporting My Org";
    $message   = "
Dear $to:

Thank you for your show of support. The details u signed up with are:

$params

Regards

My Org Team
";
    $cc       = 'cc@myorg.org';

    CRM_Utils_Mail::send( $from,
                          $toName,
                          $toEmail,
                          $subject,
                          $message,
                          $cc );
   
}

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: Contact lookup in Honoree Section
February 26, 2009, 06:29:24 am

a white screen typically means a php/mysql/apache error. You will need to find the relevant error message in the log files. without that its a bit hard to help

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

civijim

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
Re: Contact lookup in Honoree Section
February 26, 2009, 06:37:27 am
Thanks. I don't know where else to look besides the main log in the files/upload section but I'll mess around with it.

Am I on the right track in my thinking - basically, hook into civicrm_post with the contribution object and create/edit operation and do a sql insert into civicrm_contribution_soft table? i believe so but I'm unsure when the post hook on the contribution object fires.

Thanks again.
Jim

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: Contact lookup in Honoree Section
February 26, 2009, 06:46:52 am

a white screen is a php / apache error, so it will be in those log files. check with your hosting provider where they are located etc

the post hook is fired after teh contrib object is saved. your approach seems right

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

civijim

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
Re: Contact lookup in Honoree Section
March 04, 2009, 12:29:32 pm
Lobo - thanks for your reply, I've gotten quite far with this now (reading the API documentation was a great help - should have done that first  :)). I've captured the custom field using the custom_field_options hook and pull the soft contributor from the custom table (for some reason it's not being returned in the contribution object even though the field should extend Contribution I believe). Anyway, I'm looking now for a way to take the contactID, contributionID, and amount that I now have for the soft credit and get it into, civicrm_contribution_soft. I didn't see anything in the contribution API for this. Is there one?  Or is a straight insert of the fields into the table on the civicrm_post hook my best option? That hasn't worked out to great for me on the post hook.
Thanks again.
Jim

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Contact lookup in Honoree Section
March 04, 2009, 02:55:53 pm
Jim - Since there's not API functions (yet) for soft credits - you could either:

1. write the API (civicrm_contribution_add) and add it to api/V2/Contribute.php

Basically it would invoke the relevant BAO function:
CRM_Contribute_BAO_Contribution::addSoftContribution()

2. Invoke the BAO directly.
Check CRM/Contribute/Form/Contribution/Confirm.php lines 741-756 for usage pattern of this BAO (i.e. expected $params array format)

If you do #1, please submit a patch for addition to the codebase and add doc / example to the wiki at:
http://wiki.civicrm.org/confluence/display/CRMDOC/Contribution+APIs
Protect your investment in CiviCRM by  becoming a Member!

civijim

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
Re: Contact lookup in Honoree Section
April 18, 2009, 07:52:53 am
Thanks Dave. Finally revisiting this.. So to recap, I'm trying to add a soft contribution without the use of PCP page. Basically, through a donation, the donor would have the option to select a contact to "soft contribute" to. I am currently hooking into the civicrm_post with a module. The hook is fine but it's the time of the hook where I believe the problem lies. I believe since the donation is not complete at this point, I can't add the soft contribution (see below for constraint error).

I am currently doing the following on civicrm_post:

contribSoftParams['contribution_id'] = $contribution->id;
$contribSoftParams['amount']          = $params['amount'];
$contribSoftParams['contact_id'] = $softcontact_id;         
$softContribution = CRM_Contribute_BAO_Contribution::addSoftContribution( $contribSoftParams );

and get the following error on post (on the way to Paypal for payment)..

Array
(
    [callback] => Array
        (
           
  • => CRM_Core_Error
  • [1] => handle
            )

       
Code: [Select]
=> -3
    [message] => DB Error: constraint violation
    [mode] => 16
    [debug_info] => INSERT INTO civicrm_contribution_soft (contact_id ) VALUES ( 13 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`db271905914/civicrm_contribution_soft`, CONSTRAINT `FK_civicrm_contribution_soft_contribution_id` FOREIGN KEY (`contribution_id`) REFERENCES `civicrm_contribution` (`id`) ON DELETE CASCADE)]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_contribution_soft (contact_id ) VALUES ( 13 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`db271905914/civicrm_contribution_soft`, CONSTRAINT `FK_civicrm_contribution_soft_contribution_id` FOREIGN KEY (`contribution_id`) REFERENCES `civicrm_contribution` (`id`) ON DELETE CASCADE)]
    [to_string] => [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_contribution_soft (contact_id ) VALUES ( 13 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`db271905914/civicrm_contribution_soft`, CONSTRAINT `FK_civicrm_contribution_soft_contribution_id` FOREIGN KEY (`contribution_id`) REFERENCES `civicrm_contribution` (`id`) ON DELETE CASCADE)]"]
)

Thanks again.
Jim

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: Contact lookup in Honoree Section
April 18, 2009, 09:05:15 am
1. can u cut-n-paste your entire hook code (enclose it in the code tag)

2. what hook are u implementing

3. where do u get $contribution and $softcontact_id

most likely the issue is you are referencing a non-existent variable $contribution

the contact is created before the contribution, so implementing it as a contact hook is not a good idea. u should probably implement it as a contribution hook

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

civijim

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
Re: Contact lookup in Honoree Section
April 18, 2009, 10:10:31 am
Thanks for the quick reply - below is the whole shebang.
Best,
Jim

Code: [Select]
<?php
function swimsoft_civicrm_post( $op, $objectName, $objectId, &$objectRef ) {
   if ( 
$objectName == 'Contribution' && ( $op == 'create' || $op == 'edit' ) ) {
   
civicrm_initialize( true );

    require_once 
'api/v2/Contribute.php';
require_once 'CRM/Utils/Mail.php';


$qh = mysql_query("select * from civicrm_contribution order by id DESC");
$row = mysql_fetch_array($qh); 
$latest_cont = $row['id']; 

$qi = mysql_query("SELECT * FROM `civicrm_value_swimmer_sponsor_4` ORDER BY `id` DESC");
$rowi = mysql_fetch_array($qi); 
$softswimmer_id = $rowi['swimmername_17']; 

$param2       = array('contribution_id' => $latest_cont);
$contribution =& civicrm_contribution_get($param2);
$param3 = print_r( $contribution, true );

//$softswimmer_id = print_r( $contribution['custom_1'], true);

//mysql_query("DELETE from civicrm_contribution_soft where contribution_id=(select max(id) from civicrm_contribution)");
       

 
//add soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.

        
$contribSoftParams['contribution_id'] = $contribution->id;
                       
            
$contribSoftParams['amount']          = $params['amount'];

$contribSoftParams['contact_id'] = $softswimmer_id;
                   
            
$softContribution = CRM_Contribute_BAO_Contribution::addSoftContribution( $contribSoftParams );
      

    
$fromName  = 'CiviCRM Administrator';
    
$fromEmail = 'info@me.org';
    
$from      = CRM_Utils_Mail::encodeAddressHeader( $fromName, $fromEmail );
    
    
$toEmail   = 'jim@gmail.com';
    
$toName    = 'Jim test';

    
$params    = print_r( $objectRef, true );
 
    
$subject   = "A Donation Has Gone Through";
    
$message   = "
Dear 
$to:

Here are the details..

Params start..

$params

Params end..

and more details..

Param3 start..
$param3
Param3 end..

Donation on behalf of..
softswim start..
$softswimmer_id
softswim end..

or soft id maybe

$soft_id
softid end..
Regards

CiviCRM Team
"
;
    

    
CRM_Utils_Mail::send( $from,
                          
$toName,
                          
$toEmail,
                          
$subject,
                          
$message
                          
);


    }
}

  

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: Contact lookup in Honoree Section
April 18, 2009, 09:03:41 pm

the main issue is $contribution->id is not set. You'll need to debug the code and find out why

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

civijim

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
Re: Contact lookup in Honoree Section
April 19, 2009, 08:20:57 pm
Lobo - thank you. I was able to grab it. However, I have run into a further complication in that the custom data field that I am populating is not getting populated in the table civicrm_value_swimmer_sponsor_4 until after the hook. Shouldn't this information post prior to the hook since the hook is supposed to run after the post. Previously, I thought the table was populating prior to the hook, hence the query in the hook. But now, I'm getting more SQL errors because the custom data field is not getting populated. Is there a separate object I can grab to get this value? My thought is that it should be included in the contribution object. I hope this makes sense.Thanks again. The help is much appreciated.
Jim


Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Contact lookup in Honoree Section

This forum was archived on 2017-11-26.