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

This commit is contained in:
RegisHubelia
2023-01-30 07:11:03 -05:00
committed by GitHub
parent e581d3bd90
commit 2551fe0b93
3 changed files with 15 additions and 11 deletions

View File

@@ -0,0 +1,5 @@
---
"medusa-plugin-sendgrid": minor
---
fix(medusa-plugin-sendgrid): Inject GiftCardService to eliminate undefined error

View File

@@ -3608,8 +3608,9 @@ You dont have to create a template for every type in the reference. You can s
```json noReport
Object {
"code": Any<String>,
"value": 4,
"value": 100,
"balance": 100,
"display_value": "100.00",
"region": Object {
"automatic_taxes": true,
"created_at": Any<Date>,
@@ -3937,7 +3938,7 @@ const plugins = [
order_placed_template: process.env.SENDGRID_ORDER_PLACED_ID,
localization: {
"de-DE": { // locale key
order_placed_template:
order_placed_template:
process.env.SENDGRID_ORDER_PLACED_ID_LOCALIZED,
},
},

View File

@@ -31,6 +31,7 @@ class SendGridService extends NotificationService {
fulfillmentProviderService,
totalsService,
productVariantService,
giftCardService,
},
options
) {
@@ -49,6 +50,7 @@ class SendGridService extends NotificationService {
this.fulfillmentService_ = fulfillmentService
this.totalsService_ = totalsService
this.productVariantService_ = productVariantService
this.giftCardService_ = giftCardService
SendGrid.setApiKey(options.api_key)
}
@@ -579,20 +581,16 @@ class SendGridService extends NotificationService {
const giftCard = await this.giftCardService_.retrieve(id, {
relations: ["region", "order"],
})
if (!giftCard.order) {
return
}
const taxRate = giftCard.region.tax_rate / 100
const locale = await this.extractLocale(order)
const locale = giftCard.order ? await this.extractLocale(order) : null;
const email = giftCard.order ? giftCard.order.email : giftCard.metadata.email;
return {
...giftCard,
locale,
email: giftCard.order.email,
display_value: giftCard.value * (1 + taxRate),
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
}
}