From 22fe049dce9ec7443e162fb9264fde2d556bb011 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Fri, 18 Jul 2014 13:13:59 +0530 Subject: [PATCH] -- fixed code to save line item when contribution is updated for membership, CRM-14918 ---------------------------------------- * CRM-14918: Line Items are created for Participant when contribution is not recorded https://issues.civicrm.org/jira/browse/CRM-14918 --- CRM/Price/BAO/LineItem.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index ae1637e076..4d18eeae9b 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -55,16 +55,31 @@ class CRM_Price_BAO_LineItem extends CRM_Price_DAO_LineItem { * @static */ static function create(&$params) { - //create mode only as we don't support editing line items - - CRM_Utils_Hook::pre('create', 'LineItem', $params['entity_id'], $params); + $id = CRM_Utils_Array::value('id', $params); + if ($id) { + CRM_Utils_Hook::pre('edit', 'LineItem', $id, $params); + } + else { + CRM_Utils_Hook::pre('create', 'LineItem', $params['entity_id'], $params); + } + + // unset entity table and entity id in $params + // we never update the entity table and entity id during update mode + if ($id) { + unset($params['entity_id'], $params['entity_table']); + } $lineItemBAO = new CRM_Price_BAO_LineItem(); $lineItemBAO->copyValues($params); $return = $lineItemBAO->save(); - CRM_Utils_Hook::post('create', 'LineItem', $params['entity_id'], $params); + if ($id) { + CRM_Utils_Hook::post('edit', 'LineItem', $id, $params); + } + else { + CRM_Utils_Hook::post('create', 'LineItem', $params['entity_id'], $params); + } return $return; } -- 2.25.1