Skip to content

Commit

Permalink
Merge pull request civicrm#26170 from eileenmcnaughton/562_member
Browse files Browse the repository at this point in the history
Fix regression whereby membership does not submit
  • Loading branch information
totten authored May 8, 2023
2 parents aa9c250 + c3f9fce commit df78650
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 35 deletions.
27 changes: 4 additions & 23 deletions CRM/Contribute/Form/Contribution/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.'));
Expand Down Expand Up @@ -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);

Expand Down
23 changes: 20 additions & 3 deletions CRM/Contribute/Form/ContributionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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.
*
Expand Down
9 changes: 3 additions & 6 deletions CRM/Price/BAO/PriceSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Contribute/Form/Contribution/Main.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<div class="help">{ts}You have a current Lifetime Membership which does not need to be renewed.{/ts}</div>
{/if}

{if !empty($useForMember) && !$ccid}
{if $isShowMembershipQuickConfigBlock && !$ccid}
<div class="crm-public-form-item crm-section">
{include file="CRM/Contribute/Form/Contribution/MembershipBlock.tpl" context="makeContribution"}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
{if !empty($useForMember) AND !$is_quick_config}
{if $isShowMembershipQuickConfigBlock}
<div id="membership" class="crm-group membership-group">
{if $context EQ "makeContribution"}
<div id="priceset">
Expand Down Expand Up @@ -158,6 +158,7 @@
{foreach from=$membershipTypes item=row}
<tr {if $context EQ "makeContribution"}class="odd-row" {/if}valign="top">
{if $showRadio }
{* unreachable - show radio is never true *}
{assign var="pid" value=$row.id}
<td style="width: 1em;">{$form.selectMembership.$pid.html}</td>
{else}
Expand Down Expand Up @@ -203,7 +204,7 @@
</td>
</tr>
{/if}
{if $showRadio}
{if $showRadio}{* unreachable *}
{if $showRadioNoThanks } {* Provide no-thanks option when Membership signup is not required - per membership block configuration. *}
<tr class="odd-row">
<td>{$form.selectMembership.no_thanks.html}</td>
Expand Down

0 comments on commit df78650

Please sign in to comment.