-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
dev/core#860: discount not applied to line item: call buildAmount hook in CRM_Member_Form_Membership::submit(). #15004
dev/core#860: discount not applied to line item: call buildAmount hook in CRM_Member_Form_Membership::submit(). #15004
Conversation
…unt hook in CRM_Member_Form_Membership::submit().
(Standard links)
|
Hopefully that fail on E2E_Cache_ArrayCacheTest::testSetTtl is unrelated? - I see all other builds over the last 11 hours have failed, so I assume it's unrelated. I'm working on a unit test for this issue. |
Jenkins re test this please |
@davejenx wow that's a scary function. Can we |
…n CRM_Member_Form_Membership::submit() & CRM_Price_BAO_PriceSet::buildPriceSet().
Hi @eileenmcnaughton, |
@davejenx, I've applied your PR to 5.16 on our sandbox - applies cleanly but doesn't seem to have any effect for our scenario. |
@agileware-fj I suspected your case described at civicrm/org.civicrm.module.cividiscount#224 was different when you said you can replicate without adding an additional amount. The issue described in dev/core/issues/860 & addressed in this PR only occurs when there are > 1 line items. When I ran the issue 860 case but with a single line item through a debugger, I found: In CRM_Price_BAO_PriceSet::processAmount(), line 703:
sets $amount_override to 75. This is passed to CRM_Price_BAO_LineItem::format() which uses it to adjust the line item amount - though not the label. The backtrace there was: I'd vote for creating a separate core issue for your case, as the steps are different from the specific scenario I described in issue 860 and the fix is evidently different too. |
Reviewing this today |
Sorry, didn't get to finish reviewing on Friday, but after sorting out buildkit woes today I'm happy with the results. Review
|
Thanks @agileware-fj & thanks @davejenx for your work on this - merging per review |
Overview
Fix for dev/core/issues/860 Incorrect line item created for back-end membership sign-up using price set and CiviDiscount.
This is an alternative approach to the one in PR #14994, which caused test failures. See Technical Details below.
Before
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
Expected result
Contribution created with total amount $80 and 2 line items:
Actual result
Contribution created with total amount $80 and 2 line items:
Note that the membership line item has the wrong amount and the sum of the line items is not equal to the contribution amount.
After
Actual result = Expected result
Technical Details
I traced the misbehaviour in a debugger and found that the price set was being instantiated twice, once with the discount, once without, causing the line items to be calculated without the discount. However if there was only one line item, a different route through the code kicked in, overriding the line item amount. I have some detailed notes from debugger sessions if those would be of interest.
I tried a couple of different approaches to fixing:
PR [WIP] dev/core/issues/860: discount not applied to line item: don't overwrite _priceSet if populated. #14994: avoid instantiating the price set twice by checking, in CRM_Member_Form_Membership::submit(), whether $this->_priceSet is already set: if it is, we skip the call to $this->setPriceSetParameters(). This worked in my testing but led to unit test failures.
This PR: insert a call to the buildAmount hook when instantiating the price set for the second time. This also works in my testing. It
(a) requires duplicating some code for setting up the fee block, including checking isACLFinancialTypeStatus() and
(b) retains the second instantiation of the price set.