Repository navigation
Sort merch sizes smallest to largest, whatever the label - #121
Merged
Merged
Conversation
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>
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.
Why
In prod the Hydraulic Jeff shirt lists 5X first, then S, M, L… Two places treated an unrecognized size label as "sorts first":
useProductPurchaseranked sizes withSIZE_ORDER.indexOf(size), andSIZE_ORDERstopped atXXXL— so5Xreturned-1, which is below XS's0.POST /admin/products/:id/variantsdefaulted a new variant'ssort_orderto0— 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 gridStoreItemand the 3D booth'sProductDetail, so both views get it.backend/utils/sizeRank.js(new) +backend/routes/admin.js— adding or editing a size derivessort_orderfrom it; an explicitsort_orderstill wins.backend/scripts/prod-resort-variants-by-size.sql(new) — recompute existing rows.Verified
The two
sizeRankimplementations agree on 25 label forms (base, word, repeated-X, numeric, whitespace/punctuation, null). Ordering comes outXS S M L XL XXL 3X 4X 5X. ESLint clean on the touched files.Not verified: the
.sqlscript was never executed — Docker is down locally and I had no DB access. It's transactional and prints a preview beforeCOMMIT; 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'sCMDis justnode server.js; the migrate line is commented out). Existing rows keep their oldsort_orderuntil you run the migration or the SQL script by hand. That only affects row order in the Manage Store table and the raw/api/productspayload — the storefront sorts client-side and is correct either way.Follow-up worth considering
The free-text size field is what let
5Xin alongside theXXXLconvention, and it also allows2XandXXL— 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