CRM-15433 - Fix skipPayment function so it works regardless of currency localization.
authorDave Greenberg <dave@civicrm.org>
Tue, 21 Oct 2014 23:13:03 +0000 (16:13 -0700)
committerDave Greenberg <dave@civicrm.org>
Tue, 21 Oct 2014 23:13:03 +0000 (16:13 -0700)
----------------------------------------
* CRM-15433: Billing info and payment options blocks not hidden for $0 events with price sets when decimal delimiter is NOT a dot
  https://issues.civicrm.org/jira/browse/CRM-15433

templates/CRM/Event/Form/Registration/Register.tpl

index 6374ea42f99e8d623f2408b3ec2aa1a6803b5f08..ba0c30bfa2a45a2d45a07d33ad62c7ff4be51388 100644 (file)
       toggleConfirmButton();
     });
 
+    cj("#additional_participants").change(function () {
+      skipPaymentMethod();
+    });
+
     CRM.$(function($) {
       toggleConfirmButton();
       skipPaymentMethod();
     });
 
-    // Called from display() in Calculate.tpl, depends on display() having been called
+    // 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() {
-      var symbol = '{/literal}{$currencySymbol}{literal}';
+      // 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_processor = cj("div.payment_processor-section");
       var payment_information = cj("div#payment_information");
 
-      if (isMultiple && cj("#additional_participants").val() && cj('#pricevalue').text() !== symbol + " 0.00") {
+      // 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 ((cj('#pricevalue').text() == symbol + " 0.00") && flag) {
+      if (currentTotal == 0 && flag) {
         payment_options.hide();
         payment_processor.hide();
         payment_information.hide();