Merge pull request #14919 from eileenmcnaughton/mem_review
authorMatthew Wire <mjw@mjwconsult.co.uk>
Sun, 13 Oct 2019 15:36:51 +0000 (16:36 +0100)
committerGitHub <noreply@github.com>
Sun, 13 Oct 2019 15:36:51 +0000 (16:36 +0100)
[Membership-backoffice] Reduce reliance on multiple specific but confusing class variables

1  2 
CRM/Member/Form/Membership.php

index bdc9c861101e8bcdd05d732aed3365902efd38a6,83a3743bade2960c61137dbe3bc558cc0a619d50..383a73f63e1eac82cb12d1a24ae620d63ffab1d7
@@@ -1132,20 -1132,21 +1132,21 @@@ class CRM_Member_Form_Membership extend
      //take the required membership recur values.
      if ($this->_mode && !empty($formValues['auto_renew'])) {
        $params['is_recur'] = $formValues['is_recur'] = TRUE;
-       $mapping = [
-         'frequency_interval' => 'duration_interval',
-         'frequency_unit' => 'duration_unit',
-       ];
  
        $count = 0;
        foreach ($this->_memTypeSelected as $memType) {
          $recurMembershipTypeValues = CRM_Utils_Array::value($memType,
-           $this->_recurMembershipTypes, []
+           $this->allMembershipTypeDetails, []
          );
-         foreach ($mapping as $mapVal => $mapParam) {
-           $membershipTypeValues[$memType][$mapVal] = CRM_Utils_Array::value($mapParam,
-             $recurMembershipTypeValues
-           );
+         if (!$recurMembershipTypeValues['auto_renew']) {
+           continue;
+         }
+         foreach ([
+           'frequency_interval' => 'duration_interval',
+           'frequency_unit' => 'duration_unit',
+         ] as $mapVal => $mapParam) {
+           $membershipTypeValues[$memType][$mapVal] = $recurMembershipTypeValues[$mapParam];
            if (!$count) {
              $formValues[$mapVal] = CRM_Utils_Array::value($mapParam,
                $recurMembershipTypeValues
  
      $lineItem = [$this->_priceSetId => []];
  
 +    // BEGIN Fix for dev/core/issues/860
 +    // Prepare fee block and call buildAmount hook - based on CRM_Price_BAO_PriceSet::buildPriceSet().
 +    CRM_Price_BAO_PriceSet::applyACLFinancialTypeStatusToFeeBlock($this->_priceSet['fields']);
 +    CRM_Utils_Hook::buildAmount('membership', $this, $this->_priceSet['fields']);
 +    // END Fix for dev/core/issues/860
 +
      CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'],
        $formValues, $lineItem[$this->_priceSetId], NULL, $this->_priceSetId);
  
 -    if (CRM_Utils_Array::value('tax_amount', $formValues)) {
 +    if (!empty($formValues['tax_amount'])) {
        $params['tax_amount'] = $formValues['tax_amount'];
      }
      $params['total_amount'] = CRM_Utils_Array::value('amount', $formValues);
      // if selected membership doesn't match with earlier membership
        !in_array($this->_memType, $this->_memTypeSelected)
      ) {
 -      if (CRM_Utils_Array::value('is_recur', $inputParams)) {
 +      if (!empty($inputParams['is_recur'])) {
          CRM_Core_Session::setStatus(ts('Associated recurring contribution cannot be updated on membership type change.', ts('Error'), 'error'));
          return;
        }