Fixe notice, caching, showing inactive fields on membership config
authorEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 29 Nov 2023 08:12:18 +0000 (21:12 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 29 Nov 2023 08:12:18 +0000 (21:12 +1300)
CRM/Financial/BAO/Order.php
CRM/Price/BAO/PriceSet.php
templates/CRM/Contribute/Form/Contribution/MainMembershipBlock.tpl

index fc418700a8b12f320644f205369c22ff994d0790..bd934a62fb00e26417e8361f623042bc6bf03d16 100644 (file)
@@ -672,6 +672,9 @@ class CRM_Financial_BAO_Order {
    */
   protected function setPriceFieldMetadata(array $metadata): void {
     foreach ($metadata as $index => $priceField) {
+      if ($this->isExcludeExpiredFields && !$priceField['is_active']) {
+        unset($metadata[$index]);
+      }
       if ($this->isExcludeExpiredFields && !empty($priceField['active_on']) && time() < strtotime($priceField['active_on'])) {
         unset($metadata[$index]);
       }
@@ -680,7 +683,10 @@ class CRM_Financial_BAO_Order {
       }
       elseif (!empty($priceField['options'])) {
         foreach ($priceField['options'] as $optionID => $option) {
-          if (!empty($option['membership_type_id'])) {
+          if (!$option['is_active']) {
+            unset($metadata[$index]['options'][$optionID]);
+          }
+          elseif (!empty($option['membership_type_id'])) {
             $membershipType = CRM_Member_BAO_MembershipType::getMembershipType((int) $option['membership_type_id']);
             $metadata[$index]['options'][$optionID]['auto_renew'] = (int) $membershipType['auto_renew'];
             if ($membershipType['auto_renew'] && empty($this->priceSetMetadata['auto_renew_membership_field'])) {
index 9176c152a0c63ff2290814044bc97c5145e35f06..9d8d6dd24fc1d33cc9905d4cfecb8f24d3290d8b 100644 (file)
@@ -1660,4 +1660,18 @@ WHERE     ct.id = cp.financial_type_id AND
     return $result;
   }
 
+  public static function hook_civicrm_post($op, $objectName, $objectId, &$objectRef): void {
+    if (in_array($objectName, ['PriceField', 'PriceFieldValue', 'PriceSet'], TRUE)) {
+      self::flushPriceSets();
+    }
+  }
+
+  public static function flushPriceSets(): void {
+    $cache = CRM_Utils_Cache::singleton();
+    foreach (PriceSet::get(FALSE)->addSelect('id')->execute() as $priceSet) {
+      $cacheKey = 'CRM_Price_BAO_PriceSetgetCachedPriceSetDetail_' . $priceSet['id'];
+      $cache->delete($cacheKey);
+    }
+  }
+
 }
index d676d6a3a9fd2cff06e2da92deb03dbdd9095974..65bf96acbab9e1e795915015c62f53139e2a952b 100644 (file)
       if ( !memTypeId ) memTypeId = cj('input:radio[name='+priceSetName+']:checked').attr('membership-type');
 
       //does this page has only one membership type.
-      var singleMembership = {/literal}'{$singleMembership}'{literal};
-      if ( !memTypeId && singleMembership ) memTypeId = cj("input:radio[name="+priceSetName+"]").attr('membership-type');
       var renewOptions  = {/literal}{$autoRenewMembershipTypeOptions}{literal};
       var currentOption = eval( "renewOptions." + 'autoRenewMembershipType_' + memTypeId );
       var autoRenew = cj('#auto_renew_section');