Incorrect line item created for back-end membership sign-up using price set and CiviDiscount
When doing a back-end membership sign-up using a price set, with an additional item e.g. donation and with a CiviDiscount code applying to the membership, the line item created for the membership does not reflect the discount but the contribution total does. The problem does not occur without the additional item.
Steps to replicate
- Create a CiviDiscount code for e.g. 25% off General membership.
- Create a membership price set with 2 fields: Membership with options General & Student; Donation text field.
- Create a contribution page using the price set (we don't use this here but in my testing, the discount did not work on back-end sign-ups until I did this step.)
- Go to a contact's summary -> Memberships tab and click Add Membership.
- Enter the discount code & Apply.
- Choose price set -> select the above price set.
- You may need to click Apply again to get the discount to show for General membership.
- Select "General (Includes applied discount: 25% Test for General membership) - $ 75.00".
- Enter a donation amount, e.g. $5.
- Leave "Record Membership Payment?" ticked, leave other fields as default.
- Click Save.
Expected result
Contribution created with total amount $80 and 2 line items:
- entity_table: civicrm_membership, line total $75.00
- entity_table: civicrm_contribution, line total $5.00
Actual result
Contribution created with total amount $80 and 2 line items:
- entity_table: civicrm_membership, line total $100.00
- entity_table: civicrm_contribution, line total $5.00
Note that the membership line item has the wrong amount and the sum of the line items is not equal to the contribution amount.
Replicated on 5.10.3 and current local civibuild dmaster.