compucorp / uk.co.compucorp.membershipextras

Membership Extras for CiviCRM
Other
5 stars 8 forks source link

MAE-492: Fix membership end date after CiviCRM 5.35 update #368

Closed ahed-compucorp closed 3 years ago

ahed-compucorp commented 3 years ago

Overview

After updating to CiviCRM 5.35, If we created a payment plan membership with pending status, we found out that the end date will increase each time we recorded a new payment.

Before

Recording a new payment will increase the membership end date. Peek 2021-03-12 21-12

After

Recording a new payment will not increase the membership end date. Peek 2021-03-12 20-47

Technical Details

This PR https://github.com/civicrm/civicrm-core/pull/18410 to CiviCRM core has the following change :

- $prevnext[] = $this->createElement('submit', $buttonName, $button['name'], $attrs);
+ $attrs['type'] = 'submit';
+ $prevnext[] = $this->createElement('xbutton', $buttonName, $button['name'], $attrs);

Instead of creating a button with the value "Record Payment" like this

<input class="crm-form-submit default validate" onclick="return verify( );" crm-icon="fa-check" name="_qf_AdditionalPayment_upload" value="Record Payment" type="submit" id="_qf_AdditionalPayment_upload">

It will create a button with the value "1" like this

<button class="crm-form-submit default validate crm-button crm-button-type-upload crm-button_qf_AdditionalPayment_upload" onclick="return verify( );" value="1" type="submit" name="_qf_AdditionalPayment_upload" id="_qf_AdditionalPayment_upload"><i aria-hidden="true" class="crm-i fa-check"></i> Record Payment</button>

And the condition here will be false

$isRecordPayment = CRM_Utils_Request::retrieve('_qf_AdditionalPayment_upload', 'String') === 'Record Payment';

The main point is to figure out if the submitted form is a record payment submission or refund submission and we can do that by checking the the variable _paymentType in the AdditionalPayment Form class and prepare it for MembershipEdit class.

Comments

Another potential solution is to alter the button attributes and inject the value "Record Payment" again like this

/**
 * Implements hook_civicrm_buildForm().
 */
function membershipextras_civicrm_buildForm($formName, &$form) {
  if ($formName == 'CRM_Contribute_Form_AdditionalPayment') {
    $buttons = $form->getElement('buttons');
    $elements = $buttons->getElements();
    $elements[0]->setValue("Record Payment");
  }
}