Skip to content
Snippets Groups Projects
Unverified Commit 368a5cb2 authored by Seamus Lee's avatar Seamus Lee Committed by GitHub
Browse files

Merge pull request #21118 from eileenmcnaughton/5.40

5.40 contribution save regression
parents b914d938 32322d09
Branches
Tags
No related merge requests found
......@@ -914,7 +914,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
$order = new CRM_Financial_BAO_Order();
$order->setPriceSelectionFromUnfilteredInput($fields);
if (isset($fields['total_amount'])) {
$order->setOverrideTotalAmount($fields['total_amount']);
$order->setOverrideTotalAmount((float) CRM_Utils_Rule::cleanMoney($fields['total_amount']));
}
$lineItems = $order->getLineItems();
try {
......
......@@ -65,6 +65,30 @@ class CRM_Financial_BAO_Order {
*/
protected $defaultFinancialTypeID;
/**
* Number of line items.
*
* @var int
*/
protected $lineItemCount;
/**
* @return int
*/
public function getLineItemCount(): int {
if (!isset($this->lineItemCount)) {
$this->lineItemCount = count($this->getPriceOptions()) || count($this->lineItems);
}
return $this->lineItemCount;
}
/**
* @param int $lineItemCount
*/
public function setLineItemCount(int $lineItemCount): void {
$this->lineItemCount = $lineItemCount;
}
/**
* @return int
*/
......@@ -179,7 +203,7 @@ class CRM_Financial_BAO_Order {
public function getOverrideTotalAmount() {
// The override amount is only valid for quick config price sets where more
// than one field has not been selected.
if (!$this->overrideTotalAmount || !$this->supportsOverrideAmount() || count($this->getPriceOptions()) > 1) {
if (!$this->overrideTotalAmount || $this->getLineItemCount() > 1) {
return FALSE;
}
return $this->overrideTotalAmount;
......@@ -190,9 +214,9 @@ class CRM_Financial_BAO_Order {
*
* @internal use in tested core code only.
*
* @param float $overrideTotalAmount
* @param float|null $overrideTotalAmount
*/
public function setOverrideTotalAmount(float $overrideTotalAmount): void {
public function setOverrideTotalAmount(?float $overrideTotalAmount): void {
$this->overrideTotalAmount = $overrideTotalAmount;
}
......@@ -573,6 +597,10 @@ class CRM_Financial_BAO_Order {
$lineItems[$newLine['price_field_value_id']] = $newLine;
}
}
// Set the line item count here because it is needed to determine whether
// we can use overrides and would not be set yet if we have loaded them from
// a template contribution.
$this->setLineItemCount(count($lineItems));
foreach ($lineItems as &$lineItem) {
// Set any pre-calculation to zero as we will calculate.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment