Repository navigation
Remove reward lines the cart no longer earns (spec remove-unearned-reward-lines) - #2938
Merged
Merged
Conversation
…arned-reward-lines, 1/4) A line a discount added now holds exactly the reward units that discount allocates to it in the current calculation. BuyXGetY allocates its shortfall onto its own lines (keep, then raise, then add) without writing them; the new ReconcilesRewardLines action creates, resizes or deletes the lines from the breakdown, and CalculateCart runs the calculation steps once more when it changed any, so shipping and tax see them. Lines a discount added no longer count toward any discount's conditions, minimum spend or targeted lines, so a reward can't keep itself earned. ApplyDiscounts resets freeItems on each run. Marks the spec accepted and slice 1 done. Amp-Thread-ID: https://ampcode.com/threads/T-8ecb4cbd-8657-4f41-8f71-6de8c214834c Co-authored-by: Amp <amp@ampcode.com>
…arned-reward-lines, 2/4) Deleting a discount deletes the lines it added on carts without a completed order. The foreign key is null on delete, so they would otherwise stay as ordinary lines at full price. DiscountObserver runs it on every delete path, one model at a time so each cart's persisted totals go stale. Carts with a completed order keep their lines as history. Amp-Thread-ID: https://ampcode.com/threads/T-8ecb4cbd-8657-4f41-8f71-6de8c214834c Co-authored-by: Amp <amp@ampcode.com>
…arned-reward-lines, 3/4) CartLineAddedByDiscount joins the UpdateCartLineValidation steps. It fails when the requested quantity differs on a line a discount added, since the calculation sizes that line to the reward units its discount allocates and would undo the change. A meta-only update at the same quantity passes. The message is translated into all 16 locales. Amp-Thread-ID: https://ampcode.com/threads/T-8ecb4cbd-8657-4f41-8f71-6de8c214834c Co-authored-by: Amp <amp@ampcode.com>
…eward-lines, 4/4) Describes how added reward lines are kept, raised, lowered and removed, the refused quantity change, removal when a discount is deleted, how a custom discount type has core manage a line it adds, and the second pass of the calculation steps. Adds the behaviour note to the alpha upgrade guide. Amp-Thread-ID: https://ampcode.com/threads/T-8ecb4cbd-8657-4f41-8f71-6de8c214834c Co-authored-by: Amp <amp@ampcode.com>
The cross-db test for a deleted discount's line still expected every line to stay as an ordinary line. Slice 2 deletes the line on a cart still being shopped, so the test now places the cart first and checks that its line keeps the history with the key nulled. It is skipped on SQLite, which does not enforce the foreign key, so the local run missed it. Amp-Thread-ID: https://ampcode.com/threads/T-8ecb4cbd-8657-4f41-8f71-6de8c214834c Co-authored-by: Amp <amp@ampcode.com>
glennjacobs
added a commit
that referenced
this pull request
Nov 27, 2026
…ed (#2939) Tracker housekeeping. No code changes. - Flips four specs to `implemented`, ticks their slices, and moves them to `specs/completed/`. Each was checked against `2.x`: - `attribute-descriptions`: #2881. - `core-values-out-of-meta`: the `product_option_values.colour` column and `added_by_discount_id` on cart and order lines are in the baselines. - `discount-coupons`: #2855 (usage counted at placement) and #2857 (coupons, upgrade, generation, panel, docs including the single-use coupon campaign guide). - `guest-discount-usage-limits`: #2856 (`ResolvesCustomerEmail`, `CountsCustomerRedemptions`, `CouponValidator` taking the cart, `ValidateCustomerForDiscounts`, docs). - Moves their `TODO.md` entries from Outstanding to Done, along with 0083, whose spec was already marked implemented and moved to `completed/` in #2926. - No paths outside `specs/` referenced the moved files. `remove-unearned-reward-lines` stays in Outstanding until #2938 merges. Co-authored-by: Amp <amp@ampcode.com>
glennjacobs
added a commit
that referenced
this pull request
Nov 27, 2026
…t to completed (#2940) Tracker housekeeping. No code changes. - Sets `remove-unearned-reward-lines` to `implemented` (all four slices shipped in #2938) and moves it to `specs/completed/`. - Moves its `TODO.md` entry from Outstanding to Done. - No paths outside `specs/` referenced the file. Co-authored-by: Amp <amp@ampcode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Implements spec
remove-unearned-reward-lines(#2937). One commit per slice.A line a discount added now always holds exactly the reward units that discount earns in the current calculation. Before this, an automatically added Buy X Get Y reward stayed in the cart, and was charged at full price, once the cart stopped earning it.
Slice 1: reconciliation
BuyXGetYallocates the units its shopper lines can't take onto its own lines (keep, then raise, then add) and no longer saves or resizes lines.ReconcilesRewardLinesaction, bound inActionServiceProvider. It creates, resizes or deletes every line withadded_by_discount_idto match the discount breakdown, so a discount that no longer applies loses its lines.CalculateCartruns theCartCalculationsteps a second time only when reconciling changed a line, so shipping and tax see the corrected lines.BuyXGetY,AbstractDiscountType::getEligibleLines(),TargetsCartLines). A reward can no longer keep itself earned.ApplyDiscountsresetsfreeItems, so recalculating the same instance no longer repeats entries.Slice 2: deleting a discount
DiscountObserver::deleting()deletes the discount's added lines on carts without a completed order, one model at a time so each cart's persisted totals go stale. Carts with a completed order keep their lines.Slice 3: refusing quantity changes
New
CartLineAddedByDiscountvalidator inUpdateCartLineValidation. It refuses a quantity change on an added line and accepts a meta-only update at the same quantity. Newcarts.line_added_by_discountmessage in all 16 locales. The spec said "promotion"; the message says "discount", matching every locale's existing terminology, and the spec is updated.Slice 4: docs
reference/discounts.mdx,reference/carts.mdx,extending/discounts.mdx(how a custom type has core manage a line it adds),extending/carts.mdx(the second pass),guides/cart.mdx(render added lines without quantity controls) and a behaviour note in the alpha upgrade guide. No schema change.Behaviour changes to review
PercentageOffandFixedAmountOffno longer see added lines.automatically_add_rewardsremoves existing added lines.Existing tests changed
BuyXGetYTest: when the shopper already has the reward product and the cart earns 3, an added line now holds the 2 units their line can't take (before, they were never given).CalculateCartTest: the pipeline runs twice on the calculation that adds the reward line.GetExistingCartLineTestandMapDiscountBreakdownTestbuilt an "added" line from a discount that never applies, which the new rule removes. The first now adds without recalculating; the second uses a real automatic reward.Testing
ReconcileRewardLinesTestand one inDeleteDiscountTest. Each fails on2.xand passes here, on SQLite, MySQL and PostgreSQL (cross-dbgroup).mint validateandmint broken-linkspass.Not changed here, found while testing: running
CreateOrderLinesdirectly on a cart with two different variants underpreventLazyLoadingfails on2.xtoo, because it lazy-loadsvalues. Carts loaded throughCartSession(withlunar.cart.eager_load) aren't affected.