diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index 8322940..b95ddc4 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -416,6 +416,20 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { array() ); + $this->add( + 'select', + 'required_address_components', + E::ts('Required address components'), + [ + 'street_address' => E::ts("Street"), + 'postal_code' => E::ts("Postal Code"), + 'city' => E::ts("City"), + 'country' => E::ts("Country"), + ], + FALSE, // is not required + ['class' => 'crm-select2 huge', 'multiple' => 'multiple'] + ); + $this->add( 'textarea', // field type 'custom_field_mapping', // field name diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index f59d236..e6a6642 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -226,7 +226,8 @@ class CRM_Twingle_Profile { 'membership_type_id', 'membership_type_id_recur', 'membership_postprocess_call', - 'newsletter_double_opt_in' + 'newsletter_double_opt_in', + 'required_address_components', ), // Add payment methods. array_keys(static::paymentInstruments()), @@ -300,6 +301,12 @@ class CRM_Twingle_Profile { 'membership_type_id' => NULL, 'membership_type_id_recur' => NULL, 'newsletter_double_opt_in' => NULL, + 'required_address_components' => [ + 'street_address', + 'postal_code', + 'city', + 'country', + ], ) // Add contribution status for all payment methods. + array_fill_keys(array_map(function($attribute) { diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index 1aa4197..ce75369 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -335,14 +335,20 @@ function civicrm_api3_twingle_donation_Submit($params) { } } - // Do not creat a new address if user_country is the only address - // parameter. See issue #47 - if ( - !array_key_exists('street_address', $params) && - !array_key_exists('postal_code', $params) && - !array_key_exists('city', $params) - ) { - unset($params['country']); + // Do not creat a new address if 'country' is the only address + // component. See issue #47 + $required_address_components = + $profile->getAttribute('required_address_components'); + $unset_address_params = False; + foreach ($required_address_components as $req) { + if (empty($params[$req])) { + $unset_address_params = True; + } + } + if ($unset_address_params) { + foreach($required_address_components as $req) { + unset($params[$req]); + } } // Prepare parameter mapping for organisation. diff --git a/templates/CRM/Twingle/Form/Profile.hlp b/templates/CRM/Twingle/Form/Profile.hlp index d83b35e..b4c6ff9 100644 --- a/templates/CRM/Twingle/Form/Profile.hlp +++ b/templates/CRM/Twingle/Form/Profile.hlp @@ -54,6 +54,12 @@ {/ts} {/htxt} +{htxt id='id-required_address_components'} +
{ts domain="de.systopia.twingle"}Select the address components that must be present to create a new address for the contact.{/ts}
+{ts domain="de.systopia.twingle"}Depending on your XCM settings, the newly transferred address will replace the old one. This behavior may be intentional, as you always want to have the most current address.{/ts}
+{ts domain="de.systopia.twingle"}ATTENTION: In some cases Twingle sends only the country of the user. If no other address components are selected in the required address components, the current user address will be overwritten with an address containing only the country, depending on the XCM settings.{/ts}
+{/htxt} + {htxt id='id-custom_field_mapping'} {ts domain="de.systopia.twingle"}Map Twingle custom fields to CiviCRM custom fields using the following format (each assignment in a separate line):
twingle_field_1=custom_123diff --git a/templates/CRM/Twingle/Form/Profile.tpl b/templates/CRM/Twingle/Form/Profile.tpl index f5e95f5..49a0097 100644 --- a/templates/CRM/Twingle/Form/Profile.tpl +++ b/templates/CRM/Twingle/Form/Profile.tpl @@ -290,6 +290,27 @@
twingle_field_2=custom_789