Error when using automatic membership discount if the contact selects any other option in the price set that is not the selection of a membership type (php 8.1.x)
We are no longer able to use an automatic membership discount if the price set also contains additional fields, and the contact selects any option of an additional field (it works as long as they make no other selection.)
This has been replicated on Drupal 7, 9, 10, & WordPress, on CiviCRM 5.66.2 and above, including on https://dmaster.demo.civicrm.org & https://wpmaster.demo.civicrm.org. Issue occurs when running php 8.1.25, but not when running php 7.4.x.
To replicate:
- Enable civi member and have membership options configured
- Create a membership price set, 1 field for the membership option selection, and 1 additional field. For example, this could be a checkbox field for 'provincial association dues', and set a couple of options that are of a financial type that is not membership dues
- Create a contribution page with the membership section enabled and your price set selected
- Create a discount:
- give it a name
- select fixed amount of your choosing
- under 'discounts for memberships' choose a membership type that was included in your price field
- under 'automatic discounts' choose contact type 'individual'
- Visit your form, attempt to submit your contribution after selecting a membership type AND at least one option from your additional field (again, the error only occurs if you make an additional selection)
Your contribution will be recorded as pending, and you will be gifted with a system error. An error is not recorded to the CiviCRM logs. In the Drupal logs we find:
TypeError: Illegal offset type in _cividiscount_extract_memberships_from_line_items() (line 753 of civicrm_custom/extensions/org.civicrm.module.cividiscount/cividiscount.php).