From 0b9726a77868718e68c1efb70534401baa0d6a69 Mon Sep 17 00:00:00 2001 From: tommaso Date: Fri, 10 Jul 2026 10:12:41 +0200 Subject: [PATCH] Notifica merchant: link all'ordine nell'ADMIN (non la pagina cliente) Il bottone puntava a order.statusPageUrl, cioe' la pagina di stato lato cliente: inutile per il merchant, che il reso lo gestisce dal pannello. Ora punta a admin.shopify.com/store//orders/, ricavato dal GID dell'ordine. Etichetta contestuale: 'Gestisci il reso' quando un reso esiste o e' stato creato, altrimenti 'Apri l'ordine'. --- app/app/lib/mailer.server.ts | 13 +++++++++---- app/app/routes/proxy.tsx | 9 ++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/app/lib/mailer.server.ts b/app/app/lib/mailer.server.ts index f3703d4..37aaea6 100644 --- a/app/app/lib/mailer.server.ts +++ b/app/app/lib/mailer.server.ts @@ -239,7 +239,8 @@ export async function sendMerchantNotification(params: { orderName: string; customerName: string; customerEmail: string; - orderUrl: string; + /** URL dell'ordine nel pannello ADMIN (non la pagina cliente): qui si gestisce il reso. */ + adminOrderUrl: string; transmittedAt: string; returnStatus: "created" | "no_returnable" | "exists" | "error"; smtp?: SmtpConfig | null; @@ -258,8 +259,12 @@ export async function sendMerchantNotification(params: { ? "L'ordine non risulta evaso: valuta annullamento o rimborso." : "Reso non creato automaticamente: verifica manualmente l'ordine."; - const orderBtn = /^https?:\/\//i.test(params.orderUrl) - ? `

Apri l'ordine

` + const btnLabel = + params.returnStatus === "created" || params.returnStatus === "exists" + ? "Gestisci il reso" + : "Apri l'ordine"; + const orderBtn = /^https?:\/\//i.test(params.adminOrderUrl) + ? `

${btnLabel}

` : ""; const subject = `Nuovo recesso - Ordine ${params.orderName}`; @@ -289,7 +294,7 @@ ${orderBtn} `Trasmesso: ${params.transmittedAt}`, actionLine, "Promemoria: rimborso entro 14 giorni dalla richiesta (art. 56); puoi trattenere fino alla riconsegna della merce o alla prova di spedizione.", - /^https?:\/\//i.test(params.orderUrl) ? params.orderUrl : "", + /^https?:\/\//i.test(params.adminOrderUrl) ? params.adminOrderUrl : "", ] .filter(Boolean) .join("\n"); diff --git a/app/app/routes/proxy.tsx b/app/app/routes/proxy.tsx index b03276f..9fa27fb 100644 --- a/app/app/routes/proxy.tsx +++ b/app/app/routes/proxy.tsx @@ -549,12 +549,19 @@ export const action = async ({ request }: ActionFunctionArgs) => { const notifyTo = settings?.notifyEmail?.trim(); if (settings?.notifyEnabled && notifyTo) { try { + // Il merchant gestisce il reso dall'ADMIN, non dalla pagina cliente. + // gid://shopify/Order/123 -> admin.shopify.com/store//orders/123 + const storeHandle = shop.replace(/\.myshopify\.com$/, ""); + const orderNumericId = match.orderId.split("/").pop() ?? ""; + const adminOrderUrl = orderNumericId + ? `https://admin.shopify.com/store/${storeHandle}/orders/${orderNumericId}` + : ""; const notif = await sendMerchantNotification({ to: notifyTo, orderName: match.orderName, customerName, customerEmail: email, - orderUrl: match.orderUrl, + adminOrderUrl, transmittedAt: transmittedLabel, returnStatus, smtp,