Smarty3 compatibilty with Contribution Amount tab
authorEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 11 Oct 2023 06:46:30 +0000 (19:46 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 11 Oct 2023 07:01:58 +0000 (20:01 +1300)
CRM/Contribute/Form/ContributionPage.php
CRM/Contribute/Form/ContributionPage/Amount.php
templates/CRM/Contribute/Form/ContributionPage/Amount.tpl

index 28a383d00f52c25e5971084f6cdabff2644bbbe0..f7bd50d8e75abe7c6337ad4115d3875b118c3310 100644 (file)
@@ -46,7 +46,7 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form {
    *
    * @var int
    */
-  protected $_priceSetID = NULL;
+  protected $_priceSetID;
 
   protected $_values;
 
@@ -68,11 +68,7 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form {
    * Set variables up before form is built.
    */
   public function preProcess() {
-    // current contribution page id
-    $this->_id = CRM_Utils_Request::retrieve('id', 'Positive',
-      $this, FALSE, NULL, 'REQUEST'
-    );
-    $this->assign('contributionPageID', $this->_id);
+    $this->assign('contributionPageID', $this->getContributionPageID());
 
     // get the requested action
     $this->_action = CRM_Utils_Request::retrieve('action', 'String',
@@ -258,10 +254,8 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form {
 
       // get price set of type contributions
       //this is the value for stored in db if price set extends contribution
-      $usedFor = 2;
-      $this->_priceSetID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, $usedFor, 1);
-      if ($this->_priceSetID) {
-        $defaults['price_set_id'] = $this->_priceSetID;
+      if ($this->getPriceSetID()) {
+        $defaults['price_set_id'] = $this->getPriceSetID();
       }
     }
     else {
@@ -406,4 +400,36 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form {
     }
   }
 
+  /**
+   * Get the price set ID for the event.
+   *
+   * @return int|null
+   *
+   * @api This function will not change in a minor release and is supported for
+   * use outside of core. This annotation / external support for properties
+   * is only given where there is specific test cover.
+   */
+  public function getContributionPageID(): ?int {
+    if (!$this->_id) {
+      $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
+    }
+    return $this->_id ? (int) $this->_id : NULL;
+  }
+
+  /**
+   * Get the price set ID for the contribution page.
+   *
+   * @return int|null
+   *
+   * @api This function will not change in a minor release and is supported for
+   * use outside of core. This annotation / external support for properties
+   * is only given where there is specific test cover.
+   */
+  public function getPriceSetID(): ?int {
+    if (!$this->_priceSetID && $this->getContributionPageID()) {
+      $this->_priceSetID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->getContributionPageID());
+    }
+    return $this->_priceSetID ? (int) $this->_priceSetID : NULL;
+  }
+
 }
index 910d57e1a9e02e4df6d75604c9a9d58ccdfd9b67..d71efaa43f6b66022da89e8e6acdf0de31a02ba2 100644 (file)
@@ -98,9 +98,7 @@ class CRM_Contribute_Form_ContributionPage_Amount extends CRM_Contribute_Form_Co
     if (count($recurringPaymentProcessor)) {
       $this->assign('recurringPaymentProcessor', $recurringPaymentProcessor);
     }
-    if (count($futurePaymentProcessor)) {
-      $this->assign('futurePaymentProcessor', $futurePaymentProcessor);
-    }
+    $this->assign('futurePaymentProcessor', json_encode($futurePaymentProcessor ?? [], TRUE));
     if (count($paymentProcessor)) {
       $this->assign('paymentProcessor', $paymentProcessor);
     }
@@ -144,7 +142,7 @@ class CRM_Contribute_Form_ContributionPage_Amount extends CRM_Contribute_Form_Co
     else {
       $this->assign('price', TRUE);
     }
-
+    $this->assign('isQuick', $this->isQuickConfig());
     $this->addSelect('price_set_id', [
       'entity' => 'PriceSet',
       'option_url' => 'civicrm/admin/price',
@@ -208,12 +206,10 @@ class CRM_Contribute_Form_ContributionPage_Amount extends CRM_Contribute_Form_Co
     if (empty($defaults['pay_later_text'])) {
       $defaults['pay_later_text'] = ts('I will send payment by check');
     }
-
     if (!empty($defaults['amount_block_is_active'])) {
 
       if ($priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, NULL)) {
-        if ($isQuick = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config')) {
-          $this->assign('isQuick', $isQuick);
+        if ($this->isQuickConfig()) {
           //$priceField = CRM_Core_DAO::getFieldValue( 'CRM_Price_DAO_PriceField', $priceSetId, 'id', 'price_set_id' );
           $options = $pFIDs = [];
           $priceFieldParams = ['price_set_id' => $priceSetId];
@@ -828,6 +824,15 @@ class CRM_Contribute_Form_ContributionPage_Amount extends CRM_Contribute_Form_Co
     parent::endPostProcess();
   }
 
+  /**
+   * Is the price set quick config.
+   *
+   * @return bool
+   */
+  private function isQuickConfig(): bool {
+    return $this->getPriceSetID() && CRM_Price_BAO_PriceSet::isQuickConfig($this->getPriceSetID());
+  }
+
   /**
    * Return a descriptive name for the page, used in wizard header
    *
index 7f2d19e901b306863fa8a4a837efb82be6789db8..2feecd42002ab10529644b8536251d6c82570bd9 100644 (file)
 {literal}
 <script type="text/javascript">
 
-   var futurePaymentProcessorMapper = [];
-   {/literal}{if $futurePaymentProcessor}
-   {foreach from=$futurePaymentProcessor item="futurePaymentProcessor" key="index"}{literal}
-     futurePaymentProcessorMapper[{/literal}{$index}{literal}] = '{/literal}{$futurePaymentProcessor}{literal}';
-   {/literal}{/foreach}
-   {literal}
+   {/literal}{if $futurePaymentProcessor}{literal}
    CRM.$(function($) {
      var defId = $('input[name="pledge_default_toggle"][value="contribution_date"]').attr('id');
      var calId = $('input[name="pledge_default_toggle"][value="calendar_date"]').attr('id');
     function showAdjustRecurring( paymentProcessorIds ) {
         var display = true;
         cj.each(paymentProcessorIds, function(k, id){
-            if( cj.inArray(id, futurePaymentProcessorMapper) == -1 ) {
-                display = false;
-            }
+           if( cj.inArray(parseInt(id), {/literal}{$futurePaymentProcessor}{literal}) == -1 ) {
+              display = false;
+          }
         });
 
         if(display) {
-            cj( '#adjustRecurringFields' ).show( );
+            cj('#adjustRecurringFields').show();
         } else {
             if ( cj( '#adjust_recur_start_date' ).prop('checked' ) ) {
                 cj( '#adjust_recur_start_date' ).prop('checked', false);