From: Dave Greenberg Date: Fri, 23 Aug 2013 23:03:00 +0000 (-0700) Subject: CRM-13282 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=cc8ff73de32269a38b32c4e36a91bc9d04609df2;p=civicrm-core.git CRM-13282 ---------------------------------------- * CRM-13282: Prefill billing address on back-office contribution via credit card and membership via credit card using profile.get api http://issues.civicrm.org/jira/browse/CRM-13282 --- diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index bee2ee4abe..98f661b8f3 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -315,34 +315,10 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince; } - $names = array( - 'first_name', - 'middle_name', - 'last_name', - "street_address-{$this->_bltID}", - "city-{$this->_bltID}", - "postal_code-{$this->_bltID}", - "country_id-{$this->_bltID}", - "state_province_id-{$this->_bltID}", - "state_province-{$this->_bltID}", - "country-{$this->_bltID}" - ); - - foreach ($names as $name) { - $fields[$name] = 1; - } - - if ($this->_contactID) { - CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $defaults); - } - - foreach ($names as $name) { - if (!empty($defaults[$name])) { - $defaults['billing_' . $name] = $defaults[$name]; - } - } + $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID); + $defaults = array_merge($defaults, $billingDefaults); - // now fix all state country selectors + // now fix all state country selectors (FIXME: what does this do ?? dgg) CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); } diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 120902d575..4d760c6f09 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -408,46 +408,19 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $this->assign('is_pay_later', TRUE); } if ($this->_mode) { - $fields = array(); - - foreach ($this->_fields as $name => $dontCare) { - $fields[$name] = 1; + // set default country from config if no country set + $config = CRM_Core_Config::singleton(); + if (!CRM_Utils_Array::value("billing_country_id-{$this->_bltID}", $defaults)) { + $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry; } - $names = array( - 'first_name', - 'middle_name', - 'last_name', - "street_address-{$this->_bltID}", - "city-{$this->_bltID}", - "postal_code-{$this->_bltID}", - "country_id-{$this->_bltID}", - "state_province_id-{$this->_bltID}", - ); - foreach ($names as $name) { - $fields[$name] = 1; - } - $fields["state_province-{$this->_bltID}"] = 1; - $fields["country-{$this->_bltID}"] = 1; - $fields["email-{$this->_bltID}"] = 1; - $fields['email-Primary'] = 1; - if ($this->_contactID) { - CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $this->_defaults); - } - - // use primary email address if billing email address is empty - if (empty($this->_defaults["email-{$this->_bltID}"]) && - !empty($this->_defaults['email-Primary']) - ) { - $defaults["email-{$this->_bltID}"] = $this->_defaults['email-Primary']; - } - - foreach ($names as $name) { - if (!empty($this->_defaults[$name])) { - $defaults['billing_' . $name] = $this->_defaults[$name]; - } + if (!CRM_Utils_Array::value("billing_state_province_id-{$this->_bltID}", $defaults)) { + $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince; } + $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID); + $defaults = array_merge($defaults, $billingDefaults); + // // hack to simplify credit card entry for testing // $defaults['credit_card_type'] = 'Visa'; // $defaults['credit_card_number'] = '4807731747657838';