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) »
  • Inserting a contribution
Pages: [1]

Author Topic: Inserting a contribution  (Read 722 times)

ghornet

  • Guest
Inserting a contribution
July 29, 2010, 03:32:19 pm
I would like to know where in the code that civicontribute is actually inserting an approved donation. I would like to add an extra SQL statement right after this with a few more pieces of information, to a different database. Can someone point me in the right direction.

Edit: I suppose I could make a new module, but I have not done that yet. I am going to research that.

Damian
« Last Edit: July 29, 2010, 03:40:33 pm by ghornet »

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Inserting a contribution
July 29, 2010, 03:45:20 pm
You'll want to use a hook to do this.

http://en.flossmanuals.net/CiviCRM/DevelopIntro
http://wiki.civicrm.org/confluence/display/CRMDOC32/CiviCRM+hook+specification
Protect your investment in CiviCRM by  becoming a Member!

ghornet

  • Guest
Re: Inserting a contribution
July 29, 2010, 04:21:43 pm
Alright I made a hook and installed it.

I just want to make sure that I have the basic structure of what I should be doing down.

function add_votes_after_contribution_civicrm_post($op, $objectName, $objectId, &$objectRef) {

//This function will allow me to capture and manipulate data after a contribution has been made

}

I should start this function with
if $objectName != "contribution" then continue with the process

The data I want is &$objectref, this should hold all of the information from the form such as donation amount, name, address, etc...

Thanks



ghornet

  • Guest
Re: Inserting a contribution
July 29, 2010, 04:55:37 pm
Well I am super lost, but I will keep going at it. If anyone wants to help out and show me some code I can work with I would greatly appreciate it. This is what I am trying to do.

1. ) Accept contribution
2. ) Capture the following
  • Contribution amount
  • Custom Field called custom1
  • Custom Field called custom2
  • User ID
3.) Insert that data into another database.

Once I have the 4 pieces of data I can get it into the database no problem, but I am very unfamiliar with getting information from hooks.

From my reading around this is what I have made so far.
function add_votes_after_contribution_civicrm_post($op, $objectName, $objectId, &$objectRef) {

 if ($objectName == 'Contribution' && $op == 'create')
{
  $get_params = array('entityID' => $objectRef['user_id'], $custom_fields['custom1'] => 1, $custom_fields['custom2'] => 1);
  require_once 'CRM/Core/BAO/CustomValueTable.php';
  $values = CRM_Core_BAO_CustomValueTable::getValues($get_params);
  $cust1 = $values[$custom_fields['custom1']];
  $cust2 = $values[$custom_fields['custom2']];

}
}

Thanks,

Damian




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: Inserting a contribution
July 29, 2010, 07:01:47 pm

based on what u need to capture, i suspect you are better off using the postProcess hook rather than the post hook. this will give you the custom field values also

you can look at drupal/civitest.module.sample for sample implementations of that hook

if you need more help, might be faster and easier to hire someone from http://civicrm.org/professional/

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Inserting a contribution

This forum was archived on 2017-11-26.