prevent people from selecting contribution amounts if member priceset
authorAndrew Hunt <andrew@aghstrategies.com>
Tue, 19 Nov 2013 18:28:25 +0000 (13:28 -0500)
committerAndrew Hunt <andrew@aghstrategies.com>
Tue, 19 Nov 2013 18:28:25 +0000 (13:28 -0500)
CRM/Contribute/Form/ContributionPage.php
templates/CRM/Contribute/Form/ContributionPage/Amount.tpl

index 71198cbee0a9533892cc006aca2c014ff4a67ce7..3502490957bad4a6856102407905572fb9d48d7d 100644 (file)
@@ -210,6 +210,25 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form {
       $this->freeze();
       $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/custom/group?reset=1&action=browse'"));
     }
+    
+    // don't show option for contribution amounts section if membership price set
+    // this flag is sent to template
+    
+    $membershipBlock = new CRM_Member_DAO_MembershipBlock();
+    $membershipBlock->entity_table = 'civicrm_contribution_page';
+    $membershipBlock->entity_id = $this->_id;
+    $membershipBlock->is_active = 1;
+    $hasMembershipBlk = FALSE;
+    if ($membershipBlock->find(TRUE) && 
+      ($setID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, NULL, 1))
+    ) {
+      $extends = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends');
+      if ($extends && $extends == CRM_Core_Component::getComponentID('CiviMember')) {
+        $hasMembershipBlk = TRUE;
+      }
+    }
+    // set value in DOM that membership price set exists
+    CRM_Core_Resources::singleton()->addSetting(array('memberPriceset' => $hasMembershipBlk));
   }
 
   /**
index c4150f64d98e36cd05ce3cdcdad77264aa52bc26..18abcddab550e9a40a86c843ae4c6b26353de6b3 100644 (file)
   if ( ! amount_block[0].checked || priceSetID ) {
      if ( !priceSetID ) {
        cj('#priceSet').hide();
+       if (CRM.memberPriceset) {
+         cj(".crm-contribution-contributionpage-amount-form-block-amount_block_is_active td").html('<span class="description">{/literal}{ts}You cannot enable the Contribution Amounts section when a Membership Price Set is in use. (See the Memberships tab above.) Membership Price Sets may include additional fields for non-membership options that require an additional fee (e.g. magazine subscription) or an additional voluntary contribution.</span>{/ts}{literal}');
+       }
      }
      cj('#amountFields').hide();
-        }
+  }
 
   cj(function() {
     payLater('is_pay_later');