docs: describes usage of plugin
This commit is contained in:
@@ -121,6 +121,8 @@ class SendGridService extends NotificationService {
|
||||
return this.userPasswordResetData(eventData, attachmentGenerator)
|
||||
case "customer.password_reset":
|
||||
return this.customerPasswordResetData(eventData, attachmentGenerator)
|
||||
case "restock-notification.restocked":
|
||||
return await this.restockNotificationData(eventData, attachmentGenerator)
|
||||
default:
|
||||
return {}
|
||||
}
|
||||
@@ -154,6 +156,8 @@ class SendGridService extends NotificationService {
|
||||
return this.options_.user_password_reset_template
|
||||
case "customer.password_reset":
|
||||
return this.options_.customer_password_reset_template
|
||||
case "restock-notification.restocked":
|
||||
return this.options_.medusa_restock_template
|
||||
default:
|
||||
return null
|
||||
}
|
||||
@@ -671,6 +675,19 @@ class SendGridService extends NotificationService {
|
||||
}
|
||||
}
|
||||
|
||||
async restockNotificationData({ variant_id, emails }) {
|
||||
const variant = await this.productVariantService_.retrieve(variant_id, {
|
||||
relations: ["product"]
|
||||
})
|
||||
|
||||
return {
|
||||
product: variant.product,
|
||||
variant,
|
||||
variant_id,
|
||||
emails
|
||||
}
|
||||
}
|
||||
|
||||
userPasswordResetData(data) {
|
||||
return data
|
||||
}
|
||||
@@ -698,7 +715,9 @@ class SendGridService extends NotificationService {
|
||||
}
|
||||
|
||||
const normalized = humanizeAmount(amount, currency)
|
||||
return normalized.toFixed(zeroDecimalCurrencies.includes(currency.toLowerCase()) ? 0 : 2)
|
||||
return normalized.toFixed(
|
||||
zeroDecimalCurrencies.includes(currency.toLowerCase()) ? 0 : 2
|
||||
)
|
||||
}
|
||||
|
||||
normalizeThumbUrl_(url) {
|
||||
|
||||
@@ -13,10 +13,6 @@ class OrderSubscriber {
|
||||
this.notificationService_.subscribe("swap.created", "sendgrid")
|
||||
this.notificationService_.subscribe("order.items_returned", "sendgrid")
|
||||
this.notificationService_.subscribe("order.return_requested", "sendgrid")
|
||||
this.notificationService_.subscribe(
|
||||
"restock_notification.restocked",
|
||||
"sendgrid"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
class RestockNotification {
|
||||
constructor({ eventBusService, sendgridService }) {
|
||||
eventBusService.subscribe(
|
||||
"restock-notification.restocked",
|
||||
async (eventData) => {
|
||||
const templateId = await sendgridService.getTemplateId(
|
||||
"restock-notification.restocked"
|
||||
)
|
||||
|
||||
if (!templateId) {
|
||||
return
|
||||
}
|
||||
|
||||
const data = await sendgridService.fetchData(
|
||||
"restock-notification.restocked",
|
||||
eventData,
|
||||
null
|
||||
)
|
||||
|
||||
if (!data.emails) {
|
||||
return
|
||||
}
|
||||
|
||||
return await Promise.all(
|
||||
data.emails.map(async (e) => {
|
||||
const sendOptions = {
|
||||
template_id: templateId,
|
||||
from: sendgridService.options_.from,
|
||||
to: e,
|
||||
dynamic_template_data: data,
|
||||
}
|
||||
|
||||
return await sendgridService.sendEmail(sendOptions)
|
||||
})
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default RestockNotification
|
||||
Reference in New Issue
Block a user