From: Eileen McNaughton Date: Sun, 12 Jul 2015 10:03:34 +0000 (+1200) Subject: fixing membership renewal, make line items more transparent X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=27b6ce36f69f583bf63c913b1cb7df2c5404f57f;p=civicrm-core.git fixing membership renewal, make line items more transparent --- diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 7289b36f47..5ca038d83c 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -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