From 51c6be79558b0384dba24a9500836efe329b77a3 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 22 Aug 2023 21:59:12 +1200 Subject: [PATCH] Pass priceSetID into buildAmount This gets away from it needing to be set on the form as a property --- CRM/Event/Form/Participant.php | 2 +- CRM/Event/Form/ParticipantFeeSelection.php | 2 +- .../Form/Registration/AdditionalParticipant.php | 2 +- CRM/Event/Form/Registration/Register.php | 15 +++++++++------ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index bca7e00341..636e403526 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -1435,7 +1435,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment $form->assign('priceSet', $form->_priceSet ?? NULL); } else { - CRM_Event_Form_Registration_Register::buildAmount($form, TRUE, $form->getDiscountID()); + CRM_Event_Form_Registration_Register::buildAmount($form, TRUE, $form->getDiscountID(), $this->getPriceSetID()); } $lineItem = []; $totalTaxAmount = 0; diff --git a/CRM/Event/Form/ParticipantFeeSelection.php b/CRM/Event/Form/ParticipantFeeSelection.php index 048b57068c..7ad90dcc2a 100644 --- a/CRM/Event/Form/ParticipantFeeSelection.php +++ b/CRM/Event/Form/ParticipantFeeSelection.php @@ -172,7 +172,7 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form { $this->_values = []; CRM_Event_Form_Registration::initEventFee($this, $event['id'], $this->_action !== CRM_Core_Action::UPDATE, $this->getPriceSetID()); - CRM_Event_Form_Registration_Register::buildAmount($this, TRUE); + CRM_Event_Form_Registration_Register::buildAmount($this, TRUE, NULL, $this->getPriceSetID()); if (!CRM_Utils_System::isNull($this->_values['line_items'] ?? NULL)) { $lineItem[] = $this->_values['line_items']; diff --git a/CRM/Event/Form/Registration/AdditionalParticipant.php b/CRM/Event/Form/Registration/AdditionalParticipant.php index 46a64f7e5c..7d3baa4cc1 100644 --- a/CRM/Event/Form/Registration/AdditionalParticipant.php +++ b/CRM/Event/Form/Registration/AdditionalParticipant.php @@ -179,7 +179,7 @@ class CRM_Event_Form_Registration_AdditionalParticipant extends CRM_Event_Form_R $button = substr($this->controller->getButtonName(), -4); if ($this->_values['event']['is_monetary']) { - CRM_Event_Form_Registration_Register::buildAmount($this); + CRM_Event_Form_Registration_Register::buildAmount($this, TRUE, NULL, $this->_priceSetId); } //Add pre and post profiles on the form. diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index 58ec80251e..4174115c90 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -423,7 +423,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { // build amount only when needed, skip incase of event full and waitlisting is enabled // and few other conditions check preProcess() if (!$this->_noFees) { - self::buildAmount($this); + self::buildAmount($this, TRUE, NULL, $this->_priceSetId); } if (!$this->showPaymentOnConfirm) { CRM_Core_Payment_ProcessorForm::buildQuickForm($this); @@ -540,12 +540,13 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { * Form object. * @param bool $required * True if you want to add formRule. - * @param int $discountId + * @param null $discountId * Discount id for the event. + * @param int|null $priceSetID * * @throws \CRM_Core_Exception */ - public static function buildAmount(&$form, $required = TRUE, $discountId = NULL) { + public static function buildAmount(&$form, $required = TRUE, $discountId = NULL, $priceSetID = NULL) { $feeFields = $form->_values['fee'] ?? NULL; if (is_array($feeFields)) { @@ -578,11 +579,12 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { $className = CRM_Utils_System::getClassName($form); //build the priceset fields. - if (isset($form->_priceSetId) && $form->_priceSetId) { + if ($priceSetID) { //format price set fields across option full. self::formatFieldsForOptionFull($form); - $form->add('hidden', 'priceSetId', $form->_priceSetId); + // This is probably not required now - normally loaded from event .... + $form->add('hidden', 'priceSetId', $priceSetID); // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions $adminFieldVisible = FALSE; @@ -650,10 +652,11 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { } } } - $form->_priceSet['id'] = $form->_priceSet['id'] ?? $form->_priceSetId; + $form->_priceSet['id'] = $form->_priceSet['id'] ?? $priceSetID; $form->assign('priceSet', $form->_priceSet); } else { + // Is this reachable? $eventFeeBlockValues = $elements = $elementJS = []; foreach ($form->_feeBlock as $fee) { if (is_array($fee)) { -- 2.25.1