I'm using CiviCRM 4.5.8 and am setting it up to handle a three year fundraising campaign for our church.
Our church almost exclusively records donations for Households and not for individuals.
How can I create a Contribution Page that allows a person to make Pledges and Contributions that will be linked to their Household?
I am not afraid of custom coding and am currently planning to write a script that automatically shifts all individual pledges to their related household, but if I do that, I still want the contribution page to work for that person to actually make contributions.
Ideally, I'd just use a template override to inject the contact_id of the user's household if there is one or to use the individual contact_id otherwise, but I need some help on how to do that.
I already am comfortable working with template overrides, but I'm asking if anyone knows which template needs to be overridden to get the contact_id in the correct place.
EDIT: SOLUTION CODE
/**
* Implements hook_civicrm_post
*/
function householdcontributions_civicrm_post($op, $objectName, $objectId, &$objectRef) {
// the _post hook is called AFTER the object has been written to the database
// because of that, we need to change the contact_id to the household_contact_id
// and save
if($op == 'create' && $objectName == 'Contribution') {
$current_contact_id = $objectRef->contact_id;
$real_id = $current_contact_id;
// look for a household associated with this contact
$result = civicrm_api3('Relationship', 'get', array(
'sequential' => 1,
'relationship_type_id' => 7,
'contact_id_a' => $current_contact_id
));
// override the contact_id with the newly discovered household id
if ($result['count'] == 1)
{
$household_id = $result['values'][0]['contact_id_b'];
// $objectRef->contact_id = $household['values'][0]['contact_id_b'];
$result = civicrm_api3('Contribution', 'create', array(
'sequential' => 1,
'id' => $objectId,
'contact_id' => $household_id,
));
}
}
}