Kundenkonto zeigt den echten Versandstatus

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) <noreply@anthropic.com>
This commit is contained in:
torbinus
2026-10-26 10:34:55 +01:00
parent 9f25f29b7f
commit 74b0939614
3 changed files with 30 additions and 3 deletions
@@ -1,5 +1,6 @@
import { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/framework/http"; import { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/framework/http";
import { ContainerRegistrationKeys, Modules } from "@medusajs/framework/utils"; 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 // Matches Medusa's own "ALL /store/customers/me*" middleware, so this route
// is already protected by customer bearer/session auth before it runs — // 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", entity: "order",
filters: { id: order.id }, filters: { id: order.id },
fields: [ fields: [
"fulfillment_status",
"fulfillments.packed_at", "fulfillments.packed_at",
"fulfillments.shipped_at", "fulfillments.shipped_at",
"fulfillments.delivered_at", "fulfillments.delivered_at",
@@ -63,6 +63,13 @@ export async function GET(req: AuthenticatedMedusaRequest, res: MedusaResponse)
}); });
const fulfillmentData = data[0] as any; 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({ res.json({
order: { order: {
id: order.id, id: order.id,
@@ -75,7 +82,7 @@ export async function GET(req: AuthenticatedMedusaRequest, res: MedusaResponse)
item_total: itemTotal, item_total: itemTotal,
shipping_total: shippingTotal, shipping_total: shippingTotal,
total: Math.round((itemTotal + shippingTotal) * 100) / 100, 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) => ({ fulfillments: (fulfillmentData?.fulfillments ?? []).map((f: any) => ({
packed_at: f.packed_at, packed_at: f.packed_at,
shipped_at: f.shipped_at, shipped_at: f.shipped_at,
+1
View File
@@ -50,6 +50,7 @@ export interface MedusaOrderSummary {
id: string; id: string;
display_id: number; display_id: number;
status: string; status: string;
fulfillment_status?: string;
total: number; total: number;
currency_code: string; currency_code: string;
created_at: string; created_at: string;
+20 -1
View File
@@ -27,6 +27,25 @@ const STATUS_LABELS: Record<string, string> = {
archived: "Archiviert", archived: "Archiviert",
draft: "Entwurf", 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<string, string> = {
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;
}
--- ---
<Layout title="Mein Konto" description="Ihre Bestellungen bei place4bees im Überblick."> <Layout title="Mein Konto" description="Ihre Bestellungen bei place4bees im Überblick.">
@@ -66,7 +85,7 @@ const STATUS_LABELS: Record<string, string> = {
</div> </div>
<div class="flex items-center gap-5"> <div class="flex items-center gap-5">
<span class="rounded-[6px] bg-brand-surface-sunk px-3 py-1.5 text-xs font-medium text-brand-text"> <span class="rounded-[6px] bg-brand-surface-sunk px-3 py-1.5 text-xs font-medium text-brand-text">
{STATUS_LABELS[order.status] ?? order.status} {statusLabel(order)}
</span> </span>
<span class="font-medium tabular-nums text-brand-ink"> <span class="font-medium tabular-nums text-brand-ink">
{new Intl.NumberFormat("de-DE", { style: "currency", currency: order.currency_code.toUpperCase() }).format(order.total)} {new Intl.NumberFormat("de-DE", { style: "currency", currency: order.currency_code.toUpperCase() }).format(order.total)}