From 4c04d5a3c15ceac36a0e338b04b75d7316efca4b Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 23 Jun 2023 16:41:27 -0700 Subject: [PATCH] Contribution WorkflowTrait updates to support event template changes --- .../WorkflowMessage/ContributionTrait.php | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/CRM/Contribute/WorkflowMessage/ContributionTrait.php b/CRM/Contribute/WorkflowMessage/ContributionTrait.php index 2951c74803..433ef71d67 100644 --- a/CRM/Contribute/WorkflowMessage/ContributionTrait.php +++ b/CRM/Contribute/WorkflowMessage/ContributionTrait.php @@ -4,7 +4,7 @@ use Civi\Api4\Membership; /** * @method array getContribution() - * @method ?int getContributionID() + * @method int|null getContributionID() * @method $this setContributionID(?int $contributionId) */ trait CRM_Contribute_WorkflowMessage_ContributionTrait { @@ -70,6 +70,11 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait { if (!$this->order && $this->contributionID) { $this->order = new CRM_Financial_BAO_Order(); $this->order->setTemplateContributionID($this->contributionID); + if (!empty($this->eventID)) { + // Temporary support for tests that are making a mess of this. + // It should always be possible to get this from the line items. + $this->order->setPriceSetIDByEventPageID($this->eventID); + } } return $this->order; } @@ -147,11 +152,20 @@ trait CRM_Contribute_WorkflowMessage_ContributionTrait { } $this->taxRateBreakdown = []; foreach ($this->getLineItems() as $lineItem) { - $this->taxRateBreakdown[$lineItem['tax_rate']] = [ - 'amount' => $lineItem['tax_amount'] ?? 0, - 'rate' => $lineItem['tax_rate'], - 'percentage' => sprintf('%.2f', $lineItem['tax_rate']), - ]; + if (!isset($this->taxRateBreakdown[$lineItem['tax_rate']])) { + $this->taxRateBreakdown[$lineItem['tax_rate']] = [ + 'amount' => 0, + 'rate' => $lineItem['tax_rate'], + 'percentage' => sprintf('%.2f', $lineItem['tax_rate']), + ]; + } + $this->taxRateBreakdown[$lineItem['tax_rate']]['amount'] += $lineItem['tax_amount'] ?? 0; + } + // Remove the rates with no value. + foreach ($this->taxRateBreakdown as $rate => $details) { + if ($details['amount'] === 0.0) { + unset($this->taxRateBreakdown[$rate]); + } } if (array_keys($this->taxRateBreakdown) === [0]) { // If the only tax rate charged is 0% then no tax breakdown is returned. -- 2.25.1