release: next (#239)
* hotfix(medusa-plugin-brightpearl): Use order id in sales order endpoint * feat(medusa-plugin-sendgrid): adds localization option (#238) * chore(deps): bump y18n from 4.0.0 to 4.0.1 in /packages/medusa-cli (#226) Bumps [y18n](https://github.com/yargs/y18n) from 4.0.0 to 4.0.1. - [Release notes](https://github.com/yargs/y18n/releases) - [Changelog](https://github.com/yargs/y18n/blob/master/CHANGELOG.md) - [Commits](https://github.com/yargs/y18n/commits) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump y18n from 4.0.0 to 4.0.3 in /packages/medusa (#235) Bumps [y18n](https://github.com/yargs/y18n) from 4.0.0 to 4.0.3. - [Release notes](https://github.com/yargs/y18n/releases) - [Changelog](https://github.com/yargs/y18n/blob/y18n-v4.0.3/CHANGELOG.md) - [Commits](https://github.com/yargs/y18n/compare/v4.0.0...y18n-v4.0.3) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump y18n from 4.0.0 to 4.0.1 in /e2e/prod-project (#225) Bumps [y18n](https://github.com/yargs/y18n) from 4.0.0 to 4.0.1. - [Release notes](https://github.com/yargs/y18n/releases) - [Changelog](https://github.com/yargs/y18n/blob/master/CHANGELOG.md) - [Commits](https://github.com/yargs/y18n/commits) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump y18n in /packages/medusa-core-utils (#224) Bumps [y18n](https://github.com/yargs/y18n) from 4.0.0 to 4.0.1. - [Release notes](https://github.com/yargs/y18n/releases) - [Changelog](https://github.com/yargs/y18n/blob/master/CHANGELOG.md) - [Commits](https://github.com/yargs/y18n/commits) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat(medusa): Swaps on swaps (#229) Co-authored-by: Sebastian Rindom <skrindom@gmail.com> * chore: version bumps * chore: version bumps * chore(release): Publish - babel-preset-medusa-package@1.1.1 - @medusajs/medusa-cli@1.1.5 - medusa-core-utils@1.1.7 - medusa-dev-cli@0.0.6 - medusa-file-spaces@1.1.10 - medusa-fulfillment-manual@1.1.7 - medusa-fulfillment-webshipper@1.1.10 - medusa-interfaces@1.1.8 - medusa-payment-adyen@1.1.10 - medusa-payment-klarna@1.1.11 - medusa-payment-paypal@1.0.10 - medusa-payment-stripe@1.1.10 - medusa-plugin-add-ons@1.1.10 - medusa-plugin-brightpearl@1.1.13 - medusa-plugin-contentful@1.1.11 - medusa-plugin-discount-generator@1.1.1 - medusa-plugin-economic@1.1.10 - medusa-plugin-ip-lookup@1.1.1 - medusa-plugin-mailchimp@1.1.10 - medusa-plugin-permissions@1.1.10 - medusa-plugin-restock-notification@0.0.4 - medusa-plugin-segment@1.1.13 - medusa-plugin-sendgrid@1.1.11 - medusa-plugin-slack-notification@1.1.10 - medusa-plugin-twilio-sms@1.1.10 - medusa-plugin-wishlist@1.1.10 - medusa-test-utils@1.1.10 - @medusajs/medusa@1.1.20 * chore(release): Publish - babel-preset-medusa-package@1.1.2 - @medusajs/medusa-cli@1.1.6 - medusa-core-utils@1.1.8 - medusa-dev-cli@0.0.7 - medusa-file-spaces@1.1.11 - medusa-fulfillment-manual@1.1.8 - medusa-fulfillment-webshipper@1.1.11 - medusa-interfaces@1.1.9 - medusa-payment-adyen@1.1.11 - medusa-payment-klarna@1.1.12 - medusa-payment-paypal@1.0.11 - medusa-payment-stripe@1.1.11 - medusa-plugin-add-ons@1.1.11 - medusa-plugin-brightpearl@1.1.14 - medusa-plugin-contentful@1.1.12 - medusa-plugin-discount-generator@1.1.2 - medusa-plugin-economic@1.1.11 - medusa-plugin-ip-lookup@1.1.2 - medusa-plugin-mailchimp@1.1.11 - medusa-plugin-permissions@1.1.11 - medusa-plugin-restock-notification@0.0.5 - medusa-plugin-segment@1.1.14 - medusa-plugin-sendgrid@1.1.12 - medusa-plugin-slack-notification@1.1.11 - medusa-plugin-twilio-sms@1.1.11 - medusa-plugin-wishlist@1.1.11 - medusa-test-utils@1.1.11 - @medusajs/medusa@1.1.21 Co-authored-by: Sebastian Rindom <skrindom@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
6b51c06c22
commit
7343a4e841
@@ -3,6 +3,26 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.12](https://github.com/medusajs/medusa/compare/medusa-plugin-sendgrid@1.1.11...medusa-plugin-sendgrid@1.1.12) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-plugin-sendgrid
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.11](https://github.com/medusajs/medusa/compare/medusa-plugin-sendgrid@1.1.10...medusa-plugin-sendgrid@1.1.11) (2021-04-20)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **medusa:** Swaps on swaps ([#229](https://github.com/medusajs/medusa/issues/229)) ([f8f1f57](https://github.com/medusajs/medusa/commit/f8f1f57fa1bcdc6f7ae4183e657a07e2641b1345))
|
||||
* **medusa-plugin-sendgrid:** adds localization option ([#238](https://github.com/medusajs/medusa/issues/238)) ([a81ea1c](https://github.com/medusajs/medusa/commit/a81ea1c20a8779ba72e1ee5cc58c9b5335b79eca))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [1.1.10](https://github.com/medusajs/medusa/compare/medusa-plugin-sendgrid@1.1.9...medusa-plugin-sendgrid@1.1.10) (2021-04-13)
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,18 @@ If no values are defined for a given option, the plugin will not try to send an
|
||||
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]
|
||||
customer_password_reset_template: [used on customer.password_reset],
|
||||
localization: {
|
||||
"de-DE": { // locale key
|
||||
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],
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "medusa-plugin-sendgrid",
|
||||
"version": "1.1.10",
|
||||
"version": "1.1.12",
|
||||
"description": "SendGrid transactional emails",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
@@ -39,8 +39,8 @@
|
||||
"@sendgrid/mail": "^7.1.1",
|
||||
"body-parser": "^1.19.0",
|
||||
"express": "^4.17.1",
|
||||
"medusa-core-utils": "^1.1.6",
|
||||
"medusa-test-utils": "^1.1.9"
|
||||
"medusa-core-utils": "^1.1.8",
|
||||
"medusa-test-utils": "^1.1.11"
|
||||
},
|
||||
"gitHead": "d78a7ce85876e0bfd9a4bfebe4f5743921961e9c"
|
||||
"gitHead": "982da259ed93fe1b618800c8693a5c9dfe312532"
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ class SendGridService extends NotificationService {
|
||||
orderService,
|
||||
returnService,
|
||||
swapService,
|
||||
cartService,
|
||||
lineItemService,
|
||||
claimService,
|
||||
fulfillmentService,
|
||||
@@ -42,6 +43,7 @@ class SendGridService extends NotificationService {
|
||||
this.storeService_ = storeService
|
||||
this.lineItemService_ = lineItemService
|
||||
this.orderService_ = orderService
|
||||
this.cartService_ = cartService
|
||||
this.claimService_ = claimService
|
||||
this.returnService_ = returnService
|
||||
this.swapService_ = swapService
|
||||
@@ -105,7 +107,7 @@ class SendGridService extends NotificationService {
|
||||
return this.claimShipmentCreatedData(eventData, attachmentGenerator)
|
||||
case "order.items_returned":
|
||||
return this.itemsReturnedData(eventData, attachmentGenerator)
|
||||
case "order.swap_received":
|
||||
case "swap.received":
|
||||
return this.swapReceivedData(eventData, attachmentGenerator)
|
||||
case "swap.created":
|
||||
return this.swapCreatedData(eventData, attachmentGenerator)
|
||||
@@ -133,6 +135,45 @@ class SendGridService extends NotificationService {
|
||||
}
|
||||
}
|
||||
|
||||
getLocalizedTemplateId(event, locale) {
|
||||
if (this.options_.localization && this.options_.localization[locale]) {
|
||||
const map = this.options_.localization[locale]
|
||||
switch (event) {
|
||||
case "order.return_requested":
|
||||
return map.order_return_requested_template
|
||||
case "swap.shipment_created":
|
||||
return map.swap_shipment_created_template
|
||||
case "claim.shipment_created":
|
||||
return map.claim_shipment_created_template
|
||||
case "order.items_returned":
|
||||
return map.order_items_returned_template
|
||||
case "swap.received":
|
||||
return map.swap_received_template
|
||||
case "swap.created":
|
||||
return map.swap_created_template
|
||||
case "gift_card.created":
|
||||
return map.gift_card_created_template
|
||||
case "order.gift_card_created":
|
||||
return map.gift_card_created_template
|
||||
case "order.placed":
|
||||
return map.order_placed_template
|
||||
case "order.shipment_created":
|
||||
return map.order_shipped_template
|
||||
case "order.canceled":
|
||||
return map.order_canceled_template
|
||||
case "user.password_reset":
|
||||
return map.user_password_reset_template
|
||||
case "customer.password_reset":
|
||||
return map.customer_password_reset_template
|
||||
case "restock-notification.restocked":
|
||||
return map.medusa_restock_template
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
getTemplateId(event) {
|
||||
switch (event) {
|
||||
case "order.return_requested":
|
||||
@@ -143,8 +184,8 @@ class SendGridService extends NotificationService {
|
||||
return this.options_.claim_shipment_created_template
|
||||
case "order.items_returned":
|
||||
return this.options_.order_items_returned_template
|
||||
case "order.swap_received":
|
||||
return this.options_.order_swap_received_template
|
||||
case "swap.received":
|
||||
return this.options_.swap_received_template
|
||||
case "swap.created":
|
||||
return this.options_.swap_created_template
|
||||
case "gift_card.created":
|
||||
@@ -182,6 +223,10 @@ class SendGridService extends NotificationService {
|
||||
attachmentGenerator
|
||||
)
|
||||
|
||||
if (data.locale) {
|
||||
templateId = this.getLocalizedTemplateId(event, data.locale) || templateId
|
||||
}
|
||||
|
||||
const sendOptions = {
|
||||
template_id: templateId,
|
||||
from: this.options_.from,
|
||||
@@ -289,7 +334,10 @@ class SendGridService extends NotificationService {
|
||||
relations: ["items", "tracking_links"],
|
||||
})
|
||||
|
||||
const locale = await this.extractLocale(order)
|
||||
|
||||
return {
|
||||
locale,
|
||||
order,
|
||||
date: shipment.shipped_at.toDateString(),
|
||||
email: order.email,
|
||||
@@ -365,8 +413,11 @@ class SendGridService extends NotificationService {
|
||||
discounts.concat(giftCards)
|
||||
}
|
||||
|
||||
const locale = await this.extractLocale(order)
|
||||
|
||||
return {
|
||||
...order,
|
||||
locale,
|
||||
has_discounts: order.discounts.length,
|
||||
has_gift_cards: order.gift_cards.length,
|
||||
date: order.created_at.toDateString(),
|
||||
@@ -404,8 +455,11 @@ class SendGridService extends NotificationService {
|
||||
|
||||
const taxRate = giftCard.region.tax_rate / 100
|
||||
|
||||
const locale = await this.extractLocale(order)
|
||||
|
||||
return {
|
||||
...giftCard,
|
||||
locale,
|
||||
email: giftCard.order.email,
|
||||
display_value: giftCard.value * (1 + taxRate),
|
||||
}
|
||||
@@ -439,12 +493,28 @@ class SendGridService extends NotificationService {
|
||||
// Fetch the order
|
||||
const order = await this.orderService_.retrieve(id, {
|
||||
select: ["total"],
|
||||
relations: ["items", "discounts", "shipping_address", "returns"],
|
||||
relations: [
|
||||
"items",
|
||||
"discounts",
|
||||
"shipping_address",
|
||||
"returns",
|
||||
"swaps",
|
||||
"swaps.additional_items",
|
||||
],
|
||||
})
|
||||
|
||||
let merged = [...order.items]
|
||||
|
||||
// merge items from order with items from order swaps
|
||||
if (order.swaps && order.swaps.length) {
|
||||
for (const s of order.swaps) {
|
||||
merged = [...merged, ...s.additional_items]
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate which items are in the return
|
||||
const returnItems = returnRequest.items.map((i) => {
|
||||
const found = order.items.find((oi) => oi.id === i.item_id)
|
||||
const found = merged.find((oi) => oi.id === i.item_id)
|
||||
return {
|
||||
...found,
|
||||
quantity: i.quantity,
|
||||
@@ -463,7 +533,10 @@ class SendGridService extends NotificationService {
|
||||
shippingTotal = returnRequest.shipping_method.price * (1 + taxRate)
|
||||
}
|
||||
|
||||
const locale = await this.extractLocale(order)
|
||||
|
||||
return {
|
||||
locale,
|
||||
has_shipping: !!returnRequest.shipping_method,
|
||||
email: order.email,
|
||||
items: this.processItems_(returnItems, taxRate, currencyCode),
|
||||
@@ -525,15 +598,30 @@ class SendGridService extends NotificationService {
|
||||
|
||||
const order = await this.orderService_.retrieve(swap.order_id, {
|
||||
select: ["total"],
|
||||
relations: ["items", "discounts", "shipping_address"],
|
||||
relations: [
|
||||
"items",
|
||||
"discounts",
|
||||
"shipping_address",
|
||||
"swaps",
|
||||
"swaps.additional_items",
|
||||
],
|
||||
})
|
||||
|
||||
const taxRate = order.tax_rate / 100
|
||||
const currencyCode = order.currency_code.toUpperCase()
|
||||
|
||||
let merged = [...order.items]
|
||||
|
||||
// merge items from order with items from order swaps
|
||||
if (order.swaps && order.swaps.length) {
|
||||
for (const s of order.swaps) {
|
||||
merged = [...merged, ...s.additional_items]
|
||||
}
|
||||
}
|
||||
|
||||
const returnItems = this.processItems_(
|
||||
swap.return_order.items.map((i) => {
|
||||
const found = order.items.find((oi) => oi.id === i.item_id)
|
||||
const found = merged.find((oi) => oi.id === i.item_id)
|
||||
return {
|
||||
...found,
|
||||
quantity: i.quantity,
|
||||
@@ -555,7 +643,10 @@ class SendGridService extends NotificationService {
|
||||
|
||||
const refundAmount = swap.return_order.refund_amount
|
||||
|
||||
const locale = await this.extractLocale(order)
|
||||
|
||||
return {
|
||||
locale,
|
||||
swap,
|
||||
order,
|
||||
return_request: returnRequest,
|
||||
@@ -595,15 +686,24 @@ class SendGridService extends NotificationService {
|
||||
})
|
||||
|
||||
const order = await this.orderService_.retrieve(swap.order_id, {
|
||||
relations: ["items", "discounts"],
|
||||
relations: ["items", "discounts", "swaps", "swaps.additional_items"],
|
||||
})
|
||||
|
||||
let merged = [...order.items]
|
||||
|
||||
// merge items from order with items from order swaps
|
||||
if (order.swaps && order.swaps.length) {
|
||||
for (const s of order.swaps) {
|
||||
merged = [...merged, ...s.additional_items]
|
||||
}
|
||||
}
|
||||
|
||||
const taxRate = order.tax_rate / 100
|
||||
const currencyCode = order.currency_code.toUpperCase()
|
||||
|
||||
const returnItems = this.processItems_(
|
||||
swap.return_order.items.map((i) => {
|
||||
const found = order.items.find((oi) => oi.id === i.item_id)
|
||||
const found = merged.find((oi) => oi.id === i.item_id)
|
||||
return {
|
||||
...found,
|
||||
quantity: i.quantity,
|
||||
@@ -629,7 +729,10 @@ class SendGridService extends NotificationService {
|
||||
relations: ["tracking_links"],
|
||||
})
|
||||
|
||||
const locale = await this.extractLocale(order)
|
||||
|
||||
return {
|
||||
locale,
|
||||
swap,
|
||||
order,
|
||||
items: this.processItems_(swap.additional_items, taxRate, currencyCode),
|
||||
@@ -670,7 +773,10 @@ class SendGridService extends NotificationService {
|
||||
relations: ["tracking_links"],
|
||||
})
|
||||
|
||||
const locale = await this.extractLocale(claim.order)
|
||||
|
||||
return {
|
||||
locale,
|
||||
email: claim.order.email,
|
||||
claim,
|
||||
order: claim.order,
|
||||
@@ -745,6 +851,25 @@ class SendGridService extends NotificationService {
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
async extractLocale(fromOrder) {
|
||||
if (fromOrder.cart_id) {
|
||||
try {
|
||||
const cart = await this.cartService_.retrieve(fromOrder.cart_id, {
|
||||
select: ["context"],
|
||||
})
|
||||
|
||||
if (cart.context && cart.context.locale) {
|
||||
return cart.context.locale
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
console.warn("Failed to gather context for order")
|
||||
return null
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export default SendGridService
|
||||
|
||||
Reference in New Issue
Block a user