Skip to content

Commit

Permalink
Merge pull request #9466 from eileenmcnaughton/address
Browse files Browse the repository at this point in the history
CRM-19621 fix address field to show country & state.
  • Loading branch information
eileenmcnaughton authored Nov 30, 2016
2 parents 9ca524a + 1ac900b commit 091ad57
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
22 changes: 6 additions & 16 deletions CRM/Contribute/Form/Contribution/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
24 changes: 21 additions & 3 deletions CRM/Utils/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 091ad57

Please sign in to comment.