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

simplify calculation of lifetime memberships in CRM_Price_BAO_PriceSet #25456

Merged

Conversation

MegaphoneJon
Copy link
Contributor

Overview

Civi has long had many different functions for calculating lifetime memberships. Many are buggy.

I was hunting for one such bug when I found this. I don't think this gives incorrect results, but it is a) inefficient, b) gives uninitialized variable warnings.

Before

Uninitialized variables, unused static vars, making a separate query for every price option on the page.

After

Initialized variables, one query per price field on the page (my price fields have 15 options each). Shouldn't look for lifetime memberships if one is found in an earlier price field.

Comments

checkCurrentMembership() is called only from one place, exclusively to set the $ispricelifetime variable, which is used exclusively to display a message in the template if the user has a lifetime membership (that matches the membership types on the page).

static $_contact_memberships isn't used anywhere, I checked.

@civibot
Copy link

civibot bot commented Jan 29, 2023

(Standard links)

@civibot civibot bot added the master label Jan 29, 2023
$form->assign('ispricelifetime', TRUE);
$contactId = $form->getVar('_membershipContactID');
if ($contactId && $options) {
$checklifetime ?: self::checkCurrentMembership($options, $contactId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does that work - I thought it would need to be

 $checklifetime = $checklifetime ?: self::checkCurrentMembership($options, $contactId);

if it does work - does it work on all php versions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you're right - at the end of the night I was looking at small ways to improve my code, meaning a) it was after I'd done testing, b) it was late. This was a mistake.

@MegaphoneJon MegaphoneJon force-pushed the lifetime-membership-fix-1 branch from 8a1696c to bd9e389 Compare January 31, 2023 15:14
@eileenmcnaughton
Copy link
Contributor

OK - this looks good - I'm not going to insist on a unit test as it is a vaildation function so a little lower priority

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants