diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 28d3b62023e8..eb2979e4dd69 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -372,7 +372,7 @@ public function buildQuickForm() { // build price set form. $this->set('priceSetId', $this->_priceSetId); if (empty($this->_ccid)) { - CRM_Price_BAO_PriceSet::buildPriceSet($this); + CRM_Price_BAO_PriceSet::buildPriceSet($this, $this->getMainEntityType()); } if ($this->_values['is_monetary'] && $this->_values['is_recur'] && empty($this->_values['pledge_id']) @@ -511,6 +511,7 @@ private function buildMembershipBlock() { $this->_currentMemberships = []; $membershipTypeIds = $membershipTypes = $radio = $radioOptAttrs = []; + // This is always true if this line is reachable - remove along with the upcoming if. $membershipPriceset = (!empty($this->_priceSetId) && $this->isMembershipPriceSet()); $allowAutoRenewMembership = $autoRenewOption = FALSE; @@ -634,28 +635,6 @@ private function buildMembershipBlock() { $autoRenewOption = CRM_Price_BAO_PriceSet::checkAutoRenewForPriceSet($this->_priceSetId); $this->assign('autoRenewOption', $autoRenewOption); - if (!$membershipPriceset) { - if (!$this->_membershipBlock['is_required']) { - $this->assign('showRadioNoThanks', TRUE); - $radio['no_thanks'] = NULL; - $this->addRadio('selectMembership', NULL, $radio, [], NULL, FALSE, $radioOptAttrs); - } - elseif ($this->_membershipBlock['is_required'] && count($radio) == 1) { - $temp = array_keys($radio); - $this->add('hidden', 'selectMembership', $temp[0], ['id' => 'selectMembership']); - $this->assign('singleMembership', TRUE); - $this->assign('showRadio', FALSE); - } - else { - foreach ($radioOptAttrs as $opt => $attrs) { - $attrs['class'] = ' required'; - } - $this->addRadio('selectMembership', NULL, $radio, [], NULL, FALSE, $radioOptAttrs); - } - - $this->addRule('selectMembership', ts('Please select one of the memberships.'), 'required'); - } - if ((!$this->_values['is_pay_later'] || is_array($this->_paymentProcessors)) && ($allowAutoRenewMembership || $autoRenewOption)) { if ($autoRenewOption == 2) { $this->addElement('hidden', 'auto_renew', ts('Please renew my membership automatically.')); @@ -783,6 +762,8 @@ public static function formRule($fields, $files, $self) { $self->_useForMember ) ) { + + // appears to be unreachable - selectMembership never set... $isTest = $self->_action & CRM_Core_Action::PREVIEW; $lifeMember = CRM_Member_BAO_Membership::getAllContactMembership($self->_membershipContactID, $isTest, TRUE); diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 8ea9c95123aa..1d41e1ae54cf 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -446,6 +446,7 @@ public function preProcess() { $this->set('values', $this->_values); $this->set('fields', $this->_fields); } + $this->assign('isShowMembershipQuickConfigBlock', $this->isShowMembershipQuickConfigBlock()); $this->set('membershipBlock', $this->getMembershipBlock()); // Handle PCP @@ -1304,9 +1305,8 @@ protected function getMembershipBlock() { */ protected function isMembershipPriceSet(): bool { if ($this->_useForMember === NULL) { - if (CRM_Core_Component::isEnabled('CiviMember') && - (!$this->isQuickConfig() || !empty($this->_ccid)) && - (int) CRM_Core_Component::getComponentID('CiviMember') === (int) $this->order->getPriceSetMetadata()['extends']) { + if ($this->getMainEntityType() === 'membership' && + !$this->isQuickConfig()) { $this->_useForMember = 1; } else { @@ -1317,6 +1317,23 @@ protected function isMembershipPriceSet(): bool { return (bool) $this->_useForMember; } + public function getMainEntityType() { + if (CRM_Core_Component::isEnabled('CiviMember') && (int) CRM_Core_Component::getComponentID('CiviMember') === (int) $this->order->getPriceSetMetadata()['extends']) { + return 'membership'; + } + return 'contribution'; + } + + /** + * Should the membership block be displayed. + * + * This should be shown when the price set is quick config and is a membership price set. + * @return bool + */ + protected function isShowMembershipQuickConfigBlock(): bool { + return CRM_Core_Component::isEnabled('CiviMember') && $this->getMembershipBlock() && $this->isQuickConfig(); + } + /** * Is the contribution page configured for 2 payments, one being membership & one not. * diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index e263fdf3dedb..d3dedcbbe14a 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -791,10 +791,11 @@ public static function getCachedPriceSetDetail($priceSetID) { * Build the price set form. * * @param CRM_Core_Form $form + * @param string|null $component * * @return void */ - public static function buildPriceSet(&$form) { + public static function buildPriceSet(&$form, $component = NULL) { $priceSetId = $form->get('priceSetId'); if (!$priceSetId) { return; @@ -847,23 +848,19 @@ public static function buildPriceSet(&$form) { $form->_priceSet['id'] = $form->_priceSet['id'] ?? $priceSetId; $form->assign('priceSet', $form->_priceSet); - $component = 'contribution'; if ($className == 'CRM_Member_Form_Membership') { $component = 'membership'; } if ($className == 'CRM_Contribute_Form_Contribution_Main') { $feeBlock = &$form->_values['fee']; - if (!empty($form->_useForMember)) { - $component = 'membership'; - } } else { $feeBlock = &$form->_priceSet['fields']; } // Call the buildAmount hook. - CRM_Utils_Hook::buildAmount($component, $form, $feeBlock); + CRM_Utils_Hook::buildAmount($component ?? 'contribution', $form, $feeBlock); self::addPriceFieldsToForm($form, $feeBlock, $validFieldsOnly, $className, $validPriceFieldIds); } diff --git a/templates/CRM/Contribute/Form/Contribution/Main.tpl b/templates/CRM/Contribute/Form/Contribution/Main.tpl index a7ee32e09e5e..3a0c541a7e33 100644 --- a/templates/CRM/Contribute/Form/Contribution/Main.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Main.tpl @@ -76,7 +76,7 @@
{ts}You have a current Lifetime Membership which does not need to be renewed.{/ts}
{/if} - {if !empty($useForMember) && !$ccid} + {if $isShowMembershipQuickConfigBlock && !$ccid}
{include file="CRM/Contribute/Form/Contribution/MembershipBlock.tpl" context="makeContribution"}
diff --git a/templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl b/templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl index 796834c64bd9..fd70bbe24956 100644 --- a/templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl +++ b/templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl @@ -7,7 +7,7 @@ | and copyright information, see https://civicrm.org/licensing | +--------------------------------------------------------------------+ *} -{if !empty($useForMember) AND !$is_quick_config} +{if $isShowMembershipQuickConfigBlock}
{if $context EQ "makeContribution"}
@@ -158,6 +158,7 @@ {foreach from=$membershipTypes item=row} {if $showRadio } + {* unreachable - show radio is never true *} {assign var="pid" value=$row.id} {$form.selectMembership.$pid.html} {else} @@ -203,7 +204,7 @@ {/if} - {if $showRadio} + {if $showRadio}{* unreachable *} {if $showRadioNoThanks } {* Provide no-thanks option when Membership signup is not required - per membership block configuration. *} {$form.selectMembership.no_thanks.html}