From: eileenmcnaugton Date: Mon, 3 Aug 2015 02:25:05 +0000 (+1200) Subject: CRM-16955 make payment form load billing defaults on processor change X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=70d1766d84fc6d645a7dce3d73e56db62e30e656;p=civicrm-core.git CRM-16955 make payment form load billing defaults on processor change --- diff --git a/CRM/Core/Payment/Form.php b/CRM/Core/Payment/Form.php index 6ece599a74..a39aa22f1e 100644 --- a/CRM/Core/Payment/Form.php +++ b/CRM/Core/Payment/Form.php @@ -29,14 +29,14 @@ * * @package CRM * @copyright CiviCRM LLC (c) 2004-2015 - * $Id$ - * */ class CRM_Core_Payment_Form { /** - * Add payment fields depending on payment processor. The payment processor can implement the following functions to override the built in fields. + * Add payment fields depending on payment processor. + * + * The payment processor can implement the following functions to override the built in fields. * * - getPaymentFormFields() * - getPaymentFormFieldsMetadata() @@ -349,6 +349,30 @@ class CRM_Core_Payment_Form { return $creditCardTypes; } + /** + * Set default values for the form. + * + * @param CRM_Core_Form $form + * @param int $contactID + */ + public static function setDefaultValues(&$form, $contactID) { + $billingDefaults = $form->getProfileDefaults('Billing', $contactID); + $form->_defaults = array_merge($form->_defaults, $billingDefaults); + + // set default country & state from config if no country set + // note the effect of this is to set the billing country to default to the site default + // country if the person has an address but no country (for anonymous country is set above) + // this could have implications if the billing profile is filled but hidden. + // this behaviour has been in place for a while but the use of js to hide things has increased + if (empty($form->_defaults["billing_country_id-{$form->_bltID}"])) { + $form->_defaults["billing_country_id-{$form->_bltID}"] = CRM_Core_Config::singleton()->defaultContactCountry; + } + if (empty($form->_defaults["billing_state_province_id-{$form->_bltID}"])) { + $form->_defaults["billing_state_province_id-{$form->_bltID}"] = CRM_Core_Config::singleton() + ->defaultContactStateProvince; + } + } + /** * Make sure that credit card number and cvv are valid. * Called within the scope of a QF formRule function diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index 92128a003e..8900cdb662 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -116,38 +116,12 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { } /** - * Set default values for the form. For edit/view mode - * the default values are retrieved from the database - * Adding discussion from CRM-11915 as code comments - * When multiple payment processors are configured for a event and user does any selection changes for them on online event registeration page : - * The 'Register' page gets loaded through ajax and following happens : - * the setDefaults function is called with the variable _ppType set with selected payment processor type, - * so in the 'if' condition checked whether the selected payment processor's billing mode is of 'billing form mode'. If its not, don't setDefaults for billing form and return instead. - * - For payment processors of billing mode 'Notify' - return from setDefaults before the code for billing profile population execution . - * (done this is because for payment processors with 'Notify' mode billing profile form doesn't get rendered on UI) - * - * @return void + * Set default values for the form. */ public function setDefaultValues() { $this->_defaults = array(); $contactID = $this->getContactID(); - $billingDefaults = $this->getProfileDefaults('Billing', $contactID); - $this->_defaults = array_merge($this->_defaults, $billingDefaults); - - $config = CRM_Core_Config::singleton(); - // set default country from config if no country set - // note the effect of this is to set the billing country to default to the site default - // country if the person has an address but no country (for anonymous country is set above) - // this could have implications if the billing profile is filled but hidden. - // this behaviour has been in place for a while but the use of js to hide things has increased - if (empty($this->_defaults["billing_country_id-{$this->_bltID}"])) { - $this->_defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry; - } - - // set default state/province from config if no state/province set - if (empty($this->_defaults["billing_state_province_id-{$this->_bltID}"])) { - $this->_defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince; - } + CRM_Core_Payment_Form::setDefaultValues($this, $contactID); if ($contactID) { $fields = array(); diff --git a/CRM/Financial/Form/Payment.php b/CRM/Financial/Form/Payment.php index 61452dea74..a415b02d1a 100644 --- a/CRM/Financial/Form/Payment.php +++ b/CRM/Financial/Form/Payment.php @@ -55,6 +55,15 @@ class CRM_Financial_Form_Payment extends CRM_Core_Form { CRM_Core_Payment_ProcessorForm::buildQuickForm($this); } + /** + * Set default values for the form. + */ + public function setDefaultValues() { + $contactID = $this->getContactID(); + CRM_Core_Payment_Form::setDefaultValues($this, $contactID); + return $this->_defaults; + } + /** * Add JS to show icons for the accepted credit cards */