fix(core): Clear previous line adjustments before testing order item promotions #3320
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
OrderCalculator#applyOrderPromotions
clears out all existingDISTRIBUTED_ORDER_PROMOTION
s before testing promotions.applyOrderItemPromotions
does not currently do the same, the result of which is that when conditions / actions are encountered, previous adjustment data may be present on the line items in question.My specific use case was when creating a promotion of the type "apply a bulk purchase discount, but only to items that aren't already discounted," e.g. when there are 10+ of a product and they aren't already discounted.
Without this change: upon reaching 10 items, the line items become discounted. Upon reaching 11 items, the test for "are there adjustments applied" returns true (the previous adjustment), resulting in the discount being removed. Bump the quantity to 12 and it applies again.
With this change: it works properly when reaching 10, 11, 12, and on.
Breaking changes
No.
Checklist
📌 Always:
👍 Most of the time: