CRM-18397: Don't add empty billing name to non-existent billing address
authorJKingsnorth <john@johnkingsnorth.co.uk>
Tue, 12 Apr 2016 15:36:15 +0000 (16:36 +0100)
committerJKingsnorth <john@johnkingsnorth.co.uk>
Tue, 12 Apr 2016 15:36:15 +0000 (16:36 +0100)
CRM/Event/Form/Registration/Confirm.php

index 0485d4c6a1578b290fceb99b0897d8813ad3fb7a..1ef3429c1e185c04170d6a7499f62f54a2a2df1e 100644 (file)
@@ -1052,6 +1052,9 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
       }
     }
 
+    // If there's no 'first_name' in the profile then overwrite the names from
+    // the billing fields (if they are set)
+    // @todo This logic is flawed, at least check each field??
     if (is_array($fields)) {
       if (!array_key_exists('first_name', $fields)) {
         $nameFields = array('first_name', 'middle_name', 'last_name');
@@ -1065,11 +1068,12 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
       }
     }
 
-    // also add location name to the array
-    if ($form->_values['event']['is_monetary']) {
+    // Add the billing names to the billing address, if a billing name is set
+    if ($form->_values['event']['is_monetary'] && !empty($params['billing_first_name'])) {
       $params["address_name-{$form->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params);
       $fields["address_name-{$form->_bltID}"] = 1;
     }
+
     $fields["email-{$form->_bltID}"] = 1;
     $fields['email-Primary'] = 1;