Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] Move instantiation of Order class to earlier in function #19402

Merged
merged 1 commit into from
Jan 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 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 @@ -307,16 +314,13 @@ public function storeContactFields($formValues) {
$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;
Expand Down Expand Up @@ -453,11 +457,18 @@ protected function getPriceSetID(array $params): int {
* @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;
}

Expand All @@ -483,16 +494,11 @@ public function testSubmit(array $formValues): void {
* @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