Skip to content

Commit

Permalink
Pass priceSetID into buildAmount
Browse files Browse the repository at this point in the history
This gets away from it needing to be set on the form as a property
  • Loading branch information
eileenmcnaughton committed Aug 22, 2023
1 parent 97d8f92 commit 1943162
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ public function buildEventFeeForm($form) {
$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;
Expand Down
2 changes: 1 addition & 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() {
$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'];
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Form/Registration/AdditionalParticipant.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function buildQuickForm() {
$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, FALSE, NULL, $this->_priceSetId);
}

//Add pre and post profiles on the form.
Expand Down
15 changes: 9 additions & 6 deletions CRM/Event/Form/Registration/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public function buildQuickForm() {
// 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);
Expand Down Expand Up @@ -540,12 +540,13 @@ public function buildQuickForm() {
* 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)) {
Expand Down Expand Up @@ -578,11 +579,12 @@ public static function buildAmount(&$form, $required = TRUE, $discountId = NULL)
$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;
Expand Down Expand Up @@ -650,10 +652,11 @@ public static function buildAmount(&$form, $required = TRUE, $discountId = NULL)
}
}
}
$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)) {
Expand Down

0 comments on commit 1943162

Please sign in to comment.