Natural add-to-cart flow (return-to-origin + cart summary + flashes) - #3
Merged
Conversation
…ashes
Add-to-cart now redirects BACK to the page you were on (a server-composed,
allow-listed origin from the form's `return`=shop|product + filter fields —
never an echoed path/URL, per ADR 0026), with an `?added=` flash, so browsing
stays natural instead of bouncing to /cart every time.
- StorefrontCart: return-to-origin in mutating(); `?notice=` on failures
(unavailable/expired) and checkout failures (empty/stock/expired); a
read-only summary() (count = Σ line qty, total) that never mints a cart.
- StorefrontResolver: resolves `added` via CatalogReadPort->get (canonical
{sku,name}, active-only — never reflects the raw query), a validated `notice`
enum, and a `cart_summary` closure for the header pill (section pages only).
- Default templates: hidden return fields, flash bar, is-added state.
Security (reviewed green): open-redirect closed by fixed path prefixes +
http_build_query; count is section-page-only so it can't be baked into a
path-cached page; added/notice never reflect raw input. Regression tests added.
PHPStan max + phpunit (23) + cs-fixer green.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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.
Makes the shopping flow natural: add-to-cart returns you to the page you were on (server-composed, allow-listed origin — never an echoed path, per ADR 0026), with an
?added=flash. Adds a read-only cart summary for the header count pill, and?notice=messages on failures.What changed
StorefrontCart: return-to-origin (return=shop|product + filter fields), failure notices (unavailable/expired/empty/stock),summary()(count = Σ qty; never mints a cart).StorefrontResolver:addedresolved viaCatalogReadPort->get(canonical{sku,name}, active-only, never reflects raw input), validatednoticeenum,cart_summaryclosure (section pages only).Security (reviewed green before build)
/shop//shop/{rawurlencode(sku)}//cart+http_build_query(URL-encodes everything). Regression tests included.added/noticenever reflect raw request input (lookup + enum), and are escaped on render.Checks
PHPStan (max) + phpunit (23 tests) + cs-fixer all green.
🤖 Generated with Claude Code