$params['contribution'] = self::recordMembershipContribution($memInfo, $ids);
}
- if (CRM_Utils_Array::value('lineItems', $params) && empty($params['contributionId'])) {
- CRM_Price_BAO_LineItem::processPriceSet($membership->id, $params['lineItems'], CRM_Utils_Array::value('contribution', $params));
+ if (!empty($params['lineItems'])) {
+ $params['line_item'] = $params['lineItems'];
+ }
+
+ //do cleanup line items if membership edit the Membership type.
+ if (empty($ids['contribution']) && !empty($ids['membership'])) {
+ CRM_Price_BAO_LineItem::deleteLineItems($ids['membership'], 'civicrm_membership');
+ }
+
+ if (!empty($params['line_item']) && empty($ids['contribution'])) {
+ CRM_Price_BAO_LineItem::processPriceSet($membership->id, $params['line_item'], CRM_Utils_Array::value('contribution', $params));
}
//insert payment record for this membership
$membershipType = implode(', ', $membershipTypes);
- //do cleanup line items if membership edit the Membership Fee.
- $params['contributionId'] = CRM_Utils_Array::value('contribution_id', $this->_defaultValues);
- if (empty($params['contributionId']) && $this->_id) {
- CRM_Price_BAO_LineItem::deleteLineItems($this->_id, 'civicrm_membership');
- }
-
// Retrieve the name and email of the current user - this will be the FROM for the receipt email
list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($ids['userId']);
$dao->id = $formatValues['membership_id'];
$dates = array('join_date', 'start_date', 'end_date');
foreach ($dates as $v) {
- if (empty($formatted[$v])) {
+ if (empty($formatted[$v])) {
$formatted[$v] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $formatValues['membership_id'], $v);
}
}
'membership' => $formatValues['membership_id'],
'userId' => $session->get('userID'),
);
-
+
+ if (empty($params['line_item']) && !empty($formatted['membership_type_id'])) {
+ CRM_Price_BAO_LineItem::getLineItemArray($formatted, NULL, 'membership', $formatted['membership_type_id']);
+ }
+
$newMembership = CRM_Member_BAO_Membership::create($formatted, $ids, TRUE);
if (civicrm_error($newMembership)) {
array_unshift($values, $newMembership['is_error'] . ' for Membership ID ' . $formatValues['membership_id'] . '. Row was skipped.');
static function getLineItemArray(&$params, $entityId = NULL, $entityTable = 'contribution', $isRelatedID = FALSE) {
if (!$entityId) {
- $priceSetDetails = CRM_Price_BAO_PriceSet::getDefaultPriceSet();
+ $priceSetDetails = CRM_Price_BAO_PriceSet::getDefaultPriceSet($entityTable);
+ $totalAmount = CRM_Utils_Array::value('total_amount', $params);
+ $financialType = CRM_Utils_Array::value('financial_type_id', $params);
foreach ($priceSetDetails as $values) {
+ if ($entityTable == 'membership') {
+ if ($isRelatedID != $values['membership_type_id']) {
+ continue;
+ }
+ if (!$totalAmount) {
+ $totalAmount = $values['amount'];
+ }
+ $financialType = $values['financial_type_id'];
+ }
$params['line_item'][$values['setID']][$values['priceFieldID']] = array(
'price_field_id' => $values['priceFieldID'],
'price_field_value_id' => $values['priceFieldValueID'],
'label' => $values['label'],
'qty' => 1,
- 'unit_price' => $params['total_amount'],
- 'line_total' => $params['total_amount'],
- 'financial_type_id' => $params['financial_type_id']
+ 'unit_price' => $totalAmount,
+ 'line_total' => $totalAmount,
+ 'financial_type_id' => $financialType,
+ 'membership_type_id' => $values['membership_type_id']
);
+ break;
}
}
else {
}
$sql = "
-SELECT ps.id AS setID, pfv.price_field_id AS priceFieldID, pfv.id AS priceFieldValueID, pfv.name, pfv.label
+SELECT ps.id AS setID, pfv.price_field_id AS priceFieldID, pfv.id AS priceFieldValueID, pfv.name, pfv.label, pfv.membership_type_id, pfv.amount, pfv.financial_type_id
FROM civicrm_price_set ps
LEFT JOIN civicrm_price_field pf ON pf.`price_set_id` = ps.id
LEFT JOIN civicrm_price_field_value pfv ON pfv.price_field_id = pf.id
$defaultPriceSet[$dao->priceFieldValueID]['name'] = $dao->name;
$defaultPriceSet[$dao->priceFieldValueID]['label'] = $dao->label;
$defaultPriceSet[$dao->priceFieldValueID]['priceFieldValueID'] = $dao->priceFieldValueID;
+ $defaultPriceSet[$dao->priceFieldValueID]['membership_type_id'] = $dao->membership_type_id;
+ $defaultPriceSet[$dao->priceFieldValueID]['amount'] = $dao->amount;
+ $defaultPriceSet[$dao->priceFieldValueID]['financial_type_id'] = $dao->financial_type_id;
}
return $defaultPriceSet;
//need to pass action to handle related memberships.
$params['action'] = $action;
+ if (empty($params['line_item']) && !empty($params['membership_type_id'])) {
+ CRM_Price_BAO_LineItem::getLineItemArray($params, NULL, 'membership', $params['membership_type_id']);
+ }
+
$membershipBAO = CRM_Member_BAO_Membership::create($params, $ids, TRUE);
if (array_key_exists('is_error', $membershipBAO)) {