fixing membership renewal, make line items more transparent
authorEileen McNaughton <eileen@fuzion.co.nz>
Sun, 12 Jul 2015 10:03:34 +0000 (22:03 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Sun, 12 Jul 2015 10:03:34 +0000 (22:03 +1200)
CRM/Member/BAO/Membership.php

index 7289b36f4745781b167c41cc795cc2b79019f10f..5ca038d83c4fee0bd419c2e55bf39751840e23e4 100644 (file)
@@ -2258,6 +2258,54 @@ INNER JOIN  civicrm_contact contact ON ( contact.id = membership.contact_id AND
     return array($membership, $renewalMode, $dates);
   }
 
+  /**
+   * Get line items representing the default price set.
+   *
+   * @param int $membershipOrg
+   * @param int $membershipTypeID
+   * @param float $total_amount
+   *
+   * @return array
+   */
+  public static function getQuickConfigMembershipLineItems($membershipOrg, $membershipTypeID, $total_amount) {
+    $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name');
+    $priceSets = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
+
+    // The name of the price field corresponds to the membership_type organization contact.
+    $params = array(
+      'price_set_id' => $priceSetId,
+      'name' => $membershipOrg,
+    );
+    $results = array();
+    CRM_Price_BAO_PriceField::retrieve($params, $results);
+
+    if (!empty($results)) {
+      $fields[$results['id']] = $priceSets['fields'][$results['id']];
+      $fid = $results['id'];
+      $editedFieldParams = array(
+        'price_field_id' => $results['id'],
+        'membership_type_id' => $membershipTypeID,
+      );
+      $results = array();
+      CRM_Price_BAO_PriceFieldValue::retrieve($editedFieldParams, $results);
+      $fields[$fid]['options'][$results['id']] = $priceSets['fields'][$fid]['options'][$results['id']];
+      if (!empty($total_amount)) {
+        $fields[$fid]['options'][$results['id']]['amount'] = $total_amount;
+      }
+    }
+
+    $fieldID = key($fields);
+    $returnParams = array(
+      'price_set_id' => $priceSetId,
+      'price_sets' => $priceSets,
+      'fields' => $fields,
+      'price_fields' => array(
+        'price_' . $fieldID => CRM_Utils_Array::value('id', $results),
+      )
+    );
+    return $returnParams;
+  }
+
   /**
    * Process price set and line items.
    *
@@ -2608,6 +2656,9 @@ WHERE      civicrm_membership.is_test = 0";
 
   /**
    * Record line items for default membership.
+   * @deprecated
+   *
+   * Use getQuickConfigMembershipLineItems
    *
    * @param CRM_Core_Form $qf
    * @param array $membershipType