Compare currencies as well as amounts on template Contribution change
authorRich Lott / Artful Robot <code.commits@artfulrobot.uk>
Mon, 25 Apr 2022 16:33:04 +0000 (17:33 +0100)
committerRich Lott / Artful Robot <code.commits@artfulrobot.uk>
Tue, 26 Apr 2022 13:12:58 +0000 (14:12 +0100)
Update CRM/Contribute/BAO/ContributionRecur.php

CRM/Contribute/BAO/ContributionRecur.php

index cc23834d867b9cd46e60788423ca1d8caef07c70..e68e08d17962de63b20c1acbecddb24cd6dd69a6 100644 (file)
@@ -995,11 +995,12 @@ INNER JOIN civicrm_contribution       con ON ( con.id = mp.contribution_id )
       ->execute()
       ->first();
 
-    if ($contribution->total_amount === NULL) {
+    if ($contribution->total_amount === NULL || $contribution->currency === NULL) {
+      // The contribution has not been fully loaded, so fetch a full copy now.
       $contribution->find(TRUE);
     }
 
-    if (!CRM_Utils_Money::equals($contributionRecur['amount'], $contribution->total_amount, $contribution->currency)) {
+    if ($contribution->currency !== $contributionRecur['currency'] || !CRM_Utils_Money::equals($contributionRecur['amount'], $contribution->total_amount, $contribution->currency)) {
       ContributionRecur::update(FALSE)
         ->addValue('amount', $contribution->total_amount)
         ->addValue('currency', $contribution->currency)