From 25687f566cbc082366821212f9e34a1530c52370 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 23 Aug 2023 07:58:04 +1200 Subject: [PATCH] Move setting of discount back to calling function This is ths only one of the forms that has context as a property so the only one that does it --- CRM/Event/Form/Participant.php | 17 +++++++++++++++++ CRM/Event/Form/Registration.php | 18 ------------------ CRM/Event/Form/Registration/Register.php | 2 +- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 636e403526..7b41ea97d8 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -1429,6 +1429,23 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment //retrieve custom information $form->_values = []; CRM_Event_Form_Registration::initEventFee($form, $event['id'], FALSE, $this->getPriceSetID()); + if ($form->_context === 'standalone' || $form->_context === 'participant') { + $discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($event['id'], 'civicrm_event'); + if (is_array($discountedEvent)) { + foreach ($discountedEvent as $key => $discountedPriceSetID) { + $discountedPriceSet = CRM_Price_BAO_PriceSet::getSetDetail($discountedPriceSetID); + $discountedPriceSet = $discountedPriceSet[$discountedPriceSetID] ?? NULL; + $form->_values['discount'][$key] = $discountedPriceSet['fields'] ?? NULL; + $fieldID = key($form->_values['discount'][$key]); + // @todo - this may be unused. + $form->_values['discount'][$key][$fieldID]['name'] = CRM_Core_DAO::getFieldValue( + 'CRM_Price_DAO_PriceSet', + $discountedPriceSetID, + 'title' + ); + } + } + } //if payment done, no need to build the fee block. if (!empty($form->_paymentId)) { //fix to display line item in update mode. diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index 17aa8c07c1..26b938cf46 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -585,24 +585,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form { } self::initSet($form, $doNotIncludeExpiredFields, $priceSetId); - if (property_exists($form, '_context') && ($form->_context == 'standalone' - || $form->_context == 'participant') - ) { - $discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($eventID, 'civicrm_event'); - if (is_array($discountedEvent)) { - foreach ($discountedEvent as $key => $priceSetId) { - $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId); - $priceSet = $priceSet[$priceSetId] ?? NULL; - $form->_values['discount'][$key] = $priceSet['fields'] ?? NULL; - $fieldID = key($form->_values['discount'][$key]); - $form->_values['discount'][$key][$fieldID]['name'] = CRM_Core_DAO::getFieldValue( - 'CRM_Price_DAO_PriceSet', - $priceSetId, - 'title' - ); - } - } - } $eventFee = $form->_values['fee'] ?? NULL; if (!is_array($eventFee) || empty($eventFee)) { $form->_values['fee'] = []; diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index 4174115c90..82219a43d2 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -540,7 +540,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { * Form object. * @param bool $required * True if you want to add formRule. - * @param null $discountId + * @param int|null $discountId * Discount id for the event. * @param int|null $priceSetID * -- 2.25.1