feat: Redesign email to match screenshot - dark header banner, order link, Product/Qty/Price table
This commit is contained in:
parent
62a135dc85
commit
f18a018a38
97
mailer.js
97
mailer.js
@ -36,32 +36,20 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer) => {
|
||||
// --- 1. Generate Order Summary Rows HTML ---
|
||||
let orderRowsHtml = '';
|
||||
if (orderData.line_items && orderData.line_items.length > 0) {
|
||||
orderData.line_items.forEach(item => {
|
||||
// Shopify stores product image under item.image (object with src) or item.featured_image.url
|
||||
const itemImageUrl = (item.image && item.image.src)
|
||||
|| (item.image && typeof item.image === 'string' ? item.image : '')
|
||||
|| (item.featured_image && item.featured_image.url)
|
||||
|| '';
|
||||
const imageHtml = itemImageUrl
|
||||
? `<td style="padding: 15px 0; width: 60px; vertical-align: middle;">
|
||||
<img src="${itemImageUrl}" alt="${item.title}" style="width: 50px; height: 50px; border-radius: 6px; border: 1px solid #e2e8f0; object-fit: cover;" />
|
||||
</td>`
|
||||
: `<td style="padding: 15px 0; width: 60px; vertical-align: middle;">
|
||||
<div style="width: 50px; height: 50px; border-radius: 6px; border: 1px solid #e2e8f0; background: #f8fafc;"></div>
|
||||
</td>`;
|
||||
|
||||
const variantText = item.variant_title ? `<span style="font-size: 12px; color: #64748b; display: block; margin-top: 2px;">${item.variant_title}</span>` : '';
|
||||
const itemTotal = (parseFloat(item.price) * item.quantity).toFixed(2);
|
||||
|
||||
orderData.line_items.forEach((item, index) => {
|
||||
const itemPrice = parseFloat(item.price).toFixed(2);
|
||||
const rowBg = index % 2 === 0 ? '#ffffff' : '#f8fafc';
|
||||
orderRowsHtml += `
|
||||
<tr style="border-bottom: 1px solid #f1f5f9;">
|
||||
${imageHtml}
|
||||
<td style="padding: 15px 10px; vertical-align: middle; font-family: Helvetica, Arial, sans-serif; font-size: 14px; color: #1e293b;">
|
||||
<span style="font-weight: bold;">${item.title || item.name}</span> × ${item.quantity}
|
||||
${variantText}
|
||||
<tr style="background-color: ${rowBg};">
|
||||
<td style="padding: 10px 12px; font-family: Helvetica, Arial, sans-serif; font-size: 13px; color: #1e293b; border: 1px solid #e2e8f0;">
|
||||
${item.title || item.name}
|
||||
${item.variant_title ? `<br/><span style="font-size: 11px; color: #64748b;">${item.variant_title}</span>` : ''}
|
||||
</td>
|
||||
<td style="padding: 15px 0; text-align: right; vertical-align: middle; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold; color: #1e293b; width: 120px;">
|
||||
${currencySymbol}${itemTotal}
|
||||
<td style="padding: 10px 12px; text-align: center; font-family: Helvetica, Arial, sans-serif; font-size: 13px; color: #1e293b; border: 1px solid #e2e8f0; width: 80px;">
|
||||
${item.quantity}
|
||||
</td>
|
||||
<td style="padding: 10px 12px; text-align: right; font-family: Helvetica, Arial, sans-serif; font-size: 13px; color: #1e293b; border: 1px solid #e2e8f0; width: 100px;">
|
||||
${currencySymbol}${itemPrice}
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
@ -118,55 +106,40 @@ const sendEmailWithAttachment = async (toEmail, orderData, pdfBuffer) => {
|
||||
<td align="center">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px; background-color: #ffffff; border-radius: 12px; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03); overflow: hidden; padding: 30px;">
|
||||
|
||||
<!-- Header Logo & Order number -->
|
||||
<!-- DARK HEADER BANNER -->
|
||||
<tr>
|
||||
<td style="padding-bottom: 25px;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td style="font-family: Helvetica, Arial, sans-serif;">
|
||||
<img src="data:${logoMimeType};base64,${logoBase64}" alt="rayaarishop" style="height: 60px; width: auto; display: block;" />
|
||||
</td>
|
||||
<td align="right" style="font-family: Helvetica, Arial, sans-serif; font-size: 13px; color: #94a3b8; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px;">
|
||||
Order #${orderNumber}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<td style="background-color: #3d3d3d; padding: 24px 30px; border-radius: 8px 8px 0 0; margin-bottom: 0;">
|
||||
<h1 style="font-family: Helvetica, Arial, sans-serif; font-size: 26px; font-weight: bold; color: #ffffff; margin: 0;">New Order: #${orderNumber}</h1>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- GREETINGS -->
|
||||
<!-- INTRO TEXT & ORDER LINK -->
|
||||
<tr>
|
||||
<td style="font-family: Helvetica, Arial, sans-serif; padding-bottom: 20px;">
|
||||
<h1 style="font-size: 22px; font-weight: bold; color: #1e293b; margin: 0 0 10px 0;">Thank you for your order!</h1>
|
||||
<p style="font-size: 14px; line-height: 1.5; color: #475569; margin: 0;">
|
||||
We're getting your order ready to be shipped. We have attached your custom PDF invoice directly to this email.
|
||||
<td style="padding: 25px 0 20px 0;">
|
||||
<p style="font-family: Helvetica, Arial, sans-serif; font-size: 14px; color: #475569; margin: 0 0 15px 0;">
|
||||
You've received the following order from
|
||||
<strong style="color: #1e293b;">${orderData.billing_address ? `${orderData.billing_address.first_name || ''} ${orderData.billing_address.last_name || ''}`.trim() : (orderData.contact_email || 'a customer')}</strong>:
|
||||
</p>
|
||||
<p style="font-family: Helvetica, Arial, sans-serif; font-size: 14px; color: #475569; margin: 0;">
|
||||
${orderData.order_status_url
|
||||
? `<a href="${orderData.order_status_url}" target="_blank" style="color: #1d4ed8; font-weight: bold; text-decoration: none;">[Order #${orderNumber}]</a>`
|
||||
: `<strong>[Order #${orderNumber}]</strong>`
|
||||
}
|
||||
<strong> (${new Date(orderData.created_at || Date.now()).toLocaleDateString('en-US', { month: 'long', day: 'numeric', year: 'numeric' })})</strong>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- ACTION BUTTON -->
|
||||
${orderData.order_status_url ? `
|
||||
<!-- ORDER SUMMARY TABLE with HEADER ROW -->
|
||||
<tr>
|
||||
<td style="padding: 10px 0 30px 0;">
|
||||
<a href="${orderData.order_status_url}" target="_blank" style="display: inline-block; background-color: #0284c7; color: #ffffff; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold; text-decoration: none; padding: 12px 24px; border-radius: 6px; box-shadow: 0 2px 4px rgba(2, 132, 199, 0.2);">
|
||||
View your order
|
||||
</a>
|
||||
<span style="font-family: Helvetica, Arial, sans-serif; font-size: 13px; color: #64748b; margin-left: 15px;">or <a href="https://rayaarishop.myshopify.com" target="_blank" style="color: #0284c7; text-decoration: none;">Visit our store</a></span>
|
||||
</td>
|
||||
<td style="padding-bottom: 20px;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; border: 1px solid #e2e8f0;">
|
||||
<!-- Table Header -->
|
||||
<tr style="background-color: #f1f5f9;">
|
||||
<td style="padding: 10px 12px; font-family: Helvetica, Arial, sans-serif; font-size: 13px; font-weight: bold; color: #1e293b; border: 1px solid #e2e8f0;">Product</td>
|
||||
<td style="padding: 10px 12px; text-align: center; font-family: Helvetica, Arial, sans-serif; font-size: 13px; font-weight: bold; color: #1e293b; border: 1px solid #e2e8f0; width: 80px;">Quantity</td>
|
||||
<td style="padding: 10px 12px; text-align: right; font-family: Helvetica, Arial, sans-serif; font-size: 13px; font-weight: bold; color: #1e293b; border: 1px solid #e2e8f0; width: 100px;">Price</td>
|
||||
</tr>
|
||||
` : ''}
|
||||
|
||||
<!-- ORDER SUMMARY HEADER -->
|
||||
<tr>
|
||||
<td style="padding-bottom: 10px; border-bottom: 2px solid #e2e8f0;">
|
||||
<h2 style="font-family: Helvetica, Arial, sans-serif; font-size: 15px; font-weight: bold; color: #1e293b; margin: 0; text-transform: uppercase; letter-spacing: 0.5px;">Order summary</h2>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- LINE ITEMS TABLE -->
|
||||
<tr>
|
||||
<td>
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
||||
${orderRowsHtml}
|
||||
</table>
|
||||
</td>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user