From: Eileen McNaughton Date: Wed, 29 Nov 2023 08:12:18 +0000 (+1300) Subject: Fixe notice, caching, showing inactive fields on membership config X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b0bc7ffa082e4549ce0b09d739a6d862fffc2e3b;p=civicrm-core.git Fixe notice, caching, showing inactive fields on membership config --- diff --git a/CRM/Financial/BAO/Order.php b/CRM/Financial/BAO/Order.php index fc418700a8..bd934a62fb 100644 --- a/CRM/Financial/BAO/Order.php +++ b/CRM/Financial/BAO/Order.php @@ -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'])) { diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index 9176c152a0..9d8d6dd24f 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -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); + } + } + } diff --git a/templates/CRM/Contribute/Form/Contribution/MainMembershipBlock.tpl b/templates/CRM/Contribute/Form/Contribution/MainMembershipBlock.tpl index d676d6a3a9..65bf96acba 100644 --- a/templates/CRM/Contribute/Form/Contribution/MainMembershipBlock.tpl +++ b/templates/CRM/Contribute/Form/Contribution/MainMembershipBlock.tpl @@ -153,8 +153,6 @@ 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');