Pass priceSetID into buildAmount
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 22 Aug 2023 09:59:12 +0000 (21:59 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 22 Aug 2023 19:41:50 +0000 (07:41 +1200)
This gets away from it needing to be set on the form as a property

CRM/Event/Form/Participant.php
CRM/Event/Form/ParticipantFeeSelection.php
CRM/Event/Form/Registration/AdditionalParticipant.php
CRM/Event/Form/Registration/Register.php

index bca7e003416a42211a0049b340bc1caa0121a11e..636e40352603c688ea8f20915ebc247357647962 100644 (file)
@@ -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;
index 048b57068c43144178dc91d093a795fb17c84979..7ad90dcc2a1f990219d74b791e6998ae694b6be6 100644 (file)
@@ -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'];
index 46a64f7e5c461b3d9dcfa99a8b36d1371b338949..7d3baa4cc1a2b088f815df0e26bc584c84263493 100644 (file)
@@ -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.
index 58ec80251edc440e9281d06cf845d2b9a64ba3b4..4174115c904439e86371760a687a939012487720 100644 (file)
@@ -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)) {