discount tracking inaccurate when multiple memberships present
To recreate:
- create a price set with two fields, each representing different membership options. for example the first may be for national dues and the second for chapter dues
- configure a contribution page that uses this price set
- create a discount code that applies to only one of the membership categories (e.g. the national dues)
- complete the form using the discount code
Result -- the discount code tracking may incorrectly be applied to the wrong membership. The details in the line item are consistently correct, as far as I can tell. The problem is limited to the discount tracking table.
Technical details --
There are two issues in the code. The first is that the function that stores the tracking code (_cividiscount_consume_discount_code_for_online_contribution()
) retrieves the membership type from the params with the membershipID
key, but that key only returns one of the selected memberships. There is another key that provides an array of all membership IDs -- createdMembershipIDs
. The second issue is that although we do a comparison (array_intersect) between the membership types on the form and the ones that are discounted, we only check to see if there are values in that intersection. We don't actually compare the membership type to see if it's in that list.