From b205ce09283984282b7323fe9f92997b07a521f2 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Sat, 30 Aug 2014 19:32:13 +0530 Subject: [PATCH] --CRM-15055, more work to create line item from font end --- CRM/Contribute/Form/Contribution/Confirm.php | 3 ++- CRM/Member/BAO/Membership.php | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 997f3c40bf..28f3322878 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -118,7 +118,8 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr 'address_id' => $addressID, //setting to make available to hook - although seems wrong to set on form for BAO hook availability 'soft_credit_to' => $softCreditToID, - 'line_item' => $lineItems + 'line_item' => $lineItems, + 'skipLineItem' => CRM_Utils_Array::value('skipLineItem', $params, 0) ); if (!$online && isset($params['thankyou_date'])) { $contributionParam['thankyou_date'] = $params['thankyou_date']; diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index d8735c4f21..bb9bdccbea 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1273,7 +1273,20 @@ AND civicrm_membership.is_test = %2"; $result = $membershipContribution = NULL; $isTest = CRM_Utils_Array::value('is_test', $membershipParams, FALSE); $errors = $createdMemberships = array(); - + + $membershipLineItem = array(); + if (is_array($membershipTypeID)) { + foreach ($form->_lineItem[$form->_priceSetId] as $key => $line) { + if (!empty($line['membership_type_id'])) { + $membershipLineItem[$line['membership_type_id']] = $line; + unset($form->_lineItem[$form->_priceSetId][$key]); + } + } + if (empty($form->_lineItem[$form->_priceSetId])) { + $membershipParams['skipLineItem'] = TRUE; + } + } + if ($isPaidMembership) { $result = CRM_Contribute_BAO_Contribution_Utils::processConfirm($form, $membershipParams, $premiumParams, $contactID, @@ -1318,6 +1331,10 @@ AND civicrm_membership.is_test = %2"; foreach ($membershipTypeID as $memType) { $numTerms = CRM_Utils_Array::value($memType, $typesTerms, 1); $createdMemberships[$memType] = self::createOrRenewMembership($membershipParams, $contactID, $customFieldsFormatted, $membershipID, $memType, $isTest, $numTerms, $membershipContribution, $form); + if (CRM_Utils_Array::value($memType, $membershipLineItem)) { + CRM_Price_BAO_LineItem::processPriceSet($createdMemberships[$memType]->id, array($form->_priceSetId => array($membershipLineItem[$memType])), $membershipContribution); + $form->_lineItem[$form->_priceSetId][] = $membershipLineItem[$memType]; + } } if ($form->_priceSetId && !empty($form->_useForMember) && !empty($form->_lineItem)) { foreach ($form->_lineItem[$form->_priceSetId] as & $priceFieldOp) { -- 2.25.1