From 5ec4b965c1778cfc861a75e9a1da9d8431a899b5 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 24 Nov 2015 17:48:09 +1300 Subject: [PATCH] CRM-16929 fix hiding on zero dollar contribution pages & events Change-Id: I204b087279a8d5170057b1e2b06d57ed1508127f --- .../Registration/AdditionalParticipant.php | 9 +- CRM/Event/Form/Registration/Register.php | 19 ++-- .../CRM/Contribute/Form/Contribution/Main.tpl | 68 ------------ .../CRM/Event/Form/Registration/Register.tpl | 103 ++---------------- templates/CRM/Price/Form/Calculate.tpl | 5 +- templates/CRM/common/paymentBlock.tpl | 54 +++++++++ 6 files changed, 81 insertions(+), 177 deletions(-) diff --git a/CRM/Event/Form/Registration/AdditionalParticipant.php b/CRM/Event/Form/Registration/AdditionalParticipant.php index 0f9190decb..5699a977b2 100644 --- a/CRM/Event/Form/Registration/AdditionalParticipant.php +++ b/CRM/Event/Form/Registration/AdditionalParticipant.php @@ -556,10 +556,11 @@ class CRM_Event_Form_Registration_AdditionalParticipant extends CRM_Event_Form_R CRM_Core_Form::validateMandatoryFields($self->_fields, $fields, $errors); - // validate supplied payment instrument values (e.g. credit card number and cvv) - $payment_processor_id = $self->_params[0]['payment_processor']; - CRM_Core_Payment_Form::validatePaymentInstrument($payment_processor_id, $self->_params[0], $errors, (!$self->_isBillingAddressRequiredForPayLater ? NULL : 'billing')); - + if (isset($self->_params[0]['payment_processor'])) { + // validate supplied payment instrument values (e.g. credit card number and cvv) + $payment_processor_id = $self->_params[0]['payment_processor']; + CRM_Core_Payment_Form::validatePaymentInstrument($payment_processor_id, $self->_params[0], $errors, (!$self->_isBillingAddressRequiredForPayLater ? NULL : 'billing')); + } if (!empty($errors)) { return FALSE; } diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index 89c6f573ed..f5f38e1a68 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -126,6 +126,9 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { */ public function setDefaultValues() { $this->_defaults = array(); + if (!$this->_allowConfirmation && $this->_requireApproval) { + $this->_defaults['bypass_payment'] = 1; + } $contactID = $this->getContactID(); CRM_Core_Payment_Form::setDefaultValues($this, $contactID); @@ -333,6 +336,10 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { } } + if (!$this->_allowConfirmation) { + $bypassPayment = TRUE; + } + //hack to allow group to register w/ waiting if ((!empty($this->_values['event']['is_multiple_registrations']) || $this->_priceSetId @@ -368,9 +375,6 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { $this->assign('allowGroupOnWaitlist', $allowGroupOnWaitlist); $this->assign('isAdditionalParticipants', $isAdditionalParticipants); - //lets get js on two different qf elements. - $showHidePayfieldName = NULL; - $showHidePaymentInformation = FALSE; if ($this->_values['event']['is_monetary']) { self::buildAmount($this); } @@ -410,12 +414,9 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { } } - //lets add some qf element to bypass payment validations, CRM-4320 - if ($bypassPayment) { - $this->addElement('hidden', 'bypass_payment', NULL, array('id' => 'bypass_payment')); - } + $this->addElement('hidden', 'bypass_payment', NULL, array('id' => 'bypass_payment')); + $this->assign('bypassPayment', $bypassPayment); - $this->assign('showHidePaymentInformation', $showHidePaymentInformation); $userID = $this->getContactID(); @@ -803,7 +804,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { } //don't allow to register w/ waiting if enough spaces available. - if (!empty($fields['bypass_payment'])) { + if (!empty($fields['bypass_payment']) && $self->_allowConfirmation) { if (!is_numeric($self->_availableRegistrations) || (empty($fields['priceSetId']) && CRM_Utils_Array::value('additional_participants', $fields) < $self->_availableRegistrations) ) { diff --git a/templates/CRM/Contribute/Form/Contribution/Main.tpl b/templates/CRM/Contribute/Form/Contribution/Main.tpl index 52e4f25a94..795f563a67 100644 --- a/templates/CRM/Contribute/Form/Contribution/Main.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Main.tpl @@ -368,65 +368,12 @@ } } - {/literal} - {if $form.is_pay_later and $paymentProcessor.payment_processor_type EQ 'PayPal_Express'} - showHidePayPalExpressOption(); - {/if} - {literal} - CRM.$(function($) { enableHonorType(); showRecurHelp(); skipPaymentMethod(); }); - function showHidePayPalExpressOption() { - if (cj('input[name="is_pay_later"]').is(':checked')) { - cj("#crm-submit-buttons").show(); - cj("#paypalExpress").hide(); - } - else { - cj("#paypalExpress").show(); - cj("#crm-submit-buttons").hide(); - } - } - - function showHidePayment(flag) { - var payment_options = cj(".payment_options-group"); - var payment_processor = cj("div.payment_processor-section"); - var payment_information = cj("div#payment_information"); - if (flag) { - payment_options.hide(); - payment_processor.hide(); - payment_information.hide(); - } - else { - payment_options.show(); - payment_processor.show(); - payment_information.show(); - } - } - - function skipPaymentMethod() { - var flag = false; - cj('.price-set-option-content input[data-amount]').each( function(){ - currentTotal = cj(this).attr('data-amount').replace(/[^\/\d]/g,''); - if( cj(this).is(':checked') && currentTotal == 0 ) { - flag = true; - } - }); - - cj('.price-set-option-content input[data-amount]').change( function () { - if (cj(this).attr('data-amount').replace(/[^\/\d]/g,'') == 0 ) { - flag = true; - } else { - flag = false; - } - showHidePayment(flag); - }); - showHidePayment(flag); - } - CRM.$(function($) { // highlight price sets function updatePriceSetHighlight() { @@ -436,21 +383,6 @@ $('#priceset input[type="radio"]').change(updatePriceSetHighlight); updatePriceSetHighlight(); - function toggleBillingBlockIfFree(){ - var total_amount_tmp = $(this).data('raw-total'); - // Hide billing questions if this is free - if (total_amount_tmp == 0){ - $("#billing-payment-block").hide(); - $(".payment_options-group").hide(); - } - else { - $("#billing-payment-block").show(); - $(".payment_options-group").show(); - } - } - - $('#pricevalue').each(toggleBillingBlockIfFree).on('change', toggleBillingBlockIfFree); - // Update pledge contribution amount when pledge checkboxes change $("input[name^='pledge_amount']").on('change', function() { var total = 0; diff --git a/templates/CRM/Event/Form/Registration/Register.tpl b/templates/CRM/Event/Form/Registration/Register.tpl index 63628635e2..0f373d205e 100644 --- a/templates/CRM/Event/Form/Registration/Register.tpl +++ b/templates/CRM/Event/Form/Registration/Register.tpl @@ -141,13 +141,7 @@ {/if} -
- {* If we have a payment processor, load it - otherwise it happens via ajax *} - {if $paymentProcessorID or $isBillingAddressRequiredForPayLater} - {include file="CRM/Financial/Form/Payment.tpl" snippet=4} - {/if} -
- {include file="CRM/common/paymentBlock.tpl"} + {include file='CRM/Core/BillingBlockWrapper.tpl'}
{include file="CRM/UF/Form/Block.tpl" fields=$customPost} @@ -174,52 +168,11 @@ skipPaymentMethod(); }); - CRM.$(function($) { - skipPaymentMethod(); - }); - - // Hides billing and payment options block - but only if a price set is used. - // Called from display() in Calculate.tpl, depends on display() having been called. - function skipPaymentMethod() { - // If we're in quick-config price set, we do not have the pricevalue hidden element, so just return. - if (cj('#pricevalue').length == 0) { - return; - } - // CRM-15433 Remove currency symbol, decimal separator so we can check for zero numeric total regardless of localization. - currentTotal = cj('#pricevalue').text().replace(/[^\/\d]/g,''); - var isMultiple = '{/literal}{$event.is_multiple_registrations}{literal}'; - - var flag = 1; - var payment_options = cj(".payment_options-group"); - var payment_processor = cj("div.payment_processor-section"); - var payment_information = cj("div#payment_information"); - - // Do not hide billing and payment blocks if user is registering additional participants, since we do not know total owing. - if (isMultiple && cj("#additional_participants").val() && currentTotal == 0) { - flag = 0; - } - - if (currentTotal == 0 && flag) { - payment_options.hide(); - payment_processor.hide(); - payment_information.hide(); - // also unset selected payment methods - cj('input[name="payment_processor_id"]').removeProp('checked'); - } - else { - payment_options.show(); - payment_processor.show(); - payment_information.show(); - } - } - - {/literal} - - -{literal} -