Skip to content

Instantly share code, notes, and snippets.

@bobharley
Created April 6, 2021 09:55
Show Gist options
  • Save bobharley/cc09fc95bbb2446cdb17369389b03fef to your computer and use it in GitHub Desktop.
Save bobharley/cc09fc95bbb2446cdb17369389b03fef to your computer and use it in GitHub Desktop.
test email
const path = require('path')
require('dotenv').config({
path: path.resolve('../.env'),
})
require('dotenv').config({
path: path.resolve('../.env.development'),
})
const { sendEmailTemplate } = require('./utils/index')
const generateOrderItemTemplate = item => {
const { image, price, quantity, name } = item
return `<table border="0" cellpadding="0" cellspacing="0" width="100%" class="mcnCaptionBlock">
<tbody class="mcnCaptionBlockOuter">
<tr>
<td class="mcnCaptionBlockInner" valign="top" style="padding:9px;">
<table border="0" cellpadding="0" cellspacing="0" class="mcnCaptionRightContentOuter" width="100%">
<tbody>
<tr>
<td valign="top" class="mcnCaptionRightContentInner" style="padding:0 9px;">
<table align="left" border="0" cellpadding="0" cellspacing="0" class="mcnCaptionRightImageContentContainer image" width="90">
<tbody>
<tr>
<td class="mcnCaptionRightImageContent" align="left" valign="top">
<img alt="" src="${image}" width="80" style="max-width:80px;" class="mcnImage">
</td>
</tr>
</tbody>
</table>
<table class="mcnCaptionRightTextContentContainer details" align="right" border="0" cellpadding="0" cellspacing="0" width="445">
<tbody>
<tr>
<td valign="top" class="mcnTextContent" style="font-family:'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;padding-left:0px !important;">
<h4 class="null">${name}</h4>
<div style="color:#6E98EB;">₱ ${price.toLocaleString(
'en-US',
{ maximumFractionDigits: 2 }
)}</div>
<div>Quantity: ${quantity || 1}</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>`
}
const run = async () => {
const items = [
{
name: 'cat',
price: 8000,
image:
'https://www.catster.com/wp-content/uploads/2017/11/A-Siamese-cat.jpg',
},
{
name: 'cat',
price: 8000,
image:
'https://www.catster.com/wp-content/uploads/2017/11/A-Siamese-cat.jpg',
},
]
const totalPrice = `₱ ${items
.reduce((total, item) => total + item.price * (item.quantity || 1), 0)
.toLocaleString('en-US', { maximumFractionDigits: 2 })}`
const response = await sendEmailTemplate({
to: '[email protected]',
subject: 'BUZZ! Order Confirmed',
templateName: 'CODE - Checkout_ Customer - Sell Order conf cash',
data: {
date_ordered: 'test',
payment_method: 'cash',
full_name: 'harlly dela cruz',
billing_address: 'lorem ipsum',
shipping_address: 'lorem ipsum',
payment_method: 'cash',
items: items.map(generateOrderItemTemplate).join('\n'),
total: totalPrice,
subtotal: totalPrice,
},
})
console.log(response)
}
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment