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;
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)
? `<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>`
const btnLabel =
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}`;
@@ -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");

View File

@@ -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/<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({
to: notifyTo,
orderName: match.orderName,
customerName,
customerEmail: email,
orderUrl: match.orderUrl,
adminOrderUrl,
transmittedAt: transmittedLabel,
returnStatus,
smtp,