fix(medusa-plugin-sendgrid): Inject GiftCardService to eliminate undefined error (#2941)
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user