Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builds on #27049 to extract getPriceSetID() #27050

Merged
merged 3 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ 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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes any difference as things stand now, but shouldn't it be $form->getPriceSetID for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm - I've been trying to go the other way for consistency - ditch the use of form & even the passing of it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I guess it doesn't matter here as long as this doesn't get called from anywhere else, just looks a bit odd.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seamuslee001 yeah that needs cleaning up - although as long as this PR passes tests it is out of scope for it

//if payment done, no need to build the fee block.
if (!empty($form->_paymentId)) {
//fix to display line item in update mode.
Expand Down
29 changes: 27 additions & 2 deletions CRM/Event/Form/ParticipantFeeSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public function setDefaultValues() {
$params = ['id' => $this->_participantId];

CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
$priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_eventId);

$priceSetValues = CRM_Event_Form_EventFees::setDefaultPriceSet($this->_participantId, $this->_eventId, FALSE);
$priceFieldId = (array_keys($this->_values['fee']));
Expand Down Expand Up @@ -172,7 +171,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 +425,30 @@ 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably use this at 127 as well for consistency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, $priceSetId is unused, we can just remove 127.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

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());
}
// Currently some extensions, eg. civi-discount, might look for this. Once we can be
// sure all financial forms have the api-supported function `getPriceSetID` we can
// add some noise to attempts to get it & move people over.
$this->set('priceSetId', $priceSetID);
return $priceSetID;
}

}
51 changes: 35 additions & 16 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 @@ -571,20 +573,15 @@ public function buildCustom($id, $name) {
* @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 \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 @@ -674,7 +671,6 @@ private static function initSet($form, $doNotIncludeExpiredFields = FALSE, $pric
$required = TRUE;
}

$form->_priceSetId = $priceSetId;
$priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, $required, $doNotIncludeExpiredFields);
$form->_priceSet = $priceSet[$priceSetId] ?? NULL;
$form->_values['fee'] = $form->_priceSet['fields'] ?? NULL;
Expand Down Expand Up @@ -713,8 +709,6 @@ private static function initSet($form, $doNotIncludeExpiredFields = FALSE, $pric
if ($optionsMaxValueTotal) {
$form->_priceSet['optionsMaxValueDetails'] = $optionsMaxValueDetails;
}

$form->set('priceSetId', $form->_priceSetId);
$form->set('priceSet', $form->_priceSet);
}
}
Expand Down Expand Up @@ -1732,4 +1726,29 @@ 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->_priceSetId === NULL) {
if ($this->getDiscountID()) {
$this->_priceSetId = (int) CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $this->getDiscountID(), 'price_set_id');
}
else {
$this->_priceSetId = (int) CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->getEventID());
}
$this->set('priceSetId', $this->_priceSetId);
}
return $this->_priceSetId ?: NULL;
}

}