From: eileen Date: Mon, 1 Jan 2024 03:39:54 +0000 (+1300) Subject: Do not delete price_set_entity record while page supports payment X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b00e86450130f0155f29f2cb6afb7748af2f2948;p=civicrm-core.git Do not delete price_set_entity record while page supports payment --- diff --git a/CRM/Contribute/Form/ContributionPage.php b/CRM/Contribute/Form/ContributionPage.php index 3b8f5a1d6f..104e2801de 100644 --- a/CRM/Contribute/Form/ContributionPage.php +++ b/CRM/Contribute/Form/ContributionPage.php @@ -14,6 +14,7 @@ * @package CRM * @copyright CiviCRM LLC https://civicrm.org/licensing */ +use Civi\Api4\MembershipBlock; /** * Contribution Page form. @@ -413,6 +414,18 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form { return $this->_id ? (int) $this->_id : NULL; } + /** + * Get the membership Block ID, if any, attached to the contribution page. + * + * @return int|null + */ + public function getMembershipBlockID(): ?int { + return MembershipBlock::get(FALSE) + ->addWhere('entity_table', '=', 'civicrm_contribution_page') + ->addWhere('entity_id', '=', $this->getContributionPageID()) + ->addWhere('is_active', '=', TRUE)->execute()->first()['id'] ?? NULL; + } + /** * Get the price set ID for the contribution page. * diff --git a/CRM/Contribute/Form/ContributionPage/Amount.php b/CRM/Contribute/Form/ContributionPage/Amount.php index 03092f75e7..69667cabcb 100644 --- a/CRM/Contribute/Form/ContributionPage/Amount.php +++ b/CRM/Contribute/Form/ContributionPage/Amount.php @@ -543,10 +543,12 @@ class CRM_Contribute_Form_ContributionPage_Amount extends CRM_Contribute_Form_Co $contributionPageID = $contributionPage->id; // prepare for data cleanup. - $deleteAmountBlk = $deletePledgeBlk = $deletePriceSet = FALSE; - if ($this->_priceSetID) { - $deletePriceSet = TRUE; - } + $deleteAmountBlk = $deletePledgeBlk = FALSE; + // We delete the link to the price set (the price set entity record) when + // one exists and there is neither a contribution or membership section enabled. + // This amount form can set & unset the contribution section but must check the database + // for the membership section (membership block). + $deletePriceSet = $this->_priceSetID && !$this->getSubmittedValue('amount_block_is_active') && !$this->getMembershipBlockID(); if ($this->_pledgeBlockID) { $deletePledgeBlk = TRUE; } @@ -558,9 +560,9 @@ class CRM_Contribute_Form_ContributionPage_Amount extends CRM_Contribute_Form_Co if (!empty($params['amount_block_is_active'])) { // handle price set. + $deletePriceSet = FALSE; if ($priceSetID) { // add/update price set. - $deletePriceSet = FALSE; if (!empty($params['price_field_id']) || !empty($params['price_field_other'])) { $deleteAmountBlk = TRUE; } @@ -568,8 +570,6 @@ class CRM_Contribute_Form_ContributionPage_Amount extends CRM_Contribute_Form_Co CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageID, $priceSetID); } else { - - $deletePriceSet = FALSE; // process contribution amount block $deleteAmountBlk = FALSE; @@ -795,7 +795,6 @@ class CRM_Contribute_Form_ContributionPage_Amount extends CRM_Contribute_Form_Co } else { $deleteAmountBlk = TRUE; - $deletePriceSet = TRUE; } } }