CiviDiscount fix - pass correct component
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 8 May 2023 08:03:50 +0000 (20:03 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 8 May 2023 08:05:21 +0000 (20:05 +1200)
CRM/Contribute/Form/Contribution/Main.php
CRM/Contribute/Form/ContributionBase.php
CRM/Price/BAO/PriceSet.php

index 706287757850059a826710cb24205cd936cf1672..eb2979e4dd6927eac1f40babcdc05f5da6fb35c8 100644 (file)
@@ -372,7 +372,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);
+        CRM_Price_BAO_PriceSet::buildPriceSet($this, $this->getMainEntityType());
       }
       if ($this->_values['is_monetary'] &&
         $this->_values['is_recur'] && empty($this->_values['pledge_id'])
index 1b79b33b3d92cd3fab16044c5b5e1f7156b898f0..1d41e1ae54cf9a67d98dc5ad075351558a109da7 100644 (file)
@@ -1305,9 +1305,8 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
    */
   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 {
@@ -1318,6 +1317,13 @@ 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';
+  }
+
   /**
    * Should the membership block be displayed.
    *
index e263fdf3dedb466c678e1579d2dc087991ca235e..d3dedcbbe14ae45d0c217d4fe647852472cfd272 100644 (file)
@@ -791,10 +791,11 @@ WHERE  id = %1";
    * 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;
@@ -847,23 +848,19 @@ WHERE  id = %1";
     $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);
   }