From f6f2f4da5ff3644c5a8265550e598a734093f864 Mon Sep 17 00:00:00 2001 From: Jon Waldstein Date: Mon, 9 Oct 2023 10:20:57 -0400 Subject: [PATCH] Feature: update backwards compatibility for donation level id (#7002) Co-authored-by: Jon Waldstein --- ...nateControllerDonationCreatedListeners.php | 6 ++- .../Listeners/UpdateDonationLevelId.php | 42 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/DonationForms/Listeners/UpdateDonationLevelId.php diff --git a/src/DonationForms/Actions/DispatchDonateControllerDonationCreatedListeners.php b/src/DonationForms/Actions/DispatchDonateControllerDonationCreatedListeners.php index c5648d2e02..7e1f26ffda 100644 --- a/src/DonationForms/Actions/DispatchDonateControllerDonationCreatedListeners.php +++ b/src/DonationForms/Actions/DispatchDonateControllerDonationCreatedListeners.php @@ -1,11 +1,14 @@ getDonationForm(), $donation, $subscription, $formData->getCustomFields()); (new TemporarilyReplaceLegacySuccessPageUri())($formData, $donation); (new AddRedirectUrlsToGatewayData())($formData, $donation); + (new UpdateDonationLevelId())($formData->getDonationForm(), $donation); } } \ No newline at end of file diff --git a/src/DonationForms/Listeners/UpdateDonationLevelId.php b/src/DonationForms/Listeners/UpdateDonationLevelId.php new file mode 100644 index 0000000000..dc886cd356 --- /dev/null +++ b/src/DonationForms/Listeners/UpdateDonationLevelId.php @@ -0,0 +1,42 @@ +schema()->getNodeByName('amount'); + + if (!$amountField) { + return; + } + + $donationLevel = array_search( + (float)$donation->intendedAmount()->formatToDecimal(), + $amountField->getLevels(), + true + ); + + if ($donationLevel !== false) { + $donation->levelId = (string)$donationLevel; + $donation->save(); + } + } +} \ No newline at end of file