discount field doesn't appear for memberships
I've run into this a couple times, so curious if others have as well. We have discount codes configured for a few membership types. We have a contribution page which exposes those membership types via a price set. But the discount field is not getting displayed on the form.
I traced the issue to the cividiscount.php file, around line 177. https://lab.civicrm.org/extensions/cividiscount/-/blob/master/cividiscount.php#L177
In that chunk of code we retrieve the membership types configured on that page and compare with a list of membership types configured in discount codes. If the arrays intersect, we flag the discount field for display. The list of membership types for the forms are retrieved in two ways. We first check $form->_membershipBlock['membership_types']
(if it's not empty) and then check $form->_membershipTypeValues
.
That's where the issue is. What I'm finding is that Civi is storing the list of membership types as a serialized string in the membershipBlock -- and possibly may be truncated. Regardless of whether it's truncated, because it's not an array the intersection check always fails. $form->_membershipTypeValues
is present and structured correctly, so I swapped the logic and the field is displayed.
I'm unsure if this is a bug higher up in Civi, relating to what is stored in the membershipBlock element, or if the problem is with Cividiscount -- where it's expecting an array and shouldn't be.
Anyone else run into this?