Skip to content

Commit

Permalink
[REF] Move instantiation of Order class to earlier in function
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eileenmcnaughton committed Jan 17, 2021
1 parent efbd974 commit f7c1c6c
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions CRM/Member/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -453,7 +460,13 @@ protected function getPriceSetID(array $params): int {
* @return array
*/
protected function setPriceSetParameters(array $formValues): array {
$this->_priceSetId = $this->getPriceSetID($formValues);
$this->order = new CRM_Financial_BAO_Order();
$this->order->setPriceSelectionFromUnfilteredInput($formValues);
$this->order->setPriceSetID($this->getPriceSetID($formValues));
$this->order->setOverrideTotalAmount($formValues['total_amount']);
$this->order->setOverrideFinancialTypeID((int) $formValues['financial_type_id']);
// The below will be phased out in favour of the above over time.
$this->_priceSetId = $this->order->getPriceSetID();
$priceSetDetails = $this->getPriceSetDetails($formValues);
$this->_priceSet = $priceSetDetails[$this->_priceSetId];
// process price set and get total amount and line items.
Expand Down Expand Up @@ -483,16 +496,11 @@ public function testSubmit($formValues) {
* @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(),
];
}

Expand Down

0 comments on commit f7c1c6c

Please sign in to comment.