--CRM-15055, more work to create line item from font end
authorPradeep Nayak <pradeep.nayak@webaccess.co.in>
Sat, 30 Aug 2014 14:02:13 +0000 (19:32 +0530)
committerPradeep Nayak <pradeep.nayak@webaccess.co.in>
Wed, 3 Sep 2014 09:27:19 +0000 (14:57 +0530)
CRM/Contribute/Form/Contribution/Confirm.php
CRM/Member/BAO/Membership.php

index 997f3c40bfb8c2e53f6a42ae2d144589ebebff5d..28f3322878cb1fa969447235889b04e550615290 100644 (file)
@@ -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'];
index d8735c4f218332f7372aa4a7702c3ff8beae57dd..bb9bdccbeaff0a5b247002a3ad01e8b7e87aa99d 100644 (file)
@@ -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) {