Skip to content

Sort merch sizes smallest to largest, whatever the label - #121

Merged
JacobDChamberlain merged 1 commit into
mainfrom
fix-variant-size-ordering
Sep 23, 2026
Merged

JacobDChamberlain merged 1 commit into
mainfrom
fix-variant-size-ordering

Conversation

@JacobDChamberlain

Copy link
Copy Markdown
Owner

Why

In prod the Hydraulic Jeff shirt lists 5X first, then S, M, L… Two places treated an unrecognized size label as "sorts first":

  • useProductPurchase ranked sizes with SIZE_ORDER.indexOf(size), and SIZE_ORDER stopped at XXXL — so 5X returned -1, which is below XS's 0.
  • POST /admin/products/:id/variants defaulted a new variant's sort_order to 0 — XS's slot — so any size added after the original backfill led the list.

Size is a free-text field in the Manage Store panel, so this applies to any label outside the original seven, not just 5X.

What changed

sizeRank() parses the label instead of matching a fixed list: base sizes, word forms (small, x-large), repeated-X (XXXL), and numeric (2X, 5XL). Anything genuinely unrecognizable ranks last rather than first.

  • frontend/.../useProductPurchase.js — the visible fix. Shared by the grid StoreItem and the 3D booth's ProductDetail, so both views get it.
  • backend/utils/sizeRank.js (new) + backend/routes/admin.js — adding or editing a size derives sort_order from it; an explicit sort_order still wins.
  • migration + backend/scripts/prod-resort-variants-by-size.sql (new) — recompute existing rows.

Verified

The two sizeRank implementations agree on 25 label forms (base, word, repeated-X, numeric, whitespace/punctuation, null). Ordering comes out XS S M L XL XXL 3X 4X 5X. ESLint clean on the touched files.

Not verified: the .sql script was never executed — Docker is down locally and I had no DB access. It's transactional and prints a preview before COMMIT; check that preview before committing it.

Deploying

The frontend fix needs no DB change — merging and deploying is enough to see the dropdown fixed live.

The migration does not run on deploy (backend/Dockerfile's CMD is just node server.js; the migrate line is commented out). Existing rows keep their old sort_order until you run the migration or the SQL script by hand. That only affects row order in the Manage Store table and the raw /api/products payload — the storefront sorts client-side and is correct either way.

Follow-up worth considering

The free-text size field is what let 5X in alongside the XXXL convention, and it also allows 2X and XXL — the same size — on one product, which would render as two dropdown rows with separate stock. A dropdown there would remove the whole class of problem.

🤖 Generated with Claude Code

The Hydraulic Jeff shirt listed 5X ahead of Small. Two places treated an
unrecognized size label as "sorts first":

  * useProductPurchase ranked sizes with SIZE_ORDER.indexOf(size), and
    SIZE_ORDER stopped at XXXL — so "5X" ranked -1, below XS's 0.
  * The admin routes defaulted a new variant's sort_order to 0, which is
    XS's slot, so a size added after the backfill led the list.

Size is a free-text field in the admin panel, so replace the fixed list
with a sizeRank() that parses the label instead of matching it: base
sizes, word forms (small, x-large), repeated-X (XXXL) and numeric (2X,
5XL). Anything genuinely unrecognizable now ranks last rather than first.
The frontend hook is shared by the grid and the 3D booth, so both views
get the fix.

Server-side, adding or editing a size derives sort_order from it; an
explicit sort_order still wins. The migration recomputes existing rows,
with a hand-runnable SQL equivalent alongside the merch-revamp script
since deploys don't run migrations.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@JacobDChamberlain
JacobDChamberlain merged commit 5b2bd4f into main Sep 23, 2026
1 check passed
@JacobDChamberlain
JacobDChamberlain deleted the fix-variant-size-ordering branch September 23, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant