Fix handling of auto renew memberships where frequency_interval > 1
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 19 Dec 2023 05:36:54 +0000 (18:36 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 19 Dec 2023 20:31:09 +0000 (09:31 +1300)
CRM/Contribute/Form/ContributionBase.php

index d5d7561771df6763e3819cb0a22a22d474d59de2..411b01fef2d1aa5d799685a48fba91b755e77579 100644 (file)
@@ -1162,8 +1162,10 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
       // If membership_num_terms is not specified on the the price field value (which seems not uncommon
       // in default config) then the membership type provides the values.
       // @todo - access the line item value from $this->getLineItems() rather than _values['fee']
-      $this->_params['frequency_interval'] = $this->getSubmittedValue('frequency_interval') ?? ($this->_values['fee'][$priceFieldId]['options'][$priceFieldValue]['membership_num_terms'] ?? ($membershipTypeDetails['duration_interval'] ?? 1));
-      $this->_params['frequency_unit'] = $this->_params['frequency_unit'] ?? $membershipTypeDetails['duration_unit'];
+      $membershipNumTerms = $this->_values['fee'][$priceFieldId]['options'][$priceFieldValue]['membership_num_terms'] ?? 1;
+      $membershipDurationInterval = $membershipTypeDetails['duration_interval'] ?? 1;
+      $this->_params['frequency_interval'] = $this->getSubmittedValue('frequency_interval') ?? ($membershipNumTerms * $membershipDurationInterval);
+      $this->_params['frequency_unit'] = $this->getSubmittedValue('frequency_unit') ?? $membershipTypeDetails['duration_unit'];
     }
     // This seems like it repeats the above with less care...
     elseif (!$this->_separateMembershipPayment && ($membershipTypeDetails['auto_renew'] === 2