Skip to content

Commit

Permalink
CiviDiscount fix - pass correct component
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed May 8, 2023
1 parent aca3b50 commit c3f9fce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/Contribution/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public function buildQuickForm() {
// build price set form.
$this->set('priceSetId', $this->_priceSetId);
if (empty($this->_ccid)) {
CRM_Price_BAO_PriceSet::buildPriceSet($this);
CRM_Price_BAO_PriceSet::buildPriceSet($this, $this->getMainEntityType());
}
if ($this->_values['is_monetary'] &&
$this->_values['is_recur'] && empty($this->_values['pledge_id'])
Expand Down
12 changes: 9 additions & 3 deletions CRM/Contribute/Form/ContributionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1305,9 +1305,8 @@ protected function getMembershipBlock() {
*/
protected function isMembershipPriceSet(): bool {
if ($this->_useForMember === NULL) {
if (CRM_Core_Component::isEnabled('CiviMember') &&
(!$this->isQuickConfig() || !empty($this->_ccid)) &&
(int) CRM_Core_Component::getComponentID('CiviMember') === (int) $this->order->getPriceSetMetadata()['extends']) {
if ($this->getMainEntityType() === 'membership' &&
!$this->isQuickConfig()) {
$this->_useForMember = 1;
}
else {
Expand All @@ -1318,6 +1317,13 @@ protected function isMembershipPriceSet(): bool {
return (bool) $this->_useForMember;
}

public function getMainEntityType() {
if (CRM_Core_Component::isEnabled('CiviMember') && (int) CRM_Core_Component::getComponentID('CiviMember') === (int) $this->order->getPriceSetMetadata()['extends']) {
return 'membership';
}
return 'contribution';
}

/**
* Should the membership block be displayed.
*
Expand Down
9 changes: 3 additions & 6 deletions CRM/Price/BAO/PriceSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,11 @@ public static function getCachedPriceSetDetail($priceSetID) {
* Build the price set form.
*
* @param CRM_Core_Form $form
* @param string|null $component
*
* @return void
*/
public static function buildPriceSet(&$form) {
public static function buildPriceSet(&$form, $component = NULL) {
$priceSetId = $form->get('priceSetId');
if (!$priceSetId) {
return;
Expand Down Expand Up @@ -847,23 +848,19 @@ public static function buildPriceSet(&$form) {
$form->_priceSet['id'] = $form->_priceSet['id'] ?? $priceSetId;
$form->assign('priceSet', $form->_priceSet);

$component = 'contribution';
if ($className == 'CRM_Member_Form_Membership') {
$component = 'membership';
}

if ($className == 'CRM_Contribute_Form_Contribution_Main') {
$feeBlock = &$form->_values['fee'];
if (!empty($form->_useForMember)) {
$component = 'membership';
}
}
else {
$feeBlock = &$form->_priceSet['fields'];
}

// Call the buildAmount hook.
CRM_Utils_Hook::buildAmount($component, $form, $feeBlock);
CRM_Utils_Hook::buildAmount($component ?? 'contribution', $form, $feeBlock);

self::addPriceFieldsToForm($form, $feeBlock, $validFieldsOnly, $className, $validPriceFieldIds);
}
Expand Down

0 comments on commit c3f9fce

Please sign in to comment.