From: Pradeep Nayak Date: Fri, 18 Jul 2014 07:43:59 +0000 (+0530) Subject: -- fixed code to save line item when contribution is updated for membership, CRM... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=22fe049dce9ec7443e162fb9264fde2d556bb011;p=civicrm-core.git -- 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 --- 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; }