added code to insert custom data for soft credits

This commit is contained in:
CiviWare Solutions 2018-12-22 23:05:14 +00:00
parent 7e9c5502f4
commit 6175e0623f
2 changed files with 51 additions and 6 deletions

View File

@ -208,7 +208,7 @@ function _softcreditcustomfields_addCustomDataToForm(&$form, $entityId, $blockId
foreach ($groupTree as $id => $group) { foreach ($groupTree as $id => $group) {
foreach ($group['fields'] as $fldId => $field) { foreach ($group['fields'] as $fldId => $field) {
$groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name']; $groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name'];
$groupTree[$id]['fields'][$fldId]['element_name'] = "soft_credit[$blockId][{$field['element_name']}]"; $groupTree[$id]['fields'][$fldId]['element_name'] = "soft_credit_custom[$blockId][{$field['element_name']}]";
} }
} }
@ -239,12 +239,57 @@ function _softcreditcustomfields_addCustomDataToForm(&$form, $entityId, $blockId
// more handling done in formRule func // more handling done in formRule func
//self::storeRequiredCustomDataInfo($form, $groupTree); //self::storeRequiredCustomDataInfo($form, $groupTree);
$tplGroupTree = CRM_Core_Smarty::singleton() $tplGroupTree = CRM_Core_Smarty::singleton()
->get_template_vars('soft_credit_groupTree'); ->get_template_vars('soft_credit_custom_groupTree');
$tplGroupTree = empty($tplGroupTree) ? [] : $tplGroupTree; $tplGroupTree = empty($tplGroupTree) ? [] : $tplGroupTree;
$form->assign('soft_credit_groupTree', $tplGroupTree + [$blockId => $groupTree]); $form->assign('soft_credit_custom_groupTree', $tplGroupTree + [$blockId => $groupTree]);
// unset the temp smarty var that got created // unset the temp smarty var that got created
$form->assign('dnc_groupTree', NULL); $form->assign('dnc_groupTree', NULL);
} }
// softCredit custom data processing ends .. // softCredit custom data processing ends ..
} }
/**
* Implements hook_civicrm_postProcess().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_postProcess
*/
function softcreditcustomfields_civicrm_postProcess($formName, &$form) {
if ('CRM_Contribute_Form_Contribution' == $formName
&& !($form->getVar('_action') & CRM_Core_Action::DELETE)
) {
$contributionId = $form->getVar('_id');
$params = $form->getVar('_params');
if (empty($params['soft_credit_custom'])) {
return;
}
if (!empty($params['soft_credit_contact_id'])) {
foreach ($params['soft_credit_contact_id'] as $key => $softContactId) {
if ($softContactId
&& isset($params['soft_credit_amount'][$key])
&& !empty($params['soft_credit_custom'][$key])
) {
$softParams = [
'contribution_id' => $contributionId,
'contact_id' => $softContactId,
'amount' => $params['soft_credit_amount'][$key],
'return' => 'id',
];
if (!empty($params['soft_credit_type'][$key])) {
$softParams['soft_credit_type_id'] = $params['soft_credit_type'][$key];
}
try {
$softContributionId = civicrm_api3('ContributionSoft', 'getvalue', $softParams);
$softParams = [
'id' => $softContributionId,
] + $params['soft_credit_custom'][$key];
civicrm_api3('ContributionSoft', 'create', $softParams);
}
catch (Exception $e) {
continue;
}
}
}
}
}
}

View File

@ -3,7 +3,7 @@
{assign var='blockId' value=$smarty.section.i.index} {assign var='blockId' value=$smarty.section.i.index}
<tr id="soft-credit-custom_row-{$blockId}" class="customFieldIgnore {if $blockId gte $showSoftCreditRow}hiddenElement{/if}" > <tr id="soft-credit-custom_row-{$blockId}" class="customFieldIgnore {if $blockId gte $showSoftCreditRow}hiddenElement{/if}" >
<td colspan='3'> <td colspan='3'>
{foreach from=$soft_credit_groupTree.$blockId item=cd_edit key=group_id name=custom_sets} {foreach from=$soft_credit_custom_groupTree.$blockId item=cd_edit key=group_id name=custom_sets}
{if $cd_edit.is_multiple and $multiRecordDisplay eq 'single'} {if $cd_edit.is_multiple and $multiRecordDisplay eq 'single'}
{assign var="isSingleRecordEdit" value=TRUE} {assign var="isSingleRecordEdit" value=TRUE}
{else} {else}
@ -12,7 +12,7 @@
{/if} {/if}
{if $isSingleRecordEdit} {if $isSingleRecordEdit}
<div class="custom-group custom-group-{$cd_edit.name}"> <div class="custom-group custom-group-{$cd_edit.name}">
{include file="CRM/Custom/Form/Edit/CustomData.tpl" customDataEntity='soft_credit'} {include file="CRM/Custom/Form/Edit/CustomData.tpl" customDataEntity='soft_credit_custom'}
</div> </div>
{else} {else}
<div class="custom-group custom-group-{$cd_edit.name} crm-accordion-wrapper crm-custom-accordion {if $cd_edit.collapse_display and !$skipTitle}collapsed{/if}"> <div class="custom-group custom-group-{$cd_edit.name} crm-accordion-wrapper crm-custom-accordion {if $cd_edit.collapse_display and !$skipTitle}collapsed{/if}">
@ -22,7 +22,7 @@
</div><!-- /.crm-accordion-header --> </div><!-- /.crm-accordion-header -->
{/if} {/if}
<div class="crm-accordion-body"> <div class="crm-accordion-body">
{include file="CRM/Custom/Form/Edit/CustomData.tpl" customDataEntity='soft_credit'} {include file="CRM/Custom/Form/Edit/CustomData.tpl" customDataEntity='soft_credit_custom'}
</div> </div>
</div> </div>
{/if} {/if}