diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 92d975a5d4a8..5f3a119cb6db 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -320,23 +320,13 @@ public function preProcess() { if (!empty($this->_membershipBlock)) { $this->_params['selectMembership'] = $this->get('selectMembership'); } - if (!empty($this->_paymentProcessor)) { - if ($this->_paymentProcessor['object']->supports('preApproval')) { - $preApprovalParams = $this->_paymentProcessor['object']->getPreApprovalDetails($this->get('pre_approval_parameters')); - $this->_params = array_merge($this->_params, $preApprovalParams); + if (!empty($this->_paymentProcessor) && $this->_paymentProcessor['object']->supports('preApproval')) { + $preApprovalParams = $this->_paymentProcessor['object']->getPreApprovalDetails($this->get('pre_approval_parameters')); + $this->_params = array_merge($this->_params, $preApprovalParams); - // We may have fetched some billing details from the getPreApprovalDetails function so we - // want to ensure we set this after that function has been called. - CRM_Core_Payment_Form::mapParams($this->_bltID, $preApprovalParams, $this->_params, FALSE); - } - - // Set text version of state & country if present. - if (!empty($this->_params["billing_state_province_id-{$this->_bltID}"])) { - $this->_params["state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]); - } - if (!empty($this->_params["billing_country_id-{$this->_bltID}"])) { - $this->_params["country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]); - } + // We may have fetched some billing details from the getPreApprovalDetails function so we + // want to ensure we set this after that function has been called. + CRM_Core_Payment_Form::mapParams($this->_bltID, $preApprovalParams, $this->_params, FALSE); } $this->_params['is_pay_later'] = $this->get('is_pay_later'); diff --git a/CRM/Utils/Address.php b/CRM/Utils/Address.php index 73210a3df35d..3f4a7ab36cb7 100644 --- a/CRM/Utils/Address.php +++ b/CRM/Utils/Address.php @@ -347,10 +347,28 @@ public static function getFormattedBillingAddressFieldsFromParameters($params, $ $addressFields = array(); foreach ($addressParts as $name => $field) { - $addressFields[$name] = CRM_Utils_Array::value($field, $params); + $value = CRM_Utils_Array::value($field, $params); + $alternateName = 'billing_' . $name . '_id-' . $billingLocationTypeID; + $alternate2 = 'billing_' . $name . '-' . $billingLocationTypeID; + if (isset($params[$alternate2]) && !isset($params[$alternateName])) { + $alternateName = $alternate2; + } //Include values which prepend 'billing_' to country and state_province. - if (empty($params[$field])) { - $addressFields[$name] = CRM_Utils_Array::value('billing_' . $field, $params); + if (CRM_Utils_Array::value($alternateName, $params)) { + if (empty($value) || !is_numeric($value)) { + $value = $params[$alternateName]; + } + } + if (is_numeric($value) && $name == 'state_province' || $name == 'country') { + if ($name == 'state_province') { + $addressFields[$name] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($value); + } + if ($name == 'country') { + $addressFields[$name] = CRM_Core_PseudoConstant::countryIsoCode($value); + } + } + else { + $addressFields[$name] = $value; } } return CRM_Utils_Address::format($addressFields);