Skip to content

Commit

Permalink
Merge branch 'issue/53'
Browse files Browse the repository at this point in the history
[#53] Duplicate XCM-initiated activites for personal addresses
  • Loading branch information
jensschuppe committed Nov 9, 2021
2 parents cadf895 + 9751e8c commit 1975639
Showing 1 changed file with 25 additions and 34 deletions.
59 changes: 25 additions & 34 deletions api/v3/TwingleDonation/Submit.php
Expand Up @@ -400,27 +400,6 @@ function civicrm_api3_twingle_donation_Submit($params) {
$contact_data += $custom_fields['Individual'];
}

if (!$contact_id = CRM_Twingle_Submission::getContact(
'Individual',
$contact_data,
$profile,
$params
)) {
throw new CiviCRM_API3_Exception(
E::ts('Individual contact could not be found or created.'),
'api_error'
);
}

// Save user_extrafield as contact note.
if (!empty($params['user_extrafield'])) {
civicrm_api3('Note', 'create', array(
'entity_table' => 'civicrm_contact',
'entity_id' => $contact_id,
'note' => $params['user_extrafield'],
));
}

// Organisation lookup.
if (!empty($params['organization_name'])) {
$organisation_data = array(
Expand Down Expand Up @@ -449,6 +428,31 @@ function civicrm_api3_twingle_donation_Submit($params) {
);
}
}
elseif (!empty($submitted_address)) {
$contact_data += $submitted_address;
}

if (!$contact_id = CRM_Twingle_Submission::getContact(
'Individual',
$contact_data,
$profile,
$params
)) {
throw new CiviCRM_API3_Exception(
E::ts('Individual contact could not be found or created.'),
'api_error'
);
}

// Save user_extrafield as contact note.
if (!empty($params['user_extrafield'])) {
civicrm_api3('Note', 'create', array(
'entity_table' => 'civicrm_contact',
'entity_id' => $contact_id,
'note' => $params['user_extrafield'],
));
}

// Share organisation address with individual contact, using configured
// location type for organisation address.
$address_shared = (
Expand All @@ -460,19 +464,6 @@ function civicrm_api3_twingle_donation_Submit($params) {
)
);

// Address is not shared, use submitted address with
// configured location type.
if (!$address_shared && !empty($submitted_address)) {
// Do not use `Address.create` API action, let XCM decide
// whether to create an address.
CRM_Twingle_Submission::getContact(
'Individual',
array('id' => $contact_id) + $submitted_address,
$profile,
$params
);
}

// Create employer relationship between organization and individual.
if (isset($organisation_id)) {
CRM_Twingle_Submission::updateEmployerRelation($contact_id, $organisation_id);
Expand Down

0 comments on commit 1975639

Please sign in to comment.