Skip to content

Commit

Permalink
shipping price added to emails
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnisLielturks committed Apr 25, 2024
1 parent 3865066 commit dba1180
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
6 changes: 6 additions & 0 deletions data/emails/order.cancelled/html.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions data/emails/order.placed/html.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
22 changes: 19 additions & 3 deletions src/services/emails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit dba1180

Please sign in to comment.