* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
+use Civi\Api4\MembershipBlock;
/**
* Contribution Page 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.
*
$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;
}
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;
}
CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageID, $priceSetID);
}
else {
-
- $deletePriceSet = FALSE;
// process contribution amount block
$deleteAmountBlk = FALSE;
}
else {
$deleteAmountBlk = TRUE;
- $deletePriceSet = TRUE;
}
}
}