From c29a2eee50914c1902c0b86da6898fffa568c2ed Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Thu, 17 Aug 2023 08:52:34 +1000 Subject: [PATCH] [REF] Fix poor checking of extends field as per PR #27079 but this time on the Amounts tab of the contribution page config --- .../Form/ContributionPage/Amount.php | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/CRM/Contribute/Form/ContributionPage/Amount.php b/CRM/Contribute/Form/ContributionPage/Amount.php index e3dcd31d4c..544856b4f0 100644 --- a/CRM/Contribute/Form/ContributionPage/Amount.php +++ b/CRM/Contribute/Form/ContributionPage/Amount.php @@ -311,14 +311,19 @@ class CRM_Contribute_Form_ContributionPage_Amount extends CRM_Contribute_Form_Co $membershipBlock->is_active = 1; $hasMembershipBlk = FALSE; if ($membershipBlock->find(TRUE)) { - if (!empty($fields['amount_block_is_active']) && - ($setID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $self->_id, NULL, 1)) - ) { - $extends = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends'); - if ($extends && $extends == CRM_Core_Component::getComponentID('CiviMember')) { - $errors['amount_block_is_active'] = ts('You cannot use a Membership Price Set when the Contribution Amounts section is enabled. Click the Memberships tab above, and select your Membership Price Set on that form. 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.'); - return $errors; - } + // Don't allow Contribution price set w/ membership signup, CRM-5095. + $priceSetExtendsMembership = \Civi\Api4\PriceSetEntity::get(FALSE) + ->addSelect('id') + ->addJoin('PriceSet AS price_set', 'LEFT', ['price_set_id', '=', 'price_set.id']) + ->addWhere('entity_table', '=', 'civicrm_contribution_page') + ->addWhere('entity_id', '=', $self->_id) + ->addWhere('price_set.extends:name', 'CONTAINS', 'CiviMember') + ->addWhere('price_set.is_quick_config', '=', 0) + ->execute() + ->first(); + if (!empty($fields['amount_block_is_active']) && $priceSetExtendsMembership) { + $errors['amount_block_is_active'] = ts('You cannot use a Membership Price Set when the Contribution Amounts section is enabled. Click the Memberships tab above, and select your Membership Price Set on that form. 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.'); + return $errors; } $hasMembershipBlk = TRUE; if ($membershipBlock->is_separate_payment && empty($fields['amount_block_is_active'])) { @@ -377,7 +382,7 @@ class CRM_Contribute_Form_ContributionPage_Amount extends CRM_Contribute_Form_Co if ($priceSetId) { // don't allow price set w/ membership. if ($hasMembershipBlk) { - $errors['price_set_id'] = ts('You cannot enable both a Contribution Price Set and Membership Signup on the same online contribution page.'); + $errors['price_set_id'] = ts('You cannot enable both Membership Signup and a Contribution Price Set on the same online contribution page'); } } else { -- 2.25.1