From dba118058739380e832ab35efd1bd8ba8d93620b Mon Sep 17 00:00:00 2001 From: Arnis Lielturks Date: Thu, 25 Apr 2024 22:55:31 +0300 Subject: [PATCH] shipping price added to emails --- data/emails/order.cancelled/html.pug | 6 ++++++ data/emails/order.placed/html.pug | 6 ++++++ package.json | 2 +- src/services/emails.ts | 22 +++++++++++++++++++--- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/data/emails/order.cancelled/html.pug b/data/emails/order.cancelled/html.pug index d3c7e17..60b5883 100644 --- a/data/emails/order.cancelled/html.pug +++ b/data/emails/order.cancelled/html.pug @@ -12,6 +12,12 @@ block description img(src=item.thumbnail) td p #{item.unit_price / 100} #{order.currency_code === 'usd' ? '$' : order.currency_code} x#{item.quantity} + for item in order.shipping_methods + tr + td(colspan="2") + p #{item.shipping_option.name} + td + p #{item.shipping_option.amount / 100} #{order.currency_code === 'usd' ? '$' : order.currency_code} tr td(colspan="2") p(class="align-right bold") Total diff --git a/data/emails/order.placed/html.pug b/data/emails/order.placed/html.pug index f126557..119af04 100644 --- a/data/emails/order.placed/html.pug +++ b/data/emails/order.placed/html.pug @@ -12,6 +12,12 @@ block description img(src=item.thumbnail) td p #{item.unit_price / 100} #{order.currency_code === 'usd' ? '$' : order.currency_code} x#{item.quantity} + for item in order.shipping_methods + tr + td(colspan="2") + p #{item.shipping_option.name} + td + p #{item.shipping_option.amount / 100} #{order.currency_code === 'usd' ? '$' : order.currency_code} tr td(colspan="2") p(class="align-right bold") Total diff --git a/package.json b/package.json index 2a2c27d..e43cd25 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@rootxpdev/medusa-email-plugin", - "version": "0.4.2", + "version": "0.4.3", "description": "Send emails when certain actions happens in medusa store", "main": "index.js", "repository": { diff --git a/src/services/emails.ts b/src/services/emails.ts index 4019bd5..fbeedbd 100644 --- a/src/services/emails.ts +++ b/src/services/emails.ts @@ -58,18 +58,34 @@ class EmailsService extends AbstractNotificationService { relations: [ "refunds", "items", + "customer", + "billing_address", + "shipping_address", + "discounts", + "discounts.rule", + "shipping_methods", + "shipping_methods.shipping_option", + "payments", + "fulfillments", + "returns", + "gift_cards", + "gift_card_transactions", ] }); this.logger.info(`Order: ${JSON.stringify(order)}`); + let totalValue = (order.items.reduce((value, item) => { + return value + item.unit_price * item.quantity; + }, 0)) + for (const option of order.shipping_methods) { + totalValue += option.shipping_option.amount; + } await this.sendEmail(order.email, 'Order received', event, { event, order, cart: await this.cartService.retrieve(order.cart_id || ''), id: data.id, - total_value: (order.items.reduce((value, item) => { - return value + item.unit_price * item.quantity; - }, 0) / 100).toFixed(2), + total_value: (totalValue / 100).toFixed(2), }) return {