From f52b324190dbf2ace650206c605274836bbe70a6 Mon Sep 17 00:00:00 2001 From: eileen Date: Sun, 27 Sep 2020 18:34:09 +1300 Subject: [PATCH] [Ref] Extract getOrderParams Overview ---------------------------------------- Minor extraction Before ---------------------------------------- Code not re-usable After ---------------------------------------- Code is re-useable, basis for further fix Technical Details ---------------------------------------- Comments ---------------------------------------- Note this ties into https://lab.civicrm.org/dev/membership/-/issues/28 --- CRM/Member/Form/MembershipRenewal.php | 36 +++++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index 55600909ef..6defa6faec 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -610,22 +610,13 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { if (!empty($this->_params['record_contribution']) || $this->_mode) { // set the source - list($userName) = CRM_Contact_BAO_Contact_Location::getEmailDetails(CRM_Core_Session::singleton()->get('userID')); + [$userName] = CRM_Contact_BAO_Contact_Location::getEmailDetails(CRM_Core_Session::singleton()->get('userID')); $this->_params['contribution_source'] = "{$this->membershipTypeName} Membership: Offline membership renewal (by {$userName})"; //create line items $this->_params = $this->setPriceSetParameters($this->_params); - $order = new CRM_Financial_BAO_Order(); - $order->setPriceSelectionFromUnfilteredInput($this->_params); - $order->setPriceSetID(self::getPriceSetID($this->_params)); - $order->setOverrideTotalAmount($this->_params['total_amount']); - $order->setOverrideFinancialTypeID((int) $this->_params['financial_type_id']); - - $this->_params['lineItems'][$this->_priceSetId] = $order->getLineItems(); - // This is one of those weird & wonderful legacy params we aim to get rid of. - $this->_params['processPriceSet'] = TRUE; - $this->_params['tax_amount'] = $order->getTotalTaxAmount(); + $this->_params = array_merge($this->_params, $this->getOrderParams()); //assign contribution contact id to the field expected by recordMembershipContribution if ($this->_contributorContactID != $this->_contactID) { @@ -805,4 +796,27 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { return $membership; } + /** + * Get order related params. + * + * In practice these are contribution params but later they cann be used with the Order api. + * + * @return array + * + * @throws \CiviCRM_API3_Exception + */ + protected function getOrderParams(): array { + $order = new CRM_Financial_BAO_Order(); + $order->setPriceSelectionFromUnfilteredInput($this->_params); + $order->setPriceSetID(self::getPriceSetID($this->_params)); + $order->setOverrideTotalAmount($this->_params['total_amount']); + $order->setOverrideFinancialTypeID((int) $this->_params['financial_type_id']); + return [ + 'lineItems' => [$this->_priceSetId => $order->getLineItems()], + // This is one of those weird & wonderful legacy params we aim to get rid of. + 'processPriceSet' => TRUE, + 'tax_amount' => $order->getTotalTaxAmount(), + ]; + } + } -- 2.25.1