Use XCM to create non-shared address records.

This commit is contained in:
Jens Schuppe 2019-01-07 11:51:02 +01:00
parent c7cfba78e7
commit ffd99317df

View file

@ -306,17 +306,19 @@ function civicrm_api3_twingle_donation_Submit($params) {
// Exclude address for now when retrieving/creating the individual contact // Exclude address for now when retrieving/creating the individual contact
// and an organisation is given, as we are checking organisation address // and an organisation is given, as we are checking organisation address
// first and share it with the individual. // first and share it with the individual.
$submitted_address = array(); if (!empty($params['organization_name'])) {
foreach (array( $submitted_address = array();
'street_address', foreach (array(
'postal_code', 'street_address',
'city', 'postal_code',
'country', 'city',
'location_type_id', 'country',
) as $address_component) { 'location_type_id',
if (!empty($params[$address_component])) { ) as $address_component) {
$submitted_address[$address_component] = $params[$address_component]; if (!empty($params[$address_component])) {
unset($params[$address_component]); $submitted_address[$address_component] = $params[$address_component];
unset($params[$address_component]);
}
} }
} }
@ -388,8 +390,11 @@ function civicrm_api3_twingle_donation_Submit($params) {
// Address is not shared, use submitted address with configured location // Address is not shared, use submitted address with configured location
// type. // type.
if (!$address_shared && !empty($submitted_address)) { if (!$address_shared && !empty($submitted_address)) {
$submitted_address['contact_id'] = $contact_id; // Do not use `Address.create` API action in order for XCM to decide
civicrm_api3('Address', 'create', $submitted_address); // whether to create an address.
civicrm_api3('Contact', 'getorcreate', array(
'id' => $contact_id,
) + $submitted_address);
} }
// Create employer relationship between organization and individual. // Create employer relationship between organization and individual.