Skip to content

Commit

Permalink
Move setting of discount back to calling function
Browse files Browse the repository at this point in the history
This is ths only one of the forms that has context as a property so the only one that does it
  • Loading branch information
eileenmcnaughton committed Aug 22, 2023
1 parent 51c6be7 commit e4de92b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
16 changes: 16 additions & 0 deletions CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,22 @@ public function buildEventFeeForm($form) {
//retrieve custom information
$form->_values = [];
CRM_Event_Form_Registration::initEventFee($form, $event['id'], FALSE, $this->getPriceSetID());
if ($form->_context === 'standalone' || $form->_context === 'participant') {
$discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($event['id'], 'civicrm_event');
if (is_array($discountedEvent)) {
foreach ($discountedEvent as $key => $discountedPriceSetID) {
$discountedPriceSet = CRM_Price_BAO_PriceSet::getSetDetail($discountedPriceSetID);
$discountedPriceSet = $discountedPriceSet[$discountedPriceSetID] ?? NULL;
$form->_values['discount'][$key] = $discountedPriceSet['fields'] ?? NULL;
$fieldID = key($form->_values['discount'][$key]);
$form->_values['discount'][$key][$fieldID]['name'] = CRM_Core_DAO::getFieldValue(
'CRM_Price_DAO_PriceSet',
$discountedPriceSetID,
'title'
);
}
}
}
//if payment done, no need to build the fee block.
if (!empty($form->_paymentId)) {
//fix to display line item in update mode.
Expand Down
18 changes: 0 additions & 18 deletions CRM/Event/Form/Registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,24 +585,6 @@ public static function initEventFee(&$form, $eventID, $doNotIncludeExpiredFields
}
self::initSet($form, $doNotIncludeExpiredFields, $priceSetId);

if (property_exists($form, '_context') && ($form->_context == 'standalone'
|| $form->_context == 'participant')
) {
$discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($eventID, 'civicrm_event');
if (is_array($discountedEvent)) {
foreach ($discountedEvent as $key => $priceSetId) {
$priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId);
$priceSet = $priceSet[$priceSetId] ?? NULL;
$form->_values['discount'][$key] = $priceSet['fields'] ?? NULL;
$fieldID = key($form->_values['discount'][$key]);
$form->_values['discount'][$key][$fieldID]['name'] = CRM_Core_DAO::getFieldValue(
'CRM_Price_DAO_PriceSet',
$priceSetId,
'title'
);
}
}
}
$eventFee = $form->_values['fee'] ?? NULL;
if (!is_array($eventFee) || empty($eventFee)) {
$form->_values['fee'] = [];
Expand Down

0 comments on commit e4de92b

Please sign in to comment.