diff --git a/.changeset/twelve-laws-pull.md b/.changeset/twelve-laws-pull.md new file mode 100644 index 0000000000..2e1a019d82 --- /dev/null +++ b/.changeset/twelve-laws-pull.md @@ -0,0 +1,6 @@ +--- +"medusa-plugin-sendgrid": patch +"@medusajs/medusa": patch +--- + +fix(medusa-plugin-sendgrid): Undefined order diff --git a/packages/medusa-plugin-sendgrid/src/services/sendgrid.js b/packages/medusa-plugin-sendgrid/src/services/sendgrid.js index a7fc8663d5..7259b3eecc 100644 --- a/packages/medusa-plugin-sendgrid/src/services/sendgrid.js +++ b/packages/medusa-plugin-sendgrid/src/services/sendgrid.js @@ -582,15 +582,23 @@ class SendGridService extends NotificationService { relations: ["region", "order"], }) const taxRate = giftCard.region.tax_rate / 100 - const locale = giftCard.order ? await this.extractLocale(order) : null; - const email = giftCard.order ? giftCard.order.email : giftCard.metadata.email; + const locale = giftCard.order + ? await this.extractLocale(giftCard.order) + : null + const email = giftCard.order + ? giftCard.order.email + : giftCard.metadata.email return { ...giftCard, locale, email, - display_value: `${this.humanPrice_((giftCard.value * 1+ taxRate), giftCard.region.currency_code)} ${giftCard.region.currency_code}`, - message: giftCard.metadata?.message || giftCard.metadata?.personal_message + display_value: `${this.humanPrice_( + giftCard.value * 1 + taxRate, + giftCard.region.currency_code + )} ${giftCard.region.currency_code}`, + message: + giftCard.metadata?.message || giftCard.metadata?.personal_message, } } @@ -1161,13 +1169,7 @@ class SendGridService extends NotificationService { async orderRefundCreatedData({ id, refund_id }) { const order = await this.orderService_.retrieveWithTotals(id, { - select: [ - "total", - ], - relations: [ - "refunds", - "items", - ] + relations: ["refunds", "items"], }) const refund = order.refunds.find((refund) => refund.id === refund_id) @@ -1175,11 +1177,10 @@ class SendGridService extends NotificationService { return { order, refund, - refund_amount: `${this.humanPrice_( - refund.amount, + refund_amount: `${this.humanPrice_(refund.amount, order.currency_code)} ${ order.currency_code - )} ${order.currency_code}`, - email: order.email + }`, + email: order.email, } }