From 74b0939614d76d1b32785267d5fd74d7b81560f5 Mon Sep 17 00:00:00 2001 From: torbinus Date: Mon, 26 Oct 2026 10:34:55 +0100 Subject: [PATCH] Kundenkonto zeigt den echten Versandstatus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Detailseite: fulfillment_status ist bei Medusa kein gespeichertes Feld, sondern wird im Bestell-Workflow aus den Sendungen berechnet. Über query.graph kam er leer zurück, die Fortschrittsanzeige blieb immer auf "Bestellt". Jetzt über getOrderDetailWorkflow. Bestellliste: zeigte nur den Bestellstatus, der bei Medusa auf "pending" bleibt, auch nach der Zustellung. Jetzt dieselben Stufen wie auf der Detailseite (Verpackt, Versendet, Zugestellt). Im Test über alle Schritte im Admin nachvollzogen. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../store/customers/me/orders/[id]/route.ts | 11 ++++++++-- frontend/src/lib/auth.ts | 1 + frontend/src/pages/konto/index.astro | 21 ++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/backend/apps/backend/src/api/store/customers/me/orders/[id]/route.ts b/backend/apps/backend/src/api/store/customers/me/orders/[id]/route.ts index 359df0c..8c8278f 100644 --- a/backend/apps/backend/src/api/store/customers/me/orders/[id]/route.ts +++ b/backend/apps/backend/src/api/store/customers/me/orders/[id]/route.ts @@ -1,5 +1,6 @@ import { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/framework/http"; import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils"; +import { getOrderDetailWorkflow } from "@medusajs/core-flows"; // Matches Medusa's own "ALL /store/customers/me*" middleware, so this route // is already protected by customer bearer/session auth before it runs — @@ -52,7 +53,6 @@ export async function GET(req: AuthenticatedMedusaRequest, res: MedusaResponse) entity: "order", filters: { id: order.id }, fields: [ - "fulfillment_status", "fulfillments.packed_at", "fulfillments.shipped_at", "fulfillments.delivered_at", @@ -63,6 +63,13 @@ export async function GET(req: AuthenticatedMedusaRequest, res: MedusaResponse) }); const fulfillmentData = data[0] as any; + // fulfillment_status ist kein gespeichertes Feld: Medusa berechnet ihn + // erst im Bestell-Workflow aus den Sendungen. Über query.graph kam er + // leer zurück, und die Fortschrittsanzeige blieb immer auf "Bestellt". + const { result: detail } = await getOrderDetailWorkflow(req.scope).run({ + input: { order_id: order.id, fields: ["id", "fulfillment_status"] }, + }); + res.json({ order: { id: order.id, @@ -75,7 +82,7 @@ export async function GET(req: AuthenticatedMedusaRequest, res: MedusaResponse) item_total: itemTotal, shipping_total: shippingTotal, total: Math.round((itemTotal + shippingTotal) * 100) / 100, - fulfillment_status: fulfillmentData?.fulfillment_status ?? "not_fulfilled", + fulfillment_status: (detail as any)?.fulfillment_status ?? "not_fulfilled", fulfillments: (fulfillmentData?.fulfillments ?? []).map((f: any) => ({ packed_at: f.packed_at, shipped_at: f.shipped_at, diff --git a/frontend/src/lib/auth.ts b/frontend/src/lib/auth.ts index 10a6597..590e178 100644 --- a/frontend/src/lib/auth.ts +++ b/frontend/src/lib/auth.ts @@ -50,6 +50,7 @@ export interface MedusaOrderSummary { id: string; display_id: number; status: string; + fulfillment_status?: string; total: number; currency_code: string; created_at: string; diff --git a/frontend/src/pages/konto/index.astro b/frontend/src/pages/konto/index.astro index a13397b..961232c 100644 --- a/frontend/src/pages/konto/index.astro +++ b/frontend/src/pages/konto/index.astro @@ -27,6 +27,25 @@ const STATUS_LABELS: Record = { archived: "Archiviert", draft: "Entwurf", }; + +// Der Bestellstatus bleibt bei Medusa auf "pending", auch wenn das Paket +// längst zugestellt ist. Was die Kundin wissen will, steckt im Versandstatus — +// dieselben Stufen wie auf der Detailseite. +const VERSAND_LABELS: Record = { + fulfilled: "Verpackt", + partially_fulfilled: "Verpackt", + shipped: "Versendet", + partially_shipped: "Versendet", + delivered: "Zugestellt", + partially_delivered: "Zugestellt", +}; + +function statusLabel(order: { status: string; fulfillment_status?: string }): string { + if (order.status === "pending" && order.fulfillment_status && VERSAND_LABELS[order.fulfillment_status]) { + return VERSAND_LABELS[order.fulfillment_status]; + } + return STATUS_LABELS[order.status] ?? order.status; +} --- @@ -66,7 +85,7 @@ const STATUS_LABELS: Record = {
- {STATUS_LABELS[order.status] ?? order.status} + {statusLabel(order)} {new Intl.NumberFormat("de-DE", { style: "currency", currency: order.currency_code.toUpperCase() }).format(order.total)}