[#53] Remove duplicate XCM call for individual address

This commit is contained in:
Jens Schuppe 2021-11-09 11:47:40 +01:00
parent f266ff1655
commit 7ff5d18dc0

View file

@ -400,27 +400,6 @@ function civicrm_api3_twingle_donation_Submit($params) {
$contact_data += $custom_fields['Individual']; $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. // Organisation lookup.
if (!empty($params['organization_name'])) { if (!empty($params['organization_name'])) {
$organisation_data = array( $organisation_data = array(
@ -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 // Share organisation address with individual contact, using configured
// location type for organisation address. // location type for organisation address.
$address_shared = ( $address_shared = (
@ -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. // Create employer relationship between organization and individual.
if (isset($organisation_id)) { if (isset($organisation_id)) {
CRM_Twingle_Submission::updateEmployerRelation($contact_id, $organisation_id); CRM_Twingle_Submission::updateEmployerRelation($contact_id, $organisation_id);