From 7bf9cde259594168f575a5b58c1dbcd9f492d9f6 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 30 Mar 2013 17:25:32 -0700 Subject: [PATCH] Fix event registration pages CRM-12149 --- CRM/Contribute/Form/Contribution/Main.php | 80 +++++++++++-------- CRM/Event/Form/Registration/Register.php | 36 ++++----- .../CRM/Event/Form/Registration/Register.tpl | 12 ++- 3 files changed, 68 insertions(+), 60 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 8436c828ec..6eb94d59a7 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -68,41 +68,9 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu public function preProcess() { parent::preProcess(); - $this->_snippet = CRM_Utils_Array::value('snippet', $_GET); - $this->assign('snippet', $this->_snippet); - - $paymentProcessors = $this->get('paymentProcessors'); - $this->assign('ppType', FALSE); - $this->_ppType = NULL; - if (!empty($paymentProcessors)) { - // Fetch type during ajax request - if (isset($_GET['type']) && $this->_snippet) { - $this->_ppType = $_GET['type']; - } - // Set default payment processor - else { - foreach ($paymentProcessors as $values) { - if (!empty($values['is_default']) || count($paymentProcessors) == 1) { - $this->_ppType = $values['id']; - } - } - } - if ($this->_ppType) { - $this->assign('ppType', TRUE); - CRM_Core_Payment_ProcessorForm::preProcess($this); - if ($this->_snippet) { - return; - } - } - - //get payPal express id and make it available to template - foreach ($paymentProcessors as $ppId => $values) { - $payPalExpressId = ($values['payment_processor_type'] == 'PayPal_Express') ? $values['id'] : 0; - $this->assign('payPalExpressId', $payPalExpressId); - if ($payPalExpressId) { - break; - } - } + self::preProcessPaymentOptions($this); + if ($this->_snippet) { + return; } // Make the contributionPageID avilable to the template @@ -405,8 +373,10 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu * @access public */ public function buildQuickForm() { + // Build payment processor form if ($this->_ppType) { CRM_Core_Payment_ProcessorForm::buildQuickForm($this); + // Return if we are in an ajax callback if ($this->_snippet) { return; } @@ -1389,5 +1359,45 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey=$qfKey", TRUE, NULL, FALSE)); } } + + /** + * Handle Payment Processor switching + * For contribution and event registration forms + */ + static function preProcessPaymentOptions(&$form) { + $form->_snippet = CRM_Utils_Array::value('snippet', $_GET); + $form->assign('snippet', $form->_snippet); + + $paymentProcessors = $form->get('paymentProcessors'); + $form->assign('ppType', FALSE); + $form->_ppType = NULL; + if (!empty($paymentProcessors)) { + // Fetch type during ajax request + if (isset($_GET['type']) && $form->_snippet) { + $form->_ppType = $_GET['type']; + } + // Set default payment processor + else { + foreach ($paymentProcessors as $values) { + if (!empty($values['is_default']) || count($paymentProcessors) == 1) { + $form->_ppType = $values['id']; + } + } + } + if ($form->_ppType) { + $form->assign('ppType', TRUE); + CRM_Core_Payment_ProcessorForm::preProcess($form); + } + + //get payPal express id and make it available to template + foreach ($paymentProcessors as $ppId => $values) { + $payPalExpressId = ($values['payment_processor_type'] == 'PayPal_Express') ? $values['id'] : 0; + $form->assign('payPalExpressId', $payPalExpressId); + if ($payPalExpressId) { + break; + } + } + } + } } diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index afa155122d..5b7361ef19 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -68,7 +68,8 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { */ public $_skipDupeRegistrationCheck = FALSE; - protected $_ppType; + public $_ppType; + public $_snippet; /** * Function to set variables up before form is built @@ -78,24 +79,10 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { */ function preProcess() { parent::preProcess(); - $this->_ppType = CRM_Utils_Array::value('type', $_GET); - $this->assign('ppType', FALSE); - if ($this->_ppType) { - $this->assign('ppType', TRUE); - return CRM_Core_Payment_ProcessorForm::preProcess($this); - } - - //get payPal express id and make it available to template - $paymentProcessors = $this->get('paymentProcessors'); - $this->assign('payPalExpressId', 0); - if (!empty($paymentProcessors)) { - foreach ($paymentProcessors as $ppId => $values) { - $payPalExpressId = ($values['payment_processor_type'] == 'PayPal_Express') ? $values['id'] : 0; - $this->assign('payPalExpressId', $payPalExpressId); - if ($payPalExpressId) { - break; - } - } + + CRM_Contribute_Form_Contribution_Main::preProcessPaymentOptions($this); + if ($this->_snippet) { + return; } //CRM-4320. @@ -156,7 +143,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { * @return None */ function setDefaultValues() { - if ($this->_ppType && !($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM)) { + if ($this->_ppType && $this->_snippet && !($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM)) { // see function comment block for explanation of this return; } @@ -344,8 +331,13 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { * @access public */ public function buildQuickForm() { + // Build payment processor form if ($this->_ppType) { - return CRM_Core_Payment_ProcessorForm::buildQuickForm($this); + CRM_Core_Payment_ProcessorForm::buildQuickForm($this); + // Return if we are in an ajax callback + if ($this->_snippet) { + return; + } } $contactID = parent::getContactID(); @@ -554,7 +546,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { */ static public function buildAmount(&$form, $required = TRUE, $discountId = NULL) { //if payment done, no need to build the fee block. - if (isset($form->_paymentId) && $form->_paymentId) { + if (!empty($form->_paymentId)) { //fix to diaplay line item in update mode. $form->assign('priceSet', isset($form->_priceSet) ? $form->_priceSet : NULL); return; diff --git a/templates/CRM/Event/Form/Registration/Register.tpl b/templates/CRM/Event/Form/Registration/Register.tpl index 74366a5997..059bdbc4d3 100644 --- a/templates/CRM/Event/Form/Registration/Register.tpl +++ b/templates/CRM/Event/Form/Registration/Register.tpl @@ -23,7 +23,8 @@ | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ *} -{if $ppType} +{* Callback snippet: Load payment processor *} +{if $ppType and $snippet} {include file="CRM/Core/BillingBlock.tpl" context="front-end"}
@@ -144,7 +145,7 @@ {include file="CRM/UF/Form/Block.tpl" fields=$customPre} {if $form.payment_processor.label} -
+ {/if} -
+
+ {* If we have a payment processor, load it - otherwise it happens via ajax *} + {if $ppType} + {include file="CRM/Event/Form/Registration/Register.tpl" snippet=4} + {/if} +
{include file="CRM/common/paymentBlock.tpl"} {include file="CRM/UF/Form/Block.tpl" fields=$customPost} -- 2.25.1