Repository navigation
Discount coupons: many codes per discount - #2857
Merged
Merged
Conversation
glennjacobs
force-pushed
the
feat/discount-coupons
branch
2 times, most recently
from
November 26, 2026 20:23
f56bd6a to
9fbd65f
Compare
Coupons become rows on a new coupons table. A discount's redemption column says whether it applies automatically or needs a coupon, and a cart's code resolves through Cart::coupon(). Placement records the coupon on the redemption, counts its use atomically and reports a code over its own limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A new data step turns each v1 discounts.coupon into a coupons row carrying the discount's uses and max_uses, sets redemption, and drops the column. It runs before the discount_user copy, whose mirrored discount_redemptions now references coupons. The ledger baseline lists the coupons migration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CreatesCoupon adds one code to a discount and DeletesCoupon removes one, keeping its redemptions without the coupon. The panel and Filament call them rather than writing the rows themselves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The discount edit page replaces the coupon field with "Applied automatically" / "Needs a coupon", and a coupon discount gets a Coupons section: a searchable, paginated table of codes, adding one code with an optional limit, and deleting a code. The index filters on redemption and shows the code or the count. The order timeline labels discount-limit-exceeded by the limit that was passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The discount form picks a redemption method instead of a coupon code, the table shows the code or the count, and coupon discounts get a relation manager to list, search, add and delete codes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Documents the Coupon model, Discount::$redemption, Cart::coupon(), the coupon on redemptions and order breakdowns, the coupon limit in DiscountLimitExceeded, and the upgrade step and manual notes for Discount::$coupon. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implements slice 4 of spec `discount-coupons` (#2848), the generation and export parts of slice 5, and slice 6. Last of four; based on the coupons PR. - `CouponBatch` describes a run: `ofQuantity()` or `forEmails()` (distinct, normalised addresses), with length, prefix and uses per code. - `CouponCodeGenerator` contract; the default leaves out `0 O 1 I L`. - `GenerateCoupons` inserts in chunks of 1,000 with `insertOrIgnore` and tops up until the batch is complete, so collisions are replaced. The batch ULID is fixed when the `CouponBatch` is made, so a retried job finishes the same batch instead of duplicating it. `Discount::generateCoupons()` is the verb; `GenerateCouponsJob` queues it. - Panel: Generate codes (quantity, or emails pasted or uploaded as CSV) and Export to CSV for all codes or one batch. Runs above `lunar.discounts.coupons.queue_threshold` are queued and shown as generating until done. - Docs: generation reference and a new guide for a single-use code campaign with guest checkout. Set to 5,000 from a timing run into a table already holding 200k codes, `sync` queue: | Database | 1k | 5k | 10k | 50k | |:--|:--|:--|:--|:--| | SQLite | 19ms | 63ms | 137ms | 0.90s | | MySQL 8 | 28ms | 105ms | 215ms | 1.10s | | Postgres 18 | 36ms | 142ms | 280ms | 1.46s | The insert dominates; code generation is about 5% of the time. Email batches cost about 1.4x. Rerun with `vendor/bin/pest tests/core/Benchmarks` (`DB_DRIVER=mysql|pgsql`). - A queued email batch carries its address list in the job payload, about 1.25MB for 50k addresses. Fine on Redis and database queues, too large for SQS. - The generating state is a cache entry per discount with no lock, so two staff queueing on the same discount at the same instant can lose one progress marker. The codes still generate. All suites pass apart from failures that also fail on `2.x` (panel `StaffSessionInvalidationTest`, filament `ThumbnailImage` (4), search Typesense). phpstan, pint, panel vitest/type-check/build and mint pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Amp <amp@ampcode.com>
MapDiscountBreakdownTest creates its coupon through the coupons relation, the discount edit page test passes the redemption and coupon props, and the redemption draft tests send their data with the commit, which 2.x's draft layer now expects. Amp-Thread-ID: https://ampcode.com/threads/T-01a217b3-1893-73f9-b128-3754ed5c50e2 Co-authored-by: Amp <amp@ampcode.com>
glennjacobs
force-pushed
the
feat/discount-coupons
branch
from
November 26, 2026 20:23
9fbd65f to
cbfbedd
Compare
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>
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 slices 2 and 3 of spec
discount-coupons(#2848), plus code management in both admins: a discount can have many coupon codes. Third of four; based on the guest limits PR.Summary
couponstable andCouponmodel;discounts.coupondropped;discounts.redemptionadded (Enums\DiscountRedemptionMethod:Automatic,Coupon). The spec names the enumDiscountRedemption, which clashes with the redemption model.Cart::coupon()resolves the code, andDiscountManager,AbstractDiscountTypeandCouponValidatorall match through it. The order's discount breakdown carriescoupon_idandcoupon_code. Placement incrementscoupons.usesatomically and reports a coupon over-limit.CreatesCouponandDeletesCouponactions.redemption. Safe to re-run.discounts.coupon: a redemption select and aCouponRelationManager.Notes for review
couponsis000073anddiscount_redemptionsmoves to000074, so itscoupon_idforeign key has a table to point at.Checks
core, upgrade, admin, shipping and stripe suites pass; phpstan, pint, panel vitest/type-check/build and mint pass. Failures that also fail on
2.x: panelStaffSessionInvalidationTest, filamentThumbnailImage(4), search Typesense "resolves the collections index".🤖 Generated with Claude Code