import fs from 'fs/promises'; import path from 'path'; import { CONSTANTS } from '../../../../lib/helpers.js'; import { translate } from '../../../../lib/locale/translate/translate.js'; import { debug, error } from '../../../../lib/log/logger.js'; import { buildEmailBodyFromTemplate, sendEmail } from '../../../../lib/mail/emailHelper.js'; import { getConfig } from '../../../../lib/util/getConfig.js'; import { getValue } from '../../../../lib/util/registry.js'; import { EventData } from '../../../../types/event.js'; const TEMPLATE = ` {{#if storeInfo.logo}} {{/if}}
Welcome {{customer.full_name}}. Thanks for joining us.
 ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏
{{#if storeInfo.logo}} {{storeInfo.logo.alt}} {{/if}}

Hi {{customer.full_name}},

Welcome to {{storeInfo.storeName}}. We are excited to have you on board. You can now start shopping and enjoy the best deals on the market.

Start shopping

Best,
The {{storeInfo.storeName}}


{{storeInfo.address.street}}, {{storeInfo.address.city}}, {{storeInfo.address.state}} {{storeInfo.address.zip}}, {{storeInfo.address.country}}

`; export default async function sendCustomerWelcomeEmail( data: EventData<'customer_registered'> ) { try { const email = data.email; const subject = translate('Welcome to our store!'); const config = getConfig('system.notification_emails.customer_welcome', { enabled: true }); if (config?.enabled === false) { return; } let template; if (config?.templatePath) { const filePath = path.join(CONSTANTS.ROOTPATH, config.templatePath); try { await fs.access(filePath); template = await fs.readFile(filePath, 'utf8'); } catch (error) { debug( `Customer welcome email template file not found at path: ${filePath}. Using default template.` ); template = TEMPLATE; } } else { template = TEMPLATE; } const dynamicData = await getValue('customerWelcomeEmailData', { customer: data }); const args = await getValue( 'customerWelcomeEmailArguments', { to: email, subject, template, data: dynamicData }, { customer: data } ); await sendEmail('customer_welcome', args); } catch (e) { error(e); } }