Skip to content

Commit 654e067

Browse files
committed
dev/core#5802 Initial Recurring Membership Contribution modification
1 parent 70f2b92 commit 654e067

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

CRM/Member/Form/Membership.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,10 @@ public function buildQuickForm() {
476476
$this->add('number', 'num_terms', ts('Number of Terms'), ['size' => 6]);
477477
}
478478

479+
if (Civi::settings()->get('update_contribution_on_membership_type_change')) {
480+
$this->addElement('checkbox', 'update_recur', ts('Update Recurring Contribution?'));
481+
}
482+
479483
$this->add('text', 'source', ts('Membership Source'),
480484
CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'source')
481485
);
@@ -1315,6 +1319,10 @@ public function submit(): void {
13151319
}
13161320
}
13171321

1322+
$params['update_recur'] = FALSE;
1323+
if ($this->getSubmittedValue('update_recur')) {
1324+
$params['update_recur'] = $formValues['update_recur'];
1325+
}
13181326
$this->updateContributionOnMembershipTypeChange($params);
13191327

13201328
if (($this->_action & CRM_Core_Action::UPDATE)) {
@@ -1388,7 +1396,7 @@ protected function updateContributionOnMembershipTypeChange($inputParams) {
13881396
// if selected membership doesn't match with earlier membership
13891397
!in_array($this->_memType, $this->_memTypeSelected)
13901398
) {
1391-
if ($this->isCreateRecurringContribution()) {
1399+
if ($this->isCreateRecurringContribution() && !$inputParams['update_recur']) {
13921400
CRM_Core_Session::setStatus(ts('Associated recurring contribution cannot be updated on membership type change.'), ts('Error'), 'error');
13931401
return;
13941402
}
@@ -1418,6 +1426,23 @@ protected function updateContributionOnMembershipTypeChange($inputParams) {
14181426
$this
14191427
);
14201428
CRM_Core_Session::setStatus(ts('Associated contribution is updated on membership type change.'), ts('Success'), 'success');
1429+
1430+
// Update Recurring Contribution
1431+
if ($inputParams['update_recur']) {
1432+
$contribution = \Civi\Api4\Contribution::get()
1433+
->addWhere('id', '=', $contributionID)
1434+
->execute()
1435+
->first();
1436+
1437+
if (!empty($contribution['contribution_recur_id'])) {
1438+
ContributionRecur::update(FALSE)
1439+
->addValue('amount', $contribution['total_amount'])
1440+
->addValue('currency', $contribution['currency'])
1441+
->addValue('modified_date', 'now')
1442+
->addWhere('id', '=', $contribution['contribution_recur_id'])
1443+
->execute();
1444+
}
1445+
}
14211446
}
14221447
}
14231448

templates/CRM/Member/Form/Membership.tpl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@
9898
<span class="description">{ts}Select Membership Organization and then Membership Type.{/ts}{if $hasPriceSets} {ts}Alternatively, you can use a price set.{/ts}{/if}</span>
9999
</td>
100100
</tr>
101+
{if $isRecur && '{$form.update_recur.label}'}
102+
<tr id="crm-membership-form-block-update-recurring">
103+
<td class="label">{$form.update_recur.label}</td>
104+
<td class="mem_recur_contribution">
105+
<span class="UpdateRecur">{$form.update_recur.html}</span>
106+
<span class="description">
107+
{ts}Update Recurring Contribution to match the current membership pricing on this change.{/ts}
108+
</span>
109+
</td>
110+
</tr>
111+
{/if}
101112
<tr id="maxRelated" class="crm-membership-form-block-max_related">
102113
<td class="label">{$form.max_related.label}</td>
103114
<td>{$form.max_related.html}<br />
@@ -340,6 +351,9 @@
340351
cj('#membership_type_id_1-readonly').text(cj('#membership_type_id_1 option:selected').text());
341352
cj('#mem_type_id-readonly').show();
342353
cj('#mem_type_id-editable').hide();
354+
{if '{$form.update_recur.label}'}
355+
cj('#crm-membership-form-block-update-recurring').hide();
356+
{/if}
343357
{else}
344358
cj('#mem_type_id-readonly').hide();
345359
cj('#mem_type_id-editable').show();
@@ -350,6 +364,9 @@
350364
e.preventDefault();
351365
cj('#mem_type_id-readonly').hide();
352366
cj('#mem_type_id-editable').show();
367+
{if '{$form.update_recur.label}'}
368+
cj('#crm-membership-form-block-update-recurring').show();
369+
{/if}
353370
});
354371
355372
// give option to override end-date for auto-renew memberships

0 commit comments

Comments
 (0)