Skip to content

Commit

Permalink
Extract getPriceSetID
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Aug 11, 2023
1 parent afb392b commit 1ff517e
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 17 deletions.
29 changes: 28 additions & 1 deletion CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

}
24 changes: 23 additions & 1 deletion CRM/Event/Form/ParticipantFeeSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}

}
49 changes: 34 additions & 15 deletions CRM/Event/Form/Registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

}

0 comments on commit 1ff517e

Please sign in to comment.