From a817ccddb4ae483cc2167eb60872836492c9fab2 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 18 Jan 2021 09:51:58 +1300 Subject: [PATCH] [REF] Move instantiation of Order class to earlier in function This is part of making the Order object and it's methods available to the non-renewal form which has the same amount calculation bug the class is used to fix. Note the Order class is an internal class not the order api which we do wish to switch this form to using --- CRM/Member/Form.php | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/CRM/Member/Form.php b/CRM/Member/Form.php index 497047739d..b476a249a7 100644 --- a/CRM/Member/Form.php +++ b/CRM/Member/Form.php @@ -63,6 +63,13 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { */ public $_priceSet; + /** + * The order being processed. + * + * @var \CRM_Financial_BAO_Order + */ + protected $order; + /** * Explicitly declare the entity api name. */ @@ -307,16 +314,13 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { $this->_contactID = $formValues['contact_id']; } - list($this->_memberDisplayName, - $this->_memberEmail - ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); + [$this->_memberDisplayName, $this->_memberEmail] = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); //CRM-10375 Where the payer differs to the member the payer should get the email. // here we store details in order to do that if (!empty($formValues['soft_credit_contact_id'])) { $this->_receiptContactId = $this->_contributorContactID = $formValues['soft_credit_contact_id']; - list($this->_contributorDisplayName, - $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contributorContactID); + [$this->_contributorDisplayName, $this->_contributorEmail] = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contributorContactID); } else { $this->_receiptContactId = $this->_contributorContactID = $this->_contactID; @@ -453,11 +457,18 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { * @return array */ protected function setPriceSetParameters(array $formValues): array { + // process price set and get total amount and line items. $this->_priceSetId = $this->getPriceSetID($formValues); + $this->ensurePriceParamsAreSet($formValues); $priceSetDetails = $this->getPriceSetDetails($formValues); $this->_priceSet = $priceSetDetails[$this->_priceSetId]; - // process price set and get total amount and line items. - $this->ensurePriceParamsAreSet($formValues); + $this->order = new CRM_Financial_BAO_Order(); + $this->order->setPriceSelectionFromUnfilteredInput($formValues); + $this->order->setPriceSetID($this->getPriceSetID($formValues)); + if (isset($formValues['total_amount'])) { + $this->order->setOverrideTotalAmount($formValues['total_amount']); + } + $this->order->setOverrideFinancialTypeID((int) $formValues['financial_type_id']); return $formValues; } @@ -483,16 +494,11 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { * @throws \CiviCRM_API3_Exception */ protected function getOrderParams(): array { - $order = new CRM_Financial_BAO_Order(); - $order->setPriceSelectionFromUnfilteredInput($this->_params); - $order->setPriceSetID($this->getPriceSetID($this->_params)); - $order->setOverrideTotalAmount($this->_params['total_amount']); - $order->setOverrideFinancialTypeID((int) $this->_params['financial_type_id']); return [ - 'lineItems' => [$this->_priceSetId => $order->getLineItems()], + 'lineItems' => [$this->_priceSetId => $this->order->getLineItems()], // This is one of those weird & wonderful legacy params we aim to get rid of. 'processPriceSet' => TRUE, - 'tax_amount' => $order->getTotalTaxAmount(), + 'tax_amount' => $this->order->getTotalTaxAmount(), ]; } -- 2.25.1