Shop: item priority, block sort order and a Sort by menu #29

Merged
reudy merged 2 commits from session/add-service-priority into main 2026-11-10 12:00:39 +01:00
Member

What

  • Priority per item (items.priority, −1000…1000, empty = 0). Set under Services & products → Priority in the shop. Higher numbers come first; equal ones go by name. That list is now in shop order and shows each item's priority.
  • Shop block order: Recommended (by priority, the default), Most popular, Price: low to high, Price: high to low, Name (A–Z).
  • "Let visitors sort" toggle on the Shop block adds a Sort by menu above the items. It starts at the block's chosen order and is hidden when there's only one item.
  • Most popular = units sold in paid orders over the last 90 days, from a new public GET /api/shop/popular. It returns item ids only, never the numbers. Refunded orders don't count. Products handed over inside a bundle don't count either (the bundle itself does). Bookings paid with a code count for their service. Items with no recent sales come after, in Recommended order. Until anything has sold, the menu leaves Most popular out.

Behaviour change

Chosen items (itemIds) used to be shown in the order they were clicked, which you couldn't see in the editor. They now follow the block's order. Existing items all start at priority 0, so existing shops stay alphabetical until priorities are set.

Tested

  • npm run check in both apps: 0 errors (warnings unchanged, all in files this PR doesn't touch).
  • PocketBase 0.40.6 in a throwaway container. Imported the old schema, then restarted with the new migration: the field was added with its limits. Re-importing pb_schema.json was a no-op. With test orders, /api/shop/popular ranked correctly: the refunded order and the price-0 bundle part were excluded and the unsold item was left out. Sorting by -priority,name gave the expected order.
  • Full stack in a browser (Playwright, 1280 px and 390 px), with seeded items and orders. The public menu reorders correctly for all five choices, with no sideways scroll on a phone. Creating a service with a priority, then editing it to 20, moves it to the top of the admin list and the shop.

Also fixed (separate commit)

Editing any saved service was blocked on main. PocketBase returns an empty number as 0, so the form opened with "Places in a group session: 0". That's below the field's minimum of 1, so the browser refused to submit. mapItemRecord now maps 0 to null for capacity and bufferMinutes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HA82gWt7pNdAsocjxujY3m

## What - **Priority per item** (`items.priority`, −1000…1000, empty = 0). Set under *Services & products* → *Priority in the shop*. Higher numbers come first; equal ones go by name. That list is now in shop order and shows each item's priority. - **Shop block order**: *Recommended* (by priority, the default), *Most popular*, *Price: low to high*, *Price: high to low*, *Name (A–Z)*. - **"Let visitors sort" toggle** on the Shop block adds a *Sort by* menu above the items. It starts at the block's chosen order and is hidden when there's only one item. - **Most popular** = units sold in paid orders over the last 90 days, from a new public `GET /api/shop/popular`. It returns item ids only, never the numbers. Refunded orders don't count. Products handed over inside a bundle don't count either (the bundle itself does). Bookings paid with a code count for their service. Items with no recent sales come after, in Recommended order. Until anything has sold, the menu leaves *Most popular* out. ## Behaviour change Chosen items (`itemIds`) used to be shown in the order they were clicked, which you couldn't see in the editor. They now follow the block's order. Existing items all start at priority 0, so existing shops stay alphabetical until priorities are set. ## Tested - `npm run check` in both apps: 0 errors (warnings unchanged, all in files this PR doesn't touch). - PocketBase 0.40.6 in a throwaway container. Imported the old schema, then restarted with the new migration: the field was added with its limits. Re-importing `pb_schema.json` was a no-op. With test orders, `/api/shop/popular` ranked correctly: the refunded order and the price-0 bundle part were excluded and the unsold item was left out. Sorting by `-priority,name` gave the expected order. - Full stack in a browser (Playwright, 1280 px and 390 px), with seeded items and orders. The public menu reorders correctly for all five choices, with no sideways scroll on a phone. Creating a service with a priority, then editing it to 20, moves it to the top of the admin list and the shop. ## Also fixed (separate commit) Editing **any** saved service was blocked on `main`. PocketBase returns an empty number as 0, so the form opened with "Places in a group session: 0". That's below the field's minimum of 1, so the browser refused to submit. `mapItemRecord` now maps 0 to `null` for `capacity` and `bufferMinutes`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01HA82gWt7pNdAsocjxujY3m
agent added 1 commit 2026-11-04 23:37:02 +01:00
- items.priority (migration + pb_schema.json): Recommended order in Shop
  blocks, higher first, then by name. Set under Services & products, which
  now lists items in that order.
- Shop block: choose its order (Recommended, Most popular, price up/down,
  name) and optionally let visitors re-sort with a "Sort by" menu.
  sortItems() in shared/items.ts is the one place items are ordered.
- Most popular: GET /api/shop/popular returns item ids by units sold in
  paid orders over the last 90 days (ids only, no sales figures).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HA82gWt7pNdAsocjxujY3m
agent added 1 commit 2026-11-04 23:47:03 +01:00
PocketBase reads an empty number back as 0, so mapItemRecord gave every
service capacity 0 and bufferMinutes 0. The edit form then showed
'Places in a group session: 0', below the field's min of 1, and the
browser refused to submit. 0 now maps to null (not set) for both;
every reader already treats them alike.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HA82gWt7pNdAsocjxujY3m
reudy merged commit 27d95e6f8e into main 2026-11-10 12:00:39 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: reudy-net/domaino#29
No description provided.