From 270ff672b6034f29b7e06fde8c17d45b58df6fe5 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 27 Oct 2016 23:24:04 +1300 Subject: [PATCH] Fix line item fetch on membership template with priceset. In conjunction with checking Pradeep's code tidy up I found that the code here is not currently presenting membership details correctly. I used Pradeep's solution, but I also clarified the process to process quickConfig as close to the place where it is used as possible - in this case it directly affects the display of the lines. Ideally we would assign something clearer to the template such as displayLineItemRows rahter than these mystical parameters" error: pathspec 'Fix line item fetch on membership template with priceset. In conjunction with checking Pradeep's code tidy up I found that the code here is not currently presenting membership details correctly. I used Pradeep's solution, but I also clarified the process to process quickConfig as close to the place where it is used as possible - in this case it directly affects the display of the lines. Ideally we would assign something clearer to the template such as displayLineItemRows rahter than these mystical parameters --- CRM/Contribute/BAO/Contribution.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 1237d2576f..19f0d9c562 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2639,10 +2639,12 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac } // set lineItem for contribution if ($this->id) { - $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->id, 'contribution', 1); - if (!empty($lineItem)) { - $itemId = key($lineItem); - foreach ($lineItem as &$eachItem) { + $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($this->id); + if (!empty($lineItems)) { + $firstLineItem = reset($lineItems); + $priceSet = civicrm_api3('PriceSet', 'getsingle', array('id' => $firstLineItem['price_set_id'], 'return' => 'is_quick_config, id')); + $values['priceSetID'] = $priceSet['id']; + foreach ($lineItems as &$eachItem) { if (isset($this->_relatedObjects['membership']) && is_array($this->_relatedObjects['membership']) && array_key_exists($eachItem['membership_type_id'], $this->_relatedObjects['membership'])) { @@ -2650,9 +2652,11 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac $eachItem['start_date'] = CRM_Utils_Date::customFormat($this->_relatedObjects['membership'][$eachItem['membership_type_id']]->start_date); $eachItem['end_date'] = CRM_Utils_Date::customFormat($this->_relatedObjects['membership'][$eachItem['membership_type_id']]->end_date); } + // This is actually used in conjunction with is_quick_config in the template & we should deprecate it. + // However, that does create upgrade pain so would be better to be phased in. + $values['useForMember'] = !$priceSet['is_quick_config']; } - $values['lineItem'][0] = $lineItem; - $values['priceSetID'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItem[$itemId]['price_field_id'], 'price_set_id'); + $values['lineItem'][0] = $lineItems; } } @@ -2806,9 +2810,6 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac $billingMode = empty($this->_relatedObjects['paymentProcessor']) ? CRM_Core_Payment::BILLING_MODE_NOTIFY : $this->_relatedObjects['paymentProcessor']['billing_mode']; $template->assign('contributeMode', CRM_Utils_Array::value($billingMode, CRM_Core_SelectValues::contributeMode())); - if (!empty($values['lineItem']) && !empty($this->_relatedObjects['membership'])) { - $values['useForMember'] = TRUE; - } //assign honor information to receipt message $softRecord = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($this->id); -- 2.25.1