}
if (!empty($membershipParams['selectMembership'])) {
// CRM-12233
+ $membershipLineItems = array();
if ($this->_separateMembershipPayment && $this->_values['amount_block_is_active']) {
foreach ($this->_values['fee'] as $key => $feeValues) {
- if ($feeValues['name'] == 'membership_amount') {
+ if ($feeValues['name'] == 'membership_amount') {
$fieldId = $this->_params['price_' . $key];
- $this->_memLineItem[$this->_priceSetId][$fieldId] = $this->_lineItem[$this->_priceSetId][$fieldId];
+ $membershipLineItems[$this->_priceSetId][$fieldId] = $this->_lineItem[$this->_priceSetId][$fieldId];
unset($this->_lineItem[$this->_priceSetId][$fieldId]);
break;
}
}
}
- $this->processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams);
+ $this->processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems);
if (!$this->_amount > 0.0 || !$membershipParams['amount']) {
// we need to explicitly create a CMS user in case of free memberships
// since it is done under processConfirm for paid memberships
}
/**
- * @param $membershipParams
- * @param $contactID
- * @param $customFieldsFormatted
- * @param $fieldTypes
- * @param $premiumParams
+ * @param array $membershipParams
+ * @param integer $contactID
+ * @param array $customFieldsFormatted
+ * @param array $fieldTypes
+ * @param array $premiumParams
+ * @param array $membershipLineItems line items specifically relating to memberships
*/
- public function processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams) {
+ public function processMembership($membershipParams, $contactID, $customFieldsFormatted, $fieldTypes, $premiumParams, $membershipLineItems) {
try {
$membershipTypeID = (array) $membershipParams['selectMembership'];
- $membershipDetails = CRM_Member_BAO_Membership::buildMembershipTypeValues($this);
- $this->assign('membership_name', CRM_Utils_Array::value('name', $membershipDetails));
+ $membershipTypes = CRM_Member_BAO_Membership::buildMembershipTypeValues($this);
+
+ $membershipType = empty($membershipTypes) ? array() : reset($membershipTypes);
+ $this->assign('membership_name', CRM_Utils_Array::value('name', $membershipType));
+
$isPaidMembership = FALSE;
if($this->_amount > 0.0 && $membershipParams['amount']) {
//amount must be greater than zero for
$contributionTypeId = $this->_values['financial_type_id'];
}
else {
- $contributionTypeId = CRM_Utils_Array::value( 'financial_type_id', $membershipDetails );
- if (!$contributionTypeId) {
- $contributionTypeId = CRM_Utils_Array::value('financial_type_id' ,$membershipParams);
- }
+ $contributionTypeId = CRM_Utils_Array::value('financial_type_id', $membershipType, CRM_Utils_Array::value('financial_type_id' ,$membershipParams));
}
CRM_Member_BAO_Membership::postProcessMembership($membershipParams, $contactID,
- $this, $premiumParams, $customFieldsFormatted, $fieldTypes, $membershipDetails, $membershipTypeID, $isPaidMembership, $this->_membershipId, $isProcessSeparateMembershipTransaction, $contributionTypeId
+ $this, $premiumParams, $customFieldsFormatted, $fieldTypes, $membershipType, $membershipTypeID, $isPaidMembership, $this->_membershipId, $isProcessSeparateMembershipTransaction, $contributionTypeId,
+ $membershipLineItems
);
$this->assign('membership_assign', TRUE);
$this->set('membershipTypeID', $membershipParams['selectMembership']);
$priceFields = CRM_Price_BAO_PriceSet::getSetDetail($priceSetID);
$priceSetFields = reset($priceFields);
$form->_values['fee'] = $priceSetFields['fields'];
+ $form->_priceSetId = $priceSetID;
$form->setFormAmountFields($priceSetID);
$priceFields = $priceFields[$priceSetID]['fields'];
CRM_Price_BAO_PriceSet::processAmount($priceFields, $paramsProcessedForForm, $lineItems, 'civicrm_contribution');
else {
$dao->whereAdd('is_test IS NULL OR is_test = 0');
}
-
+
//avoid pending membership as current membership: CRM-3027
$statusIds[] = array_search('Pending', CRM_Member_PseudoConstant::membershipStatus());
if (!$membershipId) {
$statusIds[] = array_search('Cancelled', CRM_Member_PseudoConstant::membershipStatus());
}
$dao->whereAdd('status_id NOT IN ( ' . implode(',', $statusIds) . ')');
-
+
// order by start date to find most recent membership first, CRM-4545
$dao->orderBy('start_date DESC');
*
* @param array $membershipParams array of membership fields
* @param int $contactID contact id
- * @param object $form form object
+ * @param CRM_Contribute_Form_Contribution_Confirm $form Confirmation form object
*
* @param $premiumParams
* @param null $customFieldsFormatted
* @param $isProcessSeparateMembershipTransaction
*
* @param $defaultContributionTypeID
- *
+ * @param array $membershipLineItems Line items specific to membership payment that is separate to contribution
* @throws CRM_Core_Exception
- * @internal param \isProcessSeparateMembershipTransaction $bool $
- *
- * @internal param $singleMembershipTypeID
*
* @return void
* @access public
*/
public static function postProcessMembership($membershipParams, $contactID, &$form, $premiumParams,
$customFieldsFormatted = NULL, $includeFieldTypes = NULL, $membershipDetails, $membershipTypeID, $isPaidMembership, $membershipID,
- $isProcessSeparateMembershipTransaction, $defaultContributionTypeID) {
+ $isProcessSeparateMembershipTransaction, $defaultContributionTypeID, $membershipLineItems) {
$result = NULL;
$isTest = CRM_Utils_Array::value('is_test', $membershipParams, FALSE);
$errors = $createdMemberships = array();
if ($isProcessSeparateMembershipTransaction) {
try {
- $membershipContribution = self::processSecondaryFinancialTransaction($contactID, $form, $membershipDetails, $membershipParams, $isTest);
+ $lineItems = $form->_lineItem = $membershipLineItems;
+ $membershipContribution = self::processSecondaryFinancialTransaction($contactID, $form, $membershipParams, $isTest, $membershipLineItems, CRM_Utils_Array::value('minimum_fee', $membershipDetails, 0), CRM_Utils_Array::value('financial_type_id', $membershipDetails));
}
catch (CRM_Core_Exception $e) {
$errors[2] = $e->getMessage();
* Where a second separate financial transaction is supported we will process it here
*
* @param $contactID
- * @param $form
+ * @param CRM_Contribute_Form_Contribution_Confirm $form
* @param $membershipDetails
* @param $tempParams
- * @param $errors
* @param $isTest
*
- * @throws Exception
- * @internal param $minimumFee
+ * @throws CRM_Core_Exception
* @return CRM_Contribute_BAO_Contribution
*/
- public static function processSecondaryFinancialTransaction($contactID, &$form, $membershipDetails, $tempParams, $isTest) {
- $minimumFee = CRM_Utils_Array::value('minimum_fee', $membershipDetails);
- $lineItems = $form->_lineItem = $form->_memLineItem;
+ public static function processSecondaryFinancialTransaction($contactID, &$form, $tempParams, $isTest, $lineItems, $minimumFee, $financialTypeID) {
$contributionType = new CRM_Financial_DAO_FinancialType();
- $contributionType->id = CRM_Utils_Array::value('financial_type_id', $membershipDetails);
+ $contributionType->id = $financialTypeID;
if (!$contributionType->find(TRUE)) {
CRM_Core_Error::fatal(ts("Could not find a system table"));
}
// irrespective of the value, CRM-2888
$tempParams['cms_create_account'] = 0;
- $pending = $form->_params['is_pay_later'] ? ((CRM_Utils_Array::value('minimum_fee', $membershipDetails, 0) > 0.0) ? TRUE : FALSE) : FALSE;
+ $pending = $form->_params['is_pay_later'] ? (($minimumFee > 0.0) ? TRUE : FALSE) : FALSE;
//set this variable as we are not creating pledge for
//separate membership payment contribution.
- //so for differentiating membership contributon from
+ //so for differentiating membership contribution from
//main contribution.
$form->_params['separate_membership_payment'] = 1;
$membershipContribution = CRM_Contribute_Form_Contribution_Confirm::processContribution($form,
self::$_renewalActType = CRM_Utils_Array::key('Membership Renewal', $activityTypes);
self::$_signupActType = CRM_Utils_Array::key('Membership Signup', $activityTypes);
}
-
+
/**
* Get all Cancelled Membership(s) for a contact
*
* @param int $contactID contact id
- * @param boolean $isTest mode of payment
+ * @param boolean $isTest mode of payment
*
* @return array of membership type
* @static
static function getContactsCancelledMembership($contactID, $isTest = FALSE) {
if (!$contactID) {
return array();
- }
+ }
$allStatus = CRM_Member_PseudoConstant::membershipStatus();
$query = 'SELECT membership_type_id FROM civicrm_membership WHERE contact_id = %1 AND status_id = %2 AND is_test = %3';
$queryParams = array(
2 => array(array_search('Cancelled', $allStatus), 'Integer'),
3 => array($isTest, 'Boolean'),
);
-
+
$dao = CRM_Core_DAO::executeQuery($query, $queryParams);
$cancelledMembershipIds = array();
while ($dao->fetch()) {