diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 885b98b75f98..15c70dd0ae6f 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -57,6 +57,8 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment * Price Set ID, if the new price set method is used * * @var int + * + * @internal use getPriceSetID(). */ public $_priceSetId; @@ -1436,7 +1438,8 @@ public function buildEventFeeForm($form) { //retrieve custom information $form->_values = []; - CRM_Event_Form_Registration::initEventFee($form, $event['id'], FALSE, $form->getDiscountID()); + + CRM_Event_Form_Registration::initEventFee($form, $event['id'], FALSE, $this->getPriceSetID()); CRM_Event_Form_Registration_Register::buildAmount($form, TRUE, $form->getDiscountID()); $lineItem = []; $totalTaxAmount = 0; @@ -2290,4 +2293,28 @@ public function getDiscountID(): ?int { return $this->_discountId ?: NULL; } + /** + * Get the Price Set ID in use. + * + * @return int|null + * + * @api This function will not change in a minor release and is supported for + * use outside of core. This annotation / external support for properties + * is only given where there is specific test cover. + * + * @noinspection PhpDocMissingThrowsInspection + * @noinspection PhpUnhandledExceptionInspection + */ + public function getPriceSetID(): ?int { + if (!$this->_priceSetId) { + if ($this->getDiscountID()) { + $this->_priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $this->getDiscountID(), 'price_set_id'); + } + else { + $this->_priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->getEventID()); + } + return $this->_priceSetId ?: NULL; + } + } + } diff --git a/CRM/Event/Form/ParticipantFeeSelection.php b/CRM/Event/Form/ParticipantFeeSelection.php index e27662096af5..fd3c51cfc7de 100644 --- a/CRM/Event/Form/ParticipantFeeSelection.php +++ b/CRM/Event/Form/ParticipantFeeSelection.php @@ -172,7 +172,7 @@ public function buildQuickForm() { //retrieve custom information $this->_values = []; - CRM_Event_Form_Registration::initEventFee($this, $event['id'], $this->_action !== CRM_Core_Action::UPDATE, $this->getDiscountID()); + CRM_Event_Form_Registration::initEventFee($this, $event['id'], $this->_action !== CRM_Core_Action::UPDATE, $this->getPriceSetID()); CRM_Event_Form_Registration_Register::buildAmount($this, TRUE); if (!CRM_Utils_System::isNull($this->_values['line_items'] ?? NULL)) { @@ -426,4 +426,26 @@ public function getEventID(): int { return $this->_eventId; } + /** + * Get the price set ID for the event. + * + * @return int|null + * + * @api This function will not change in a minor release and is supported for + * use outside of core. This annotation / external support for properties + * is only given where there is specific test cover. + * + * @noinspection PhpUnhandledExceptionInspection + * @noinspection PhpDocMissingThrowsInspection + */ + public function getPriceSetID(): ?int { + if ($this->getDiscountID()) { + $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $this->getDiscountID(), 'price_set_id'); + } + else { + $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->getEventID()); + } + return $priceSetId; + } + } diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index 5685a1d682d6..d27d95c8b66c 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -298,8 +298,10 @@ public function preProcess() { $this->assignPaymentProcessor($isPayLater); } - $discountId = $this->getDiscountID(); - self::initEventFee($this, $this->_eventId, TRUE, $discountId); + $priceSetID = $this->getPriceSetID(); + if ($priceSetID) { + self::initEventFee($this, $this->_eventId, TRUE, $priceSetID); + } // get the profile ids $ufJoinParams = [ @@ -567,24 +569,19 @@ public function buildCustom($id, $name) { /** * Initiate event fee. * - * @param CRM_Core_Form $form + * @param \CRM_Event_Form_Participant|\CRM_Event_Form_Registration|\CRM_Event_Form_ParticipantFeeSelection|\CRM_Event_Form_Task_Register $form * @param int $eventID * @param bool $doNotIncludeExpiredFields * See CRM-16456. - * @param int|null $discountId - * ID of any discount in use. + * @param int|null $priceSetId + * ID of the price set in use. * - * @throws Exception + * @throws \CRM_Core_Exception */ - public static function initEventFee(&$form, $eventID, $doNotIncludeExpiredFields = TRUE, $discountId = NULL) { - // get price info - - // retrive all active price set fields. - if ($discountId) { - $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id'); - } - else { - $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventID); + public static function initEventFee(&$form, $eventID, $doNotIncludeExpiredFields, $priceSetId): void { + if (!$priceSetId) { + CRM_Core_Error::deprecatedWarning('this should not be reachable'); + return; } self::initSet($form, $doNotIncludeExpiredFields, $priceSetId); @@ -1732,4 +1729,26 @@ protected function getDiscountID(): ?int { return $id ?: NULL; } + /** + * Get the price set ID for the event. + * + * @return int|null + * + * @api This function will not change in a minor release and is supported for + * use outside of core. This annotation / external support for properties + * is only given where there is specific test cover. + * + * @noinspection PhpUnhandledExceptionInspection + * @noinspection PhpDocMissingThrowsInspection + */ + public function getPriceSetID(): ?int { + if ($this->getDiscountID()) { + $priceSetID = (int) CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $this->getDiscountID(), 'price_set_id'); + } + else { + $priceSetID = (int) CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->getEventID()); + } + return $priceSetID ?: NULL; + } + }