CRM-13282, fixed state default for membership billing block and code cleanup for...
authorkurund <kurund@civicrm.org>
Tue, 27 Aug 2013 12:27:45 +0000 (17:57 +0530)
committerkurund <kurund@civicrm.org>
Tue, 27 Aug 2013 12:27:45 +0000 (17:57 +0530)
----------------------------------------
* 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

CRM/Contribute/Form/Contribution.php
CRM/Event/Form/EventFees.php
CRM/Member/Form/Membership.php

index 98f661b8f30254e6fd47da5776d9194db3774058..194b2c1944d8ad28fc6de9d255aa75f3da4452ee 100644 (file)
@@ -318,7 +318,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
       $defaults = array_merge($defaults, $billingDefaults);
 
-      // now fix all state country selectors (FIXME: what does this do ?? dgg)
+      // now fix all state country selectors, set correct state based on country
       CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     }
 
index 13017940d2d210f0282e9ef2b064ad466a297681..f71d404802bdb7eef87b509d4bae4804fb0065ed 100644 (file)
@@ -126,49 +126,22 @@ class CRM_Event_Form_EventFees {
     }
 
     if ($form->_mode) {
-      $fields = array();
-
-      foreach ($form->_fields as $name => $dontCare) {
-        $fields[$name] = 1;
-      }
-
-      $names = array(
-        'first_name', 'middle_name', 'last_name', "street_address-{$form->_bltID}",
-        "city-{$form->_bltID}", "postal_code-{$form->_bltID}", "country_id-{$form->_bltID}",
-        "state_province_id-{$form->_bltID}",
-      );
-      foreach ($names as $name) {
-        $fields[$name] = 1;
-      }
-
-      $fields["state_province-{$form->_bltID}"] = 1;
-      $fields["country-{$form->_bltID}"] = 1;
-      $fields["email-{$form->_bltID}"] = 1;
-      $fields['email-Primary'] = 1;
-
-      if ($form->_contactId) {
-        CRM_Core_BAO_UFGroup::setProfileDefaults($form->_contactId, $fields, $form->_defaults);
-      }
-
-      // use primary email address if billing email address is empty
-      if (empty($form->_defaults["email-{$form->_bltID}"]) &&
-        !empty($form->_defaults['email-Primary'])
-      ) {
-        $defaults[$form->_pId]["email-{$form->_bltID}"] = $form->_defaults['email-Primary'];
-      }
-
-      foreach ($names as $name) {
-        if (!empty($form->_defaults[$name])) {
-          $defaults[$form->_pId]['billing_' . $name] = $form->_defaults[$name];
-        }
-      }
-
       $config = CRM_Core_Config::singleton();
       // set default country from config if no country set
       if (!CRM_Utils_Array::value("billing_country_id-{$form->_bltID}", $defaults[$form->_pId])) {
         $defaults[$form->_pId]["billing_country_id-{$form->_bltID}"] = $config->defaultContactCountry;
       }
 
+      if (!CRM_Utils_Array::value("billing_state_province_id-{$form->_bltID}", $defaults)) {
+        $defaults[$form->_pId]["billing_state_province_id-{$form->_bltID}"] = $config->defaultContactStateProvince;
+      }
+
+      $billingDefaults = $form->getProfileDefaults('Billing', $form->_contactId);
+      $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $billingDefaults);
+
+      // now fix all state country selectors, set correct state based on country
+      CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults[$form->_pId]);
+
       //             // hack to simplify credit card entry for testing
       //             $defaults[$form->_pId]['credit_card_type']     = 'Visa';
       //             $defaults[$form->_pId]['credit_card_number']   = '4807731747657838';
index 4d760c6f09af8f60447fb6c0b1c8027a262e3c1d..811a7e63575a5706fd0dddd8593779387c9f1fcf 100644 (file)
@@ -420,6 +420,9 @@ class CRM_Member_Form_Membership extends CRM_Member_Form {
 
       $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
       $defaults = array_merge($defaults, $billingDefaults);
+
+      // now fix all state country selectors, set correct state based on country
+      CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
       
       //             // hack to simplify credit card entry for testing
       //             $defaults['credit_card_type']     = 'Visa';