fix(medusa-plugin-sendgrid): Adds order shipped support
This commit is contained in:
@@ -13,6 +13,7 @@ If no values are defined for a given option, the plugin will not try to send an
|
||||
gift_card_created_template: [used on gift_card.created],
|
||||
order_placed_template: [used on order.placed],
|
||||
order_cancelled_template: [used on order.cancelled],
|
||||
order_shipped_template: [used on order.shipment_created],
|
||||
order_completed_template: [used on order.completed],
|
||||
user_password_reset_template: [used on user.password_reset],
|
||||
customer_password_reset_template: [used on customer.password_reset]
|
||||
|
||||
@@ -42,6 +42,9 @@ class SendGridService extends BaseService {
|
||||
case "order.updated":
|
||||
templateId = this.options_.order_updated_template
|
||||
break
|
||||
case "order.shipment_created":
|
||||
templateId = this.options_.order_shipped_template
|
||||
break
|
||||
case "order.cancelled":
|
||||
templateId = this.options_.order_cancelled_template
|
||||
break
|
||||
|
||||
@@ -1,9 +1,31 @@
|
||||
class OrderSubscriber {
|
||||
constructor({ totalsService, sendgridService, eventBusService }) {
|
||||
constructor({
|
||||
totalsService,
|
||||
orderService,
|
||||
sendgridService,
|
||||
eventBusService,
|
||||
}) {
|
||||
this.orderService_ = orderService
|
||||
this.totalsService_ = totalsService
|
||||
this.sendgridService_ = sendgridService
|
||||
this.eventBus_ = eventBusService
|
||||
|
||||
this.eventBus_.subscribe(
|
||||
"order.shipment_created",
|
||||
async ({ order_id, shipment }) => {
|
||||
const order = await this.orderService_.retrieve(order_id)
|
||||
const data = {
|
||||
...order,
|
||||
tracking_number: shipment.tracking_numbers.join(", "),
|
||||
}
|
||||
|
||||
await this.sendgridService_.transactionalEmail(
|
||||
"order.shipment_created",
|
||||
data
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
this.eventBus_.subscribe("order.gift_card_created", async (order) => {
|
||||
await this.sendgridService_.transactionalEmail(
|
||||
"order.gift_card_created",
|
||||
|
||||
Reference in New Issue
Block a user