From b22c94d6b5a10988141bc64cabe74e3c9c603f4c Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 11 Oct 2023 19:46:30 +1300 Subject: [PATCH] Smarty3 compatibilty with Contribution Amount tab --- CRM/Contribute/Form/ContributionPage.php | 46 +++++++++++++++---- .../Form/ContributionPage/Amount.php | 19 +++++--- .../Form/ContributionPage/Amount.tpl | 15 ++---- 3 files changed, 53 insertions(+), 27 deletions(-) diff --git a/CRM/Contribute/Form/ContributionPage.php b/CRM/Contribute/Form/ContributionPage.php index 28a383d00f..f7bd50d8e7 100644 --- a/CRM/Contribute/Form/ContributionPage.php +++ b/CRM/Contribute/Form/ContributionPage.php @@ -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; + } + } diff --git a/CRM/Contribute/Form/ContributionPage/Amount.php b/CRM/Contribute/Form/ContributionPage/Amount.php index 910d57e1a9..d71efaa43f 100644 --- a/CRM/Contribute/Form/ContributionPage/Amount.php +++ b/CRM/Contribute/Form/ContributionPage/Amount.php @@ -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 * diff --git a/templates/CRM/Contribute/Form/ContributionPage/Amount.tpl b/templates/CRM/Contribute/Form/ContributionPage/Amount.tpl index 7f2d19e901..2feecd4200 100644 --- a/templates/CRM/Contribute/Form/ContributionPage/Amount.tpl +++ b/templates/CRM/Contribute/Form/ContributionPage/Amount.tpl @@ -199,12 +199,7 @@ {literal}