From 9c86599ca1033a60e2bdf5db4f9da2446ba60d2a Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 29 Nov 2016 23:56:58 +1300 Subject: [PATCH 1/2] CRM-19621 fix address field to show country & state. --- CRM/Contribute/Form/Contribution/Confirm.php | 22 +++++------------- CRM/Utils/Address.php | 24 +++++++++++++++++--- 2 files changed, 27 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/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); From 1ac900b2af01eb94ee16c434f4950a48b8652e6e Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Wed, 30 Nov 2016 17:34:59 +0530 Subject: [PATCH 2/2] Fix if condition for country --- CRM/Utils/Address.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Utils/Address.php b/CRM/Utils/Address.php index 3f4a7ab36cb7..8b48e41ef13f 100644 --- a/CRM/Utils/Address.php +++ b/CRM/Utils/Address.php @@ -359,7 +359,7 @@ public static function getFormattedBillingAddressFieldsFromParameters($params, $ $value = $params[$alternateName]; } } - if (is_numeric($value) && $name == 'state_province' || $name == 'country') { + if (is_numeric($value) && ($name == 'state_province' || $name == 'country')) { if ($name == 'state_province') { $addressFields[$name] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($value); }