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/<handle>/orders/<id>, ricavato dal GID dell'ordine.
Etichetta contestuale: 'Gestisci il reso' quando un reso esiste o e' stato creato,
altrimenti 'Apri l'ordine'.
This commit is contained in:
2026-07-10 10:12:41 +02:00
parent b15567c8e1
commit 0b9726a778
2 changed files with 17 additions and 5 deletions

View File

@@ -239,7 +239,8 @@ export async function sendMerchantNotification(params: {
orderName: string; orderName: string;
customerName: string; customerName: string;
customerEmail: string; customerEmail: string;
orderUrl: string; /** URL dell'ordine nel pannello ADMIN (non la pagina cliente): qui si gestisce il reso. */
adminOrderUrl: string;
transmittedAt: string; transmittedAt: string;
returnStatus: "created" | "no_returnable" | "exists" | "error"; returnStatus: "created" | "no_returnable" | "exists" | "error";
smtp?: SmtpConfig | null; smtp?: SmtpConfig | null;
@@ -258,8 +259,12 @@ export async function sendMerchantNotification(params: {
? "L'ordine non risulta evaso: valuta annullamento o rimborso." ? "L'ordine non risulta evaso: valuta annullamento o rimborso."
: "Reso non creato automaticamente: verifica manualmente l'ordine."; : "Reso non creato automaticamente: verifica manualmente l'ordine.";
const orderBtn = /^https?:\/\//i.test(params.orderUrl) const btnLabel =
? `<p style="margin:16px 0 0;"><a href="${escM(params.orderUrl)}" style="display:inline-block;padding:10px 18px;background:#1a1a1a;color:#fff;text-decoration:none;border-radius:8px;font-size:14px;font-weight:600;">Apri l'ordine</a></p>` params.returnStatus === "created" || params.returnStatus === "exists"
? "Gestisci il reso"
: "Apri l'ordine";
const orderBtn = /^https?:\/\//i.test(params.adminOrderUrl)
? `<p style="margin:16px 0 0;"><a href="${escM(params.adminOrderUrl)}" style="display:inline-block;padding:10px 18px;background:#1a1a1a;color:#fff;text-decoration:none;border-radius:8px;font-size:14px;font-weight:600;">${btnLabel}</a></p>`
: ""; : "";
const subject = `Nuovo recesso - Ordine ${params.orderName}`; const subject = `Nuovo recesso - Ordine ${params.orderName}`;
@@ -289,7 +294,7 @@ ${orderBtn}
`Trasmesso: ${params.transmittedAt}`, `Trasmesso: ${params.transmittedAt}`,
actionLine, actionLine,
"Promemoria: rimborso entro 14 giorni dalla richiesta (art. 56); puoi trattenere fino alla riconsegna della merce o alla prova di spedizione.", "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) .filter(Boolean)
.join("\n"); .join("\n");

View File

@@ -549,12 +549,19 @@ export const action = async ({ request }: ActionFunctionArgs) => {
const notifyTo = settings?.notifyEmail?.trim(); const notifyTo = settings?.notifyEmail?.trim();
if (settings?.notifyEnabled && notifyTo) { if (settings?.notifyEnabled && notifyTo) {
try { try {
// Il merchant gestisce il reso dall'ADMIN, non dalla pagina cliente.
// gid://shopify/Order/123 -> admin.shopify.com/store/<handle>/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({ const notif = await sendMerchantNotification({
to: notifyTo, to: notifyTo,
orderName: match.orderName, orderName: match.orderName,
customerName, customerName,
customerEmail: email, customerEmail: email,
orderUrl: match.orderUrl, adminOrderUrl,
transmittedAt: transmittedLabel, transmittedAt: transmittedLabel,
returnStatus, returnStatus,
smtp, smtp,