@jarwizz/create-jarshop 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/template/src/migrations/1788000000000-jarshop-email-brand-schema-parity.ts +21 -0
- package/dist/template/src/plugins/jarshop-checkout/order-email-configuration.entity.ts +2 -2
- package/dist/template/src/plugins/jarshop-checkout/order-email-lifecycle.ts +31 -11
- package/dist/template/src/plugins/jarshop-checkout/order-lifecycle-core.ts +21 -0
- package/dist/template-manifest.json +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from "typeorm";
|
|
2
|
+
|
|
3
|
+
export class JarShopEmailBrandSchemaParity1788000000000 implements MigrationInterface {
|
|
4
|
+
name = "JarShopEmailBrandSchemaParity1788000000000";
|
|
5
|
+
|
|
6
|
+
async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
+
await queryRunner.query(`
|
|
8
|
+
ALTER TABLE "jarshop_email_brand_configuration"
|
|
9
|
+
DROP CONSTRAINT IF EXISTS "FK_jarshop_email_brand_configuration_channel"
|
|
10
|
+
`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async down(queryRunner: QueryRunner): Promise<void> {
|
|
14
|
+
await queryRunner.query(`
|
|
15
|
+
ALTER TABLE "jarshop_email_brand_configuration"
|
|
16
|
+
ADD CONSTRAINT "FK_jarshop_email_brand_configuration_channel"
|
|
17
|
+
FOREIGN KEY ("channelId") REFERENCES "channel"("id")
|
|
18
|
+
ON DELETE CASCADE ON UPDATE CASCADE
|
|
19
|
+
`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -47,10 +47,10 @@ export class JarShopEmailBrandConfiguration {
|
|
|
47
47
|
@Column({ type: "text" })
|
|
48
48
|
companyAddress!: string;
|
|
49
49
|
|
|
50
|
-
@Column({ type: "jsonb", default:
|
|
50
|
+
@Column({ type: "jsonb", default: [] })
|
|
51
51
|
enabledEvents!: ConfigurableOrderEmailKind[];
|
|
52
52
|
|
|
53
|
-
@Column({ type: "jsonb", default:
|
|
53
|
+
@Column({ type: "jsonb", default: [] })
|
|
54
54
|
shippingMethods!: OrderEmailShippingMethodConfiguration[];
|
|
55
55
|
|
|
56
56
|
@CreateDateColumn()
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
import { toOrderEmailLanguageCode } from "./order-email-delivery-core.js";
|
|
32
32
|
import {
|
|
33
33
|
getCourierOrderAlignmentState,
|
|
34
|
+
resolveLocalizedVariantName,
|
|
34
35
|
resolveShippingMethodCodeForOrderLines,
|
|
35
36
|
toFulfillmentLifecycleEmailKind,
|
|
36
37
|
} from "./order-lifecycle-core.js";
|
|
@@ -43,6 +44,15 @@ type CancellationHistoryInput = {
|
|
|
43
44
|
};
|
|
44
45
|
};
|
|
45
46
|
|
|
47
|
+
export const fulfillmentLifecycleOrderRelations = [
|
|
48
|
+
"customer",
|
|
49
|
+
"lines.productVariant",
|
|
50
|
+
"lines.productVariant.translations",
|
|
51
|
+
"shippingLines.shippingMethod",
|
|
52
|
+
"shippingLines.orderLines",
|
|
53
|
+
"fulfillments.lines",
|
|
54
|
+
] as const;
|
|
55
|
+
|
|
46
56
|
@Injectable()
|
|
47
57
|
export class JarShopOrderEmailLifecycleOutbox
|
|
48
58
|
implements OnApplicationBootstrap, OnModuleDestroy
|
|
@@ -98,13 +108,7 @@ export class JarShopOrderEmailLifecycleOutbox
|
|
|
98
108
|
}
|
|
99
109
|
const orders = await this.connection.getRepository(event.ctx, Order).find({
|
|
100
110
|
where: { fulfillments: { id: event.fulfillment.id } },
|
|
101
|
-
relations: [
|
|
102
|
-
"customer",
|
|
103
|
-
"lines.productVariant",
|
|
104
|
-
"shippingLines.shippingMethod",
|
|
105
|
-
"shippingLines.orderLines",
|
|
106
|
-
"fulfillments.lines",
|
|
107
|
-
],
|
|
111
|
+
relations: [...fulfillmentLifecycleOrderRelations],
|
|
108
112
|
});
|
|
109
113
|
|
|
110
114
|
for (const order of orders) {
|
|
@@ -138,7 +142,11 @@ export class JarShopOrderEmailLifecycleOutbox
|
|
|
138
142
|
shippingMethodCode,
|
|
139
143
|
fulfillmentId: String(fulfillment.id),
|
|
140
144
|
trackingCode: fulfillment.trackingCode ?? "",
|
|
141
|
-
lines: toEmailLineSnapshots(
|
|
145
|
+
lines: toEmailLineSnapshots(
|
|
146
|
+
order.lines,
|
|
147
|
+
fulfillment.lines,
|
|
148
|
+
identity.languageCode,
|
|
149
|
+
),
|
|
142
150
|
},
|
|
143
151
|
});
|
|
144
152
|
await this.insertOnce(event.ctx, delivery);
|
|
@@ -162,7 +170,11 @@ export class JarShopOrderEmailLifecycleOutbox
|
|
|
162
170
|
.getRepository(event.ctx, Order)
|
|
163
171
|
.findOne({
|
|
164
172
|
where: { id: orderId },
|
|
165
|
-
relations: [
|
|
173
|
+
relations: [
|
|
174
|
+
"customer",
|
|
175
|
+
"lines.productVariant",
|
|
176
|
+
"lines.productVariant.translations",
|
|
177
|
+
],
|
|
166
178
|
});
|
|
167
179
|
if (!order) return;
|
|
168
180
|
|
|
@@ -177,7 +189,11 @@ export class JarShopOrderEmailLifecycleOutbox
|
|
|
177
189
|
shippingWithTax: order.shippingWithTax,
|
|
178
190
|
historyEntryId: String(event.entity.id),
|
|
179
191
|
shippingCancelled: input.data.shippingCancelled,
|
|
180
|
-
lines: toEmailLineSnapshots(
|
|
192
|
+
lines: toEmailLineSnapshots(
|
|
193
|
+
order.lines,
|
|
194
|
+
input.data.lines,
|
|
195
|
+
identity.languageCode,
|
|
196
|
+
),
|
|
181
197
|
},
|
|
182
198
|
});
|
|
183
199
|
await this.insertOnce(event.ctx, delivery);
|
|
@@ -293,6 +309,7 @@ export function toEmailLineSnapshots(
|
|
|
293
309
|
orderLineId: string | number;
|
|
294
310
|
quantity: number;
|
|
295
311
|
}>,
|
|
312
|
+
languageCode: string,
|
|
296
313
|
): OrderEmailLineSnapshot[] {
|
|
297
314
|
return eventLines.map((eventLine) => {
|
|
298
315
|
const orderLine = orderLines.find(
|
|
@@ -302,7 +319,10 @@ export function toEmailLineSnapshots(
|
|
|
302
319
|
throw new Error("order lifecycle email line is missing");
|
|
303
320
|
}
|
|
304
321
|
return {
|
|
305
|
-
name:
|
|
322
|
+
name: resolveLocalizedVariantName(
|
|
323
|
+
orderLine.productVariant.translations,
|
|
324
|
+
languageCode,
|
|
325
|
+
),
|
|
306
326
|
quantity: eventLine.quantity,
|
|
307
327
|
totalWithTax: Math.round(
|
|
308
328
|
orderLine.proratedUnitPriceWithTax * eventLine.quantity,
|
|
@@ -105,6 +105,27 @@ export function toFulfillmentLifecycleEmailKind(
|
|
|
105
105
|
return undefined;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
export function resolveLocalizedVariantName(
|
|
109
|
+
translations: ReadonlyArray<{
|
|
110
|
+
languageCode: string;
|
|
111
|
+
name: string;
|
|
112
|
+
}>,
|
|
113
|
+
languageCode: string,
|
|
114
|
+
): string {
|
|
115
|
+
const preferredLanguages = [languageCode, "en"];
|
|
116
|
+
for (const preferredLanguage of preferredLanguages) {
|
|
117
|
+
const name = translations.find(
|
|
118
|
+
(translation) => translation.languageCode === preferredLanguage,
|
|
119
|
+
)?.name;
|
|
120
|
+
if (name?.trim()) return name;
|
|
121
|
+
}
|
|
122
|
+
const fallbackName = translations.find((translation) =>
|
|
123
|
+
Boolean(translation.name.trim()),
|
|
124
|
+
)?.name;
|
|
125
|
+
if (fallbackName) return fallbackName;
|
|
126
|
+
throw new Error("order lifecycle email variant translation is missing");
|
|
127
|
+
}
|
|
128
|
+
|
|
108
129
|
function coverageByOrderLine(lines: readonly FulfillmentCoverage[]) {
|
|
109
130
|
const coverage = new Map<string, number>();
|
|
110
131
|
for (const line of lines) {
|