From 3986ed4fb61edc075b933fa1fa332063e61330ad Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 29 Nov 2016 23:56:58 +1300 Subject: [PATCH] CRM-19621 fix address field to show country & state. --- CRM/Contribute/Form/Contribution/Confirm.php | 22 ++++++-------------- CRM/Core/Payment/Form.php | 9 ++++++++ CRM/Utils/Address.php | 20 +++++++++++++++--- 3 files changed, 32 insertions(+), 19 deletions(-) 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/Core/Payment/Form.php b/CRM/Core/Payment/Form.php index 1a018fa3e62b..f8e8f1f60e84 100644 --- a/CRM/Core/Payment/Form.php +++ b/CRM/Core/Payment/Form.php @@ -360,6 +360,15 @@ public static function validateCreditCard($values, &$errors, $processorID = NULL * @param bool $reverse */ public static function mapParams($id, $src, &$dst, $reverse = FALSE) { + // Set text version of state & country if present. + // This probably obsolete now as CRM_Utils_Address::getFormattedBillingAddressFieldsFromParameters + // should be capable of calculating the right values for state & country for display. + if (isset($src["billing_state_province_id-{$id}"])) { + $src["billing_state_province-{$id}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($src["billing_state_province_id-{$id}"]); + } + if (isset($src["billing_country_id-{$id}"])) { + $src["billing_country-{$id}"] = CRM_Core_PseudoConstant::countryIsoCode($src["billing_country_id-{$id}"]);; + }; $map = array( 'first_name' => 'billing_first_name', 'middle_name' => 'billing_middle_name', diff --git a/CRM/Utils/Address.php b/CRM/Utils/Address.php index 73210a3df35d..dd355df52d0b 100644 --- a/CRM/Utils/Address.php +++ b/CRM/Utils/Address.php @@ -347,10 +347,24 @@ 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; //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);