From 28251846e70115531c01468e4214e0e32f6dbb20 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 16 Jun 2023 13:05:36 +1200 Subject: [PATCH] Fix for membership discounts not showing in 5.62 --- CRM/Contribute/Form/Contribution/Main.php | 2 +- CRM/Contribute/Form/ContributionBase.php | 16 ++++++++++------ CRM/Financial/BAO/Order.php | 10 ++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 02d7f88378..c34b3f4bf1 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -369,7 +369,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu // 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']) diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 0a02db1e1c..e97fd44536 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -1305,7 +1305,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { */ protected function isMembershipPriceSet(): bool { if ($this->_useForMember === NULL) { - if ($this->getMainEntityType() === 'membership' && + if ($this->getFormContext() === 'membership' && !$this->isQuickConfig()) { $this->_useForMember = 1; } @@ -1317,11 +1317,15 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { 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'; } /** diff --git a/CRM/Financial/BAO/Order.php b/CRM/Financial/BAO/Order.php index 6f4cbe9a8e..d4a0e299dc 100644 --- a/CRM/Financial/BAO/Order.php +++ b/CRM/Financial/BAO/Order.php @@ -651,6 +651,8 @@ class CRM_Financial_BAO_Order { 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; @@ -658,6 +660,14 @@ class CRM_Financial_BAO_Order { 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. * -- 2.25.1