Shop: show the bundle's separate price as a saving; hide unsellable bundles

Bundle cards show what the parts cost one by one, crossed out when it's
more than the bundle price. Bundles with a part that isn't on sale are
left out of the shop data, so their parts always have names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
This commit is contained in:
agent 2026-10-26 09:04:35 +00:00
parent 338aef9e01
commit 23c5b70a93
5 changed files with 32 additions and 5 deletions

View file

@ -2,7 +2,7 @@
// the Shop block and the checkout. Which duration costs what is decided
// (and charged) by the shop hooks in PocketBase; this only reads and shows it.
import type { ItemDuration } from './types';
import type { BundlePart, ItemDuration, ItemRecord } from './types';
/** A service's `durations` field (JSON, possibly hand-edited) → valid entries, shortest first, one per length. */
export function parseDurations(raw: unknown): ItemDuration[] {
@ -32,3 +32,20 @@ export function lowestPrice(durations: ItemDuration[]) {
export function formatCode(code: string) {
return code.length === 8 ? `${code.slice(0, 4)}-${code.slice(4)}` : code;
}
/**
* What a bundle's parts cost bought one by one (each service at the part's
* length), to show next to the bundle price — or null when a part isn't on
* sale (not in `items`, or a length the service no longer has).
*/
export function bundleListPrice(parts: BundlePart[], items: ItemRecord[]) {
let total = 0;
for (const part of parts) {
const item = items.find((candidate) => candidate.id === part.item);
if (!item || item.type === 'bundle') return null;
const unit = item.type === 'item_with_time' ? item.durations.find((d) => d.minutes === part.minutes)?.price : item.price;
if (unit == null) return null;
total += unit * part.count;
}
return Math.round(total * 100) / 100;
}