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

Fix for membership discounts not showing in 5.62 #26538

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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/Contribute/Form/Contribution/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public function buildQuickForm() {
// build price set form.
$this->set('priceSetId', $this->_priceSetId);
if (empty($this->_ccid)) {
CRM_Price_BAO_PriceSet::buildPriceSet($this, $this->getMainEntityType());
CRM_Price_BAO_PriceSet::buildPriceSet($this, $this->getFormContext());
}
if ($this->_values['is_monetary'] &&
$this->_values['is_recur'] && empty($this->_values['pledge_id'])
Expand Down
16 changes: 10 additions & 6 deletions CRM/Contribute/Form/ContributionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ protected function getMembershipBlock() {
*/
protected function isMembershipPriceSet(): bool {
if ($this->_useForMember === NULL) {
if ($this->getMainEntityType() === 'membership' &&
if ($this->getFormContext() === 'membership' &&
!$this->isQuickConfig()) {
$this->_useForMember = 1;
}
Expand All @@ -1317,11 +1317,15 @@ 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';
/**
* Get the form context.
*
* This is important for passing to the buildAmount hook as CiviDiscount checks it.
*
* @return string
*/
public function getFormContext(): string {
return $this->order->isMembershipPriceSet() ? 'membership' : 'contribution';
}

/**
Expand Down
10 changes: 10 additions & 0 deletions CRM/Financial/BAO/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,13 +651,23 @@ protected function setPriceFieldMetadata($metadata) {
public function getPriceSetMetadata(): array {
if (empty($this->priceSetMetadata)) {
$priceSetMetadata = CRM_Price_BAO_PriceSet::getCachedPriceSetDetail($this->getPriceSetID());
// @todo - make sure this is an array - commented out for now as this PR is against the rc.
// $priceSetMetadata['extends'] = explode(CRM_Core_DAO::VALUE_SEPARATOR, $priceSetMetadata['extends']);
$this->setPriceFieldMetadata($priceSetMetadata['fields']);
unset($priceSetMetadata['fields']);
$this->priceSetMetadata = $priceSetMetadata;
}
return $this->priceSetMetadata;
}

public function isMembershipPriceSet() {
if (!CRM_Core_Component::isEnabled('CiviMember')) {
return FALSE;
}
$extends = explode(CRM_Core_DAO::VALUE_SEPARATOR, $this->getPriceSetMetadata()['extends']);
return in_array(CRM_Core_Component::getComponentID('CiviMember'), $extends, FALSE);
}

/**
* Get the financial type id for the order.
*
Expand Down