|
|
@@ -22,19 +22,29 @@ export const orderConfirmationHandler = new EmailEventListener('order-confirmati
|
|
|
.on(OrderStateTransitionEvent)
|
|
|
.filter(event => event.toState === 'PaymentSettled' && !!event.order.customer)
|
|
|
.loadData(async context => {
|
|
|
- let shippingMethod: ShippingMethod | undefined;
|
|
|
- if (!context.event.order.shippingMethod && context.event.order.shippingMethodId) {
|
|
|
- shippingMethod = await context.injector
|
|
|
- .get(TransactionalConnection)
|
|
|
- .getRepository(ShippingMethod)
|
|
|
- .findOne(context.event.order.shippingMethodId);
|
|
|
+ const shippingMethods: ShippingMethod[] = [];
|
|
|
+
|
|
|
+ for (const line of context.event.order.shippingLines || []) {
|
|
|
+ let shippingMethod: ShippingMethod | undefined;
|
|
|
+ if (!line.shippingMethod && line.shippingMethodId) {
|
|
|
+ shippingMethod = await context.injector
|
|
|
+ .get(TransactionalConnection)
|
|
|
+ .getRepository(ShippingMethod)
|
|
|
+ .findOne(line.shippingMethodId);
|
|
|
+ } else if (line.shippingMethod) {
|
|
|
+ shippingMethod = line.shippingMethod;
|
|
|
+ }
|
|
|
+ if (shippingMethod) {
|
|
|
+ shippingMethods.push(shippingMethod);
|
|
|
+ }
|
|
|
}
|
|
|
- return { shippingMethod };
|
|
|
+
|
|
|
+ return { shippingMethods };
|
|
|
})
|
|
|
.setRecipient(event => event.order.customer!.emailAddress)
|
|
|
.setFrom(`{{ fromAddress }}`)
|
|
|
.setSubject(`Order confirmation for #{{ order.code }}`)
|
|
|
- .setTemplateVars(event => ({ order: event.order, shippingMethod: event.data.shippingMethod }))
|
|
|
+ .setTemplateVars(event => ({ order: event.order, shippingMethods: event.data.shippingMethods }))
|
|
|
.setMockEvent(mockOrderStateTransitionEvent);
|
|
|
|
|
|
export const emailVerificationHandler = new EmailEventListener('email-verification')
|