fix(medusa-plugin-sendgrid): Inject GiftCardService to eliminate undefined error (#2941)

This commit is contained in:
RegisHubelia
2023-01-30 13:11:03 +01:00
committed by GitHub
parent e581d3bd90
commit 2551fe0b93
3 changed files with 15 additions and 11 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"medusa-plugin-sendgrid": minor
---
fix(medusa-plugin-sendgrid): Inject GiftCardService to eliminate undefined error
+3 -2
View File
@@ -3608,8 +3608,9 @@ You dont have to create a template for every type in the reference. You can s
```json noReport ```json noReport
Object { Object {
"code": Any<String>, "code": Any<String>,
"value": 4, "value": 100,
"balance": 100, "balance": 100,
"display_value": "100.00",
"region": Object { "region": Object {
"automatic_taxes": true, "automatic_taxes": true,
"created_at": Any<Date>, "created_at": Any<Date>,
@@ -3937,7 +3938,7 @@ const plugins = [
order_placed_template: process.env.SENDGRID_ORDER_PLACED_ID, order_placed_template: process.env.SENDGRID_ORDER_PLACED_ID,
localization: { localization: {
"de-DE": { // locale key "de-DE": { // locale key
order_placed_template: order_placed_template:
process.env.SENDGRID_ORDER_PLACED_ID_LOCALIZED, process.env.SENDGRID_ORDER_PLACED_ID_LOCALIZED,
}, },
}, },
@@ -31,6 +31,7 @@ class SendGridService extends NotificationService {
fulfillmentProviderService, fulfillmentProviderService,
totalsService, totalsService,
productVariantService, productVariantService,
giftCardService,
}, },
options options
) { ) {
@@ -49,6 +50,7 @@ class SendGridService extends NotificationService {
this.fulfillmentService_ = fulfillmentService this.fulfillmentService_ = fulfillmentService
this.totalsService_ = totalsService this.totalsService_ = totalsService
this.productVariantService_ = productVariantService this.productVariantService_ = productVariantService
this.giftCardService_ = giftCardService
SendGrid.setApiKey(options.api_key) SendGrid.setApiKey(options.api_key)
} }
@@ -579,20 +581,16 @@ class SendGridService extends NotificationService {
const giftCard = await this.giftCardService_.retrieve(id, { const giftCard = await this.giftCardService_.retrieve(id, {
relations: ["region", "order"], relations: ["region", "order"],
}) })
if (!giftCard.order) {
return
}
const taxRate = giftCard.region.tax_rate / 100 const taxRate = giftCard.region.tax_rate / 100
const locale = giftCard.order ? await this.extractLocale(order) : null;
const locale = await this.extractLocale(order) const email = giftCard.order ? giftCard.order.email : giftCard.metadata.email;
return { return {
...giftCard, ...giftCard,
locale, locale,
email: giftCard.order.email, email,
display_value: giftCard.value * (1 + taxRate), display_value: `${this.humanPrice_((giftCard.value * 1+ taxRate), giftCard.region.currency_code)} ${giftCard.region.currency_code}`,
message: giftCard.metadata?.message || giftCard.metadata?.personal_message
} }
} }